diff --git a/src/musikbox/cursespp/App.cpp b/src/musikbox/cursespp/App.cpp index 0109e3862..4008897ae 100755 --- a/src/musikbox/cursespp/App.cpp +++ b/src/musikbox/cursespp/App.cpp @@ -54,14 +54,6 @@ #include #endif -#ifdef WIN32 -#define IDLE_TIMEOUT_MS 0 -#define REDRAW_DEBOUNCE_MS 100 -#else -#define IDLE_TIMEOUT_MS 75 -#define REDRAW_DEBOUNCE_MS 100 -#endif - using namespace cursespp; using namespace boost::chrono; @@ -144,15 +136,12 @@ void App::Run(ILayoutPtr layout) { if (this->state.input) { /* if the focused window is an input, allow it to draw a cursor */ WINDOW *c = this->state.focused->GetContent(); - wtimeout(this->state.focused->GetContent(), IDLE_TIMEOUT_MS); - curs_set(1); keypad(c, TRUE); ch = wgetch(c); } else { /* otherwise, no cursor */ ch = wgetch(stdscr); - curs_set(0); } if (ch == ERR) { @@ -209,25 +198,11 @@ void App::Run(ILayoutPtr layout) { } } -void App::CheckDrawCursor() { - if (this->state.input != NULL) { - curs_set(1); - - if (this->state.focused) { - wtimeout(this->state.focused->GetContent(), IDLE_TIMEOUT_MS); - } - } - else { - curs_set(0); - } -} - void App::UpdateFocusedWindow(IWindowPtr window) { if (this->state.focused != window) { this->state.focused = window; this->state.input = dynamic_cast(window.get()); this->state.keyHandler = dynamic_cast(window.get()); - this->CheckDrawCursor(); } } diff --git a/src/musikbox/cursespp/Window.cpp b/src/musikbox/cursespp/Window.cpp index 1031f9d50..96058d5e3 100755 --- a/src/musikbox/cursespp/Window.cpp +++ b/src/musikbox/cursespp/Window.cpp @@ -46,25 +46,27 @@ static int NEXT_ID = 0; static bool drawPending = false; static bool freeze = false; +static inline void DrawCursor(IInput* input) { + if (input) { + Window* inputWindow = dynamic_cast(input); + if (inputWindow) { + WINDOW* content = inputWindow->GetContent(); + curs_set(1); + wtimeout(content, IDLE_TIMEOUT_MS); + wmove(content, 0, input->Position()); + } + } + else { + curs_set(0); + } +} + void Window::WriteToScreen(IInput* input) { if (drawPending && !freeze) { drawPending = false; - update_panels(); doupdate(); - - /* had problems finding reliable documentation here, but it seems like - manually moving the cursor requires a refresh() -- doupdate() is not - good enough. further, we allow windows to repaint themselves at will, - which may change the cursor position. after each draw cycle, move the - cursor back to the focused input. */ - if (input) { - Window* inputWindow = dynamic_cast(input); - if (inputWindow) { - wmove(inputWindow->GetContent(), 0, input->Position()); - wrefresh(inputWindow->GetContent()); - } - } + DrawCursor(input); } } diff --git a/src/musikbox/cursespp/Window.h b/src/musikbox/cursespp/Window.h index 35f3b1e82..213ae5c6c 100755 --- a/src/musikbox/cursespp/Window.h +++ b/src/musikbox/cursespp/Window.h @@ -37,6 +37,14 @@ #include "curses_config.h" #include "IWindow.h" +#ifdef WIN32 +#define IDLE_TIMEOUT_MS 0 +#define REDRAW_DEBOUNCE_MS 100 +#else +#define IDLE_TIMEOUT_MS 75 +#define REDRAW_DEBOUNCE_MS 100 +#endif + namespace cursespp { class IInput;