From b50e5ed7e60172bf31ad6a878ac199c3ab2bb6b8 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Fri, 30 Apr 2021 18:17:15 -0500 Subject: [PATCH] Fix keyboard grab on X11 Fixes #584 --- app/streaming/input/input.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/streaming/input/input.cpp b/app/streaming/input/input.cpp index 5772b61d..d41d87f9 100644 --- a/app/streaming/input/input.cpp +++ b/app/streaming/input/input.cpp @@ -372,11 +372,18 @@ void SdlInputHandler::updateKeyboardGrabState() // Ungrab if it's fullscreen only and we left fullscreen shouldGrab = false; } +#ifdef Q_OS_DARWIN else if (!(windowFlags & SDL_WINDOW_INPUT_FOCUS)) { - // Ungrab if we lose input focus (SDL will do this internally, but - // not for macOS where SDL is not handling the grab logic). + // Ungrab if we lose input focus on macOS. SDL will handle + // this internally for platforms where we use the SDL + // SDL_SetWindowKeyboardGrab() API exclusively. + // + // NB: On X11, we may not have input focus at the time of + // the initial keyboard grab update, so we must not enable + // this codepath on Linux. shouldGrab = false; } +#endif // Don't close the window on Alt+F4 when keyboard grab is enabled SDL_SetHint(SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4, shouldGrab ? "1" : "0");