From 7f2b66d6011152a470439fb73104b3c38a56ea55 Mon Sep 17 00:00:00 2001 From: rakshasa Date: Wed, 17 Aug 2005 16:58:07 +0000 Subject: [PATCH] * Add includes of headers for select. * Make initialization and cleanup of display::Canvast safer. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@533 e378c898-3ddf-0310-93e7-cc216c733640 --- src/core/poll_manager_epoll.cc | 2 + src/core/poll_manager_select.cc | 2 + src/display/canvas.cc | 14 +++++- src/display/canvas.h | 76 +++++++++++++++++---------------- src/ui/control.cc | 2 +- 5 files changed, 57 insertions(+), 39 deletions(-) diff --git a/src/core/poll_manager_epoll.cc b/src/core/poll_manager_epoll.cc index bf2a7962..63a93185 100644 --- a/src/core/poll_manager_epoll.cc +++ b/src/core/poll_manager_epoll.cc @@ -38,6 +38,8 @@ #include #include +#include +#include #include #include diff --git a/src/core/poll_manager_select.cc b/src/core/poll_manager_select.cc index 9bb034fe..63c676e1 100644 --- a/src/core/poll_manager_select.cc +++ b/src/core/poll_manager_select.cc @@ -38,6 +38,8 @@ #include #include +#include +#include #include #include diff --git a/src/display/canvas.cc b/src/display/canvas.cc index 28c9bb13..5d904c57 100644 --- a/src/display/canvas.cc +++ b/src/display/canvas.cc @@ -40,6 +40,8 @@ namespace display { +bool Canvas::m_isInitialized = false; + void Canvas::resize(int x, int y, int w, int h) { wresize(m_window, h, w); @@ -47,7 +49,12 @@ Canvas::resize(int x, int y, int w, int h) { } void -Canvas::init() { +Canvas::initialize() { + if (m_isInitialized) + return; + + m_isInitialized = true; + initscr(); raw(); noecho(); @@ -58,6 +65,11 @@ Canvas::init() { void Canvas::cleanup() { + if (!m_isInitialized) + return; + + m_isInitialized = false; + noraw(); endwin(); } diff --git a/src/display/canvas.h b/src/display/canvas.h index 385c3ac0..4a8fe809 100644 --- a/src/display/canvas.h +++ b/src/display/canvas.h @@ -48,77 +48,79 @@ public: m_window(newwin(height, width, y, x)) {} ~Canvas() { delwin(m_window); } - void refresh() { wnoutrefresh(m_window); } - static void refresh_std() { wnoutrefresh(stdscr); } - void redraw() { redrawwin(m_window); } + void refresh() { wnoutrefresh(m_window); } + static void refresh_std() { wnoutrefresh(stdscr); } + void redraw() { redrawwin(m_window); } - void resize(int w, int h) { wresize(m_window, h, w); } - void resize(int x, int y, int w, int h); + void resize(int w, int h) { wresize(m_window, h, w); } + void resize(int x, int y, int w, int h); - int get_x() { int x, y; getyx(m_window, y, x); return x; } - int get_y() { int x, y; getyx(m_window, y, x); return y; } - int get_width() { int x, y; getmaxyx(m_window, y, x); return x; } - int get_height() { int x, y; getmaxyx(m_window, y, x); return y; } + int get_x() { int x, y; getyx(m_window, y, x); return x; } + int get_y() { int x, y; getyx(m_window, y, x); return y; } + int get_width() { int x, y; getmaxyx(m_window, y, x); return x; } + int get_height() { int x, y; getmaxyx(m_window, y, x); return y; } - chtype get_background() { return getbkgd(m_window); } - void set_background(chtype c) { return wbkgdset(m_window, c); } + chtype get_background() { return getbkgd(m_window); } + void set_background(chtype c) { return wbkgdset(m_window, c); } - void erase() { werase(m_window); } - static void erase_std() { werase(stdscr); } + void erase() { werase(m_window); } + static void erase_std() { werase(stdscr); } - void print_border(chtype ls, chtype rs, - chtype ts, chtype bs, - chtype tl, chtype tr, - chtype bl, chtype br) { wborder(m_window, ls, rs, ts, bs, tl, tr, bl, br); } + void print_border(chtype ls, chtype rs, + chtype ts, chtype bs, + chtype tl, chtype tr, + chtype bl, chtype br) { wborder(m_window, ls, rs, ts, bs, tl, tr, bl, br); } // The format string is non-const, but that will not be a problem // since the string shall always be a C string choosen at // compiletime. Might cause extra copying of the string? - void print(int x, int y, char* str) { mvwprintw(m_window, y, x, str); } + void print(int x, int y, char* str) { mvwprintw(m_window, y, x, str); } template - void print(int x, int y, char* str, A1 a1) { mvwprintw(m_window, y, x, str, a1); } + void print(int x, int y, char* str, A1 a1) { mvwprintw(m_window, y, x, str, a1); } template - void print(int x, int y, char* str, A1 a1, A2 a2) { mvwprintw(m_window, y, x, str, a1, a2); } + void print(int x, int y, char* str, A1 a1, A2 a2) { mvwprintw(m_window, y, x, str, a1, a2); } template - void print(int x, int y, char* str, - A1 a1, A2 a2, A3 a3) { mvwprintw(m_window, y, x, str, a1, a2, a3); } + void print(int x, int y, char* str, + A1 a1, A2 a2, A3 a3) { mvwprintw(m_window, y, x, str, a1, a2, a3); } template - void print(int x, int y, char* str, - A1 a1, A2 a2, A3 a3, A4 a4) { mvwprintw(m_window, y, x, str, a1, a2, a3, a4); } + void print(int x, int y, char* str, + A1 a1, A2 a2, A3 a3, A4 a4) { mvwprintw(m_window, y, x, str, a1, a2, a3, a4); } template - void print(int x, int y, char* str, - A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { mvwprintw(m_window, y, x, str, a1, a2, a3, a4, a5); } + void print(int x, int y, char* str, + A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { mvwprintw(m_window, y, x, str, a1, a2, a3, a4, a5); } template - void print(int x, int y, char* str, - A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) { mvwprintw(m_window, y, x, str, a1, a2, a3, a4, a5, a6); } + void print(int x, int y, char* str, + A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) { mvwprintw(m_window, y, x, str, a1, a2, a3, a4, a5, a6); } template - void print(int x, int y, char* str, - A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) { mvwprintw(m_window, y, x, str, a1, a2, a3, a4, a5, a6, a7); } + void print(int x, int y, char* str, + A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) { mvwprintw(m_window, y, x, str, a1, a2, a3, a4, a5, a6, a7); } - void set_attr(int x, int y, int n, int attr, int color) { mvwchgat(m_window, y, x, n, attr, color, NULL); } + void set_attr(int x, int y, int n, int attr, int color) { mvwchgat(m_window, y, x, n, attr, color, NULL); } // Initialize stdscr. - static void init(); - static void cleanup(); + static void initialize(); + static void cleanup(); - static int get_screen_width() { int x, y; getmaxyx(stdscr, y, x); return x; } - static int get_screen_height() { int x, y; getmaxyx(stdscr, y, x); return y; } + static int get_screen_width() { int x, y; getmaxyx(stdscr, y, x); return x; } + static int get_screen_height() { int x, y; getmaxyx(stdscr, y, x); return y; } - static void do_update() { doupdate(); } + static void do_update() { doupdate(); } private: Canvas(const Canvas&); void operator = (const Canvas&); - WINDOW* m_window; + static bool m_isInitialized; + + WINDOW* m_window; }; } diff --git a/src/ui/control.cc b/src/ui/control.cc index 4bba89f1..99dc522d 100644 --- a/src/ui/control.cc +++ b/src/ui/control.cc @@ -58,7 +58,7 @@ Control::~Control() { void Control::initialize() { - display::Canvas::init(); + display::Canvas::initialize(); display::Window::slot_adjust(sigc::mem_fun(m_display, &display::Manager::adjust_layout)); m_core.get_poll_manager()->signal_interrupted().connect(sigc::mem_fun(*m_inputStdin, &input::InputEvent::event_read));