Browse Source

Only grab keyboard when we have focus

There was an issue with the new grabs that were introduced in commit
2289342de7. 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.
tags/v1.12.90
Samuel Mannehed 2 years ago
parent
commit
72e94ca93d
2 changed files with 17 additions and 1 deletions
  1. 15
    1
      vncviewer/DesktopWindow.cxx
  2. 2
    0
      vncviewer/DesktopWindow.h

+ 15
- 1
vncviewer/DesktopWindow.cxx View 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();
}


+ 2
- 0
vncviewer/DesktopWindow.h View 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();

Loading…
Cancel
Save