From fa1deafd58cbea02cb1d340ad47757c5fa1700b8 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Sun, 10 Jan 2021 01:00:40 +1100 Subject: [PATCH] Revert "[client] spice: better x11 grab/ungrab behaviour" This reverts commit 18f9d936c6b71ae5df047bd14bbb3cb556e776fc. --- client/src/main.c | 76 ++++++++++++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 31 deletions(-) diff --git a/client/src/main.c b/client/src/main.c index 4f3796c4..c9824cd6 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -1133,6 +1133,36 @@ static void handleWindowEnter() g_cursor.redraw = true; } +// only called for X11 +static void keyboardGrab() +{ + if (!params.grabKeyboardOnFocus) + return; + + // grab the keyboard so we can intercept WM keys + XGrabKeyboard( + g_state.wminfo.info.x11.display, + g_state.wminfo.info.x11.window, + true, + GrabModeAsync, + GrabModeAsync, + CurrentTime + ); +} + +// only called for X11 +static void keyboardUngrab() +{ + if (!params.grabKeyboardOnFocus) + return; + + // ungrab the keyboard + XUngrabKeyboard( + g_state.wminfo.info.x11.display, + CurrentTime + ); +} + static void setGrab(bool enable) { setGrabQuiet(enable); @@ -1197,10 +1227,7 @@ static void setGrabQuiet(bool enable) alignToGuest(); if (g_cursor.grab) - { g_cursor.inView = true; - g_cursor.draw = true; - } } int eventFilter(void * userdata, SDL_Event * event) @@ -1418,45 +1445,34 @@ int eventFilter(void * userdata, SDL_Event * event) g_cursor.pos.x = x; g_cursor.pos.y = y; handleWindowLeave(); - - /* ungrab to avoid bad behaviour */ - if (g_cursor.grab) - setGrab(false); - else - XUngrabKeyboard(g_state.wminfo.info.x11.display, CurrentTime); - break; } case FocusIn: - if (xe.xfocus.mode == NotifyGrab) - break; - g_state.focused = true; - if (params.grabKeyboardOnFocus) - XGrabKeyboard( - g_state.wminfo.info.x11.display, - g_state.wminfo.info.x11.window, - true, - GrabModeAsync, - GrabModeAsync, - CurrentTime - ); + if (!inputEnabled()) + break; + if (xe.xfocus.mode == NotifyNormal || + xe.xfocus.mode == NotifyUngrab) + keyboardGrab(); break; case FocusOut: g_state.focused = false; - if (xe.xfocus.mode != NotifyNormal) + + if (!inputEnabled()) break; - /* ungrab to avoid bad behaviour */ - if (g_cursor.grab) - setGrab(false); - else - XUngrabKeyboard(g_state.wminfo.info.x11.display, CurrentTime); - + if (xe.xfocus.mode == NotifyNormal || + xe.xfocus.mode == NotifyWhileGrabbed) + { + if (g_cursor.grab) + setGrab(false); + else + keyboardUngrab(); + } break; } } @@ -1661,8 +1677,6 @@ static bool try_renderer(const int index, const LG_RendererParams lgrParams, Uin static void toggle_fullscreen(SDL_Scancode key, void * opaque) { - /* first move the local mouse to the screen center so that we don't get a - * leave event breaking focus */ SDL_SetWindowFullscreen(g_state.window, params.fullscreen ? 0 : SDL_WINDOW_FULLSCREEN_DESKTOP); params.fullscreen = !params.fullscreen; }