aboutsummaryrefslogtreecommitdiffstats
path: root/vncviewer/Viewport.cxx
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2021-12-14 17:06:36 +0100
committerPierre Ossman <ossman@cendio.se>2022-12-13 14:52:13 +0100
commit4f6d4895c3420e5ac301a916bced4a0065a19183 (patch)
treef838f2f17e2902c57bf5f5b15be8e12338aa0436 /vncviewer/Viewport.cxx
parent946fb2b03b7663abd9d71014de5dfdf25a7e040d (diff)
downloadtigervnc-4f6d4895c3420e5ac301a916bced4a0065a19183.tar.gz
tigervnc-4f6d4895c3420e5ac301a916bced4a0065a19183.zip
Handle macOS keyboard stealing
The system steals keyboard events for certain system keyboard shortcuts, e.g. Cmd+Tab. Unfortunately this isn't considered a focus loss, so we don't realise we've lost a few keyboard events and can end up in a confused state. Fortunately it is possible to detect when this happens and reset the keyboard state, just like we do when focus is lost.
Diffstat (limited to 'vncviewer/Viewport.cxx')
-rw-r--r--vncviewer/Viewport.cxx20
1 files changed, 16 insertions, 4 deletions
diff --git a/vncviewer/Viewport.cxx b/vncviewer/Viewport.cxx
index 81ad9827..83872ced 100644
--- a/vncviewer/Viewport.cxx
+++ b/vncviewer/Viewport.cxx
@@ -643,10 +643,9 @@ int Viewport::handle(int event)
return 1;
case FL_UNFOCUS:
- // Release all keys that were pressed as that generally makes most
- // sense (e.g. Alt+Tab where we only see the Alt press)
- while (!downKeySym.empty())
- handleKeyRelease(downKeySym.begin()->first);
+ // We won't get more key events, so reset our knowledge about keys
+ resetKeyboard();
+
Fl::enable_im();
return 1;
@@ -823,6 +822,13 @@ void Viewport::handlePointerTimeout(void *data)
}
+void Viewport::resetKeyboard()
+{
+ while (!downKeySym.empty())
+ handleKeyRelease(downKeySym.begin()->first);
+}
+
+
void Viewport::handleKeyPress(int keyCode, rdr::U32 keySym)
{
static bool menuRecursion = false;
@@ -1125,6 +1131,12 @@ int Viewport::handleSystemEvent(void *event, void *data)
return 1;
}
#elif defined(__APPLE__)
+ // Special event that means we temporarily lost some input
+ if (cocoa_is_keyboard_sync(event)) {
+ self->resetKeyboard();
+ return 1;
+ }
+
if (cocoa_is_keyboard_event(event)) {
int keyCode;