]> source.dussan.org Git - tigervnc.git/commitdiff
Only grab keyboard when we have focus
authorSamuel Mannehed <samuel@cendio.se>
Thu, 23 Sep 2021 14:31:59 +0000 (16:31 +0200)
committerSamuel Mannehed <samuel@cendio.se>
Wed, 6 Oct 2021 15:20:57 +0000 (17:20 +0200)
There was an issue with the new grabs that were introduced in commit
2289342de7222e4ff2483eae95bb9898830e6097. On macOS when running
vncviewer in fullscreen on one monitor, we saw that we sometimes got
resize and fullscreen events when switching the focus away from
vncviewer. With the changes in the commit mentioned above this meant
that we immediately grabbed the keyboard again, thus never releasing it.

Fixes #1332.

(cherry picked from commit 72e94ca93d3ada8fb7f518fa65644d2bc172bd4b)

vncviewer/DesktopWindow.cxx
vncviewer/DesktopWindow.h

index 31b5c4c64c593bb0753c46bbdceda011dd69e58b..d379a712f92bc0f113662187ebd42c3ede064455 100644 (file)
@@ -1007,9 +1007,23 @@ Bool eventIsFocusWithSerial(Display *display, XEvent *event, XPointer arg)
 }
 #endif
 
+bool DesktopWindow::hasFocus()
+{
+  Fl_Widget* focus;
+
+  focus = Fl::grab();
+  if (!focus)
+    focus = Fl::focus();
+
+  if (!focus)
+    return false;
+
+  return focus->window() == this;
+}
+
 void DesktopWindow::maybeGrabKeyboard()
 {
-  if (fullscreenSystemKeys && fullscreen_active())
+  if (fullscreenSystemKeys && fullscreen_active() && hasFocus())
     grabKeyboard();
 }
 
index 04539700dbc6bed20992c20e7718c2098b186f39..a654b1262555c46e9196040689bc9fa2f4de14b4 100644 (file)
@@ -95,6 +95,8 @@ private:
   static int fltkDispatch(int event, Fl_Window *win);
   static int fltkHandle(int event);
 
+  bool hasFocus();
+
   void maybeGrabKeyboard();
   void grabKeyboard();
   void ungrabKeyboard();