Calling curs_set() with the same value it already has seems to still

trigger redraws sometimes, at least with PDCurses WinGui. Our
application currently controls showing the cursor, so let's just
remember if it's visible or not, and not call set_curs() again unless we
have to.
This commit is contained in:
casey langen 2020-11-17 21:04:53 -08:00
parent ff5217485f
commit 62db8015d2
2 changed files with 20 additions and 6 deletions

View File

@ -55,6 +55,7 @@ static bool drawPending = false;
static bool freeze = false; static bool freeze = false;
static Window* top = nullptr; static Window* top = nullptr;
static Window* focused = nullptr; static Window* focused = nullptr;
static bool cursorVisible = false;
static MessageQueue messageQueue; static MessageQueue messageQueue;
static std::shared_ptr<INavigationKeys> keys; static std::shared_ptr<INavigationKeys> keys;
@ -92,16 +93,29 @@ mention wbkgd() was changed, but it's unclear what exactly happened... */
static inline void DrawCursor(IInput* input) { static inline void DrawCursor(IInput* input) {
if (input) { if (input) {
Window* inputWindow = dynamic_cast<Window*>(input); const Window* inputWindow = dynamic_cast<Window*>(input);
if (inputWindow && inputWindow->GetContent()) { if (inputWindow && inputWindow->GetContent()) {
if (!cursorVisible) {
curs_set(1);
cursorVisible = true;
}
WINDOW* content = inputWindow->GetContent(); WINDOW* content = inputWindow->GetContent();
curs_set(1); if (content) {
wtimeout(content, IDLE_TIMEOUT_MS); wtimeout(content, IDLE_TIMEOUT_MS);
wmove(content, 0, (int) input->Position()); int currentX = 0, currentY = 0;
getyx(content, currentY, currentX);
int const targetY = 0, const targetX = (int) input->Position();
if (currentX != targetX || currentY != targetY) {
wmove(content, targetY, targetX);
}
}
return; return;
} }
} }
curs_set(0); if (cursorVisible) {
curs_set(0);
cursorVisible = false;
}
} }
static inline void DrawTooSmall() { static inline void DrawTooSmall() {

View File

@ -40,7 +40,7 @@
#include <musikcore/runtime/IMessageQueue.h> #include <musikcore/runtime/IMessageQueue.h>
#ifdef WIN32 #ifdef WIN32
#define IDLE_TIMEOUT_MS 5 #define IDLE_TIMEOUT_MS 0
#define REDRAW_DEBOUNCE_MS 100 #define REDRAW_DEBOUNCE_MS 100
#else #else
#define IDLE_TIMEOUT_MS 75 #define IDLE_TIMEOUT_MS 75