From: Samuel Mannehed Date: Tue, 31 Mar 2020 20:02:21 +0000 (+0200) Subject: Cancel AltGr timeout on mouse events as well X-Git-Tag: v1.10.90~27^2~2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d71135b02bd47037e5c210dbf678815a880065ed;p=tigervnc.git Cancel AltGr timeout on mouse events as well We have a timer after Ctrl is pressed in order to see if an Alt will come right after. Ctrl + Alt is what windows sends for AltGr. If a key other than Alt was pressed we knew that we could cancel this timer, this commit extends that to mouse events too. Since this detection breaks the true order of events we want to make a decision as fast as possible. --- diff --git a/vncviewer/Viewport.cxx b/vncviewer/Viewport.cxx index b0b2a15a..84777be1 100644 --- a/vncviewer/Viewport.cxx +++ b/vncviewer/Viewport.cxx @@ -939,7 +939,22 @@ int Viewport::handleSystemEvent(void *event, void *data) #if defined(WIN32) MSG *msg = (MSG*)event; - if ((msg->message == WM_KEYDOWN) || (msg->message == WM_SYSKEYDOWN)) { + if ((msg->message == WM_MOUSEMOVE) || + (msg->message == WM_LBUTTONDOWN) || + (msg->message == WM_LBUTTONUP) || + (msg->message == WM_RBUTTONDOWN) || + (msg->message == WM_RBUTTONUP) || + (msg->message == WM_MBUTTONDOWN) || + (msg->message == WM_MBUTTONUP) || + (msg->message == WM_MOUSEWHEEL) || + (msg->message == WM_MOUSEHWHEEL)) { + // We can't get a mouse event in the middle of an AltGr sequence, so + // abort that detection + if (self->altGrArmed) + self->resolveAltGrDetection(false); + + return 0; // We didn't really consume the mouse event + } else if ((msg->message == WM_KEYDOWN) || (msg->message == WM_SYSKEYDOWN)) { UINT vKey; bool isExtended; int keyCode; @@ -963,16 +978,11 @@ int Viewport::handleSystemEvent(void *event, void *data) // by seeing the two key events directly after each other with a very // short time between them (<50ms) and supress the Ctrl event. if (self->altGrArmed) { - self->altGrArmed = false; - Fl::remove_timeout(handleAltGrTimeout); - - if (isExtended && (keyCode == 0x38) && (vKey == VK_MENU) && - ((msg->time - self->altGrCtrlTime) < 50)) { - // Alt seen, so this is an AltGr sequence - } else { - // Not Alt, so fire the queued up Ctrl event - self->handleKeyPress(0x1d, XK_Control_L); - } + bool altPressed = isExtended && + (keyCode == 0x38) && + (vKey == VK_MENU) && + ((msg->time - self->altGrCtrlTime) < 50); + self->resolveAltGrDetection(altPressed); } if (keyCode == SCAN_FAKE) { @@ -1069,11 +1079,8 @@ int Viewport::handleSystemEvent(void *event, void *data) // We can't get a release in the middle of an AltGr sequence, so // abort that detection - if (self->altGrArmed) { - self->altGrArmed = false; - Fl::remove_timeout(handleAltGrTimeout); - self->handleKeyPress(0x1d, XK_Control_L); - } + if (self->altGrArmed) + self->resolveAltGrDetection(false); if (keyCode == SCAN_FAKE) { vlog.debug("Ignoring fake key release (virtual key 0x%02x)", vKey); @@ -1197,6 +1204,15 @@ void Viewport::handleAltGrTimeout(void *data) self->altGrArmed = false; self->handleKeyPress(0x1d, XK_Control_L); } + +void Viewport::resolveAltGrDetection(bool isAltGrSequence) +{ + altGrArmed = false; + Fl::remove_timeout(handleAltGrTimeout); + // when it's not an AltGr sequence we can't supress the Ctrl anymore + if (!isAltGrSequence) + handleKeyPress(0x1d, XK_Control_L); +} #endif void Viewport::initContextMenu() diff --git a/vncviewer/Viewport.h b/vncviewer/Viewport.h index 306beee9..19def92c 100644 --- a/vncviewer/Viewport.h +++ b/vncviewer/Viewport.h @@ -91,6 +91,7 @@ private: #ifdef WIN32 static void handleAltGrTimeout(void *data); + void resolveAltGrDetection(bool isAltGrSequence); #endif void pushLEDState();