summaryrefslogtreecommitdiffstats
path: root/vncviewer
diff options
context:
space:
mode:
authorSamuel Mannehed <samuel@cendio.se>2020-03-31 22:02:21 +0200
committerNiko Lehto <nikle@cendio.se>2020-05-29 15:26:33 +0200
commitd71135b02bd47037e5c210dbf678815a880065ed (patch)
tree7f2bc1ee33da6a3f33c25008194fd6ff5dc3f034 /vncviewer
parentc79a05dc152a6a51d38b8db9f085339bd193241a (diff)
downloadtigervnc-d71135b02bd47037e5c210dbf678815a880065ed.tar.gz
tigervnc-d71135b02bd47037e5c210dbf678815a880065ed.zip
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.
Diffstat (limited to 'vncviewer')
-rw-r--r--vncviewer/Viewport.cxx48
-rw-r--r--vncviewer/Viewport.h1
2 files changed, 33 insertions, 16 deletions
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();