From 4a823d0e4fdada800743a4b02f9602af95e31b38 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Sat, 28 Nov 2020 10:05:02 +1100 Subject: [PATCH] [client] grab the keyboard when the window has focus --- client/src/main.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/client/src/main.c b/client/src/main.c index 8672e63d..b3571099 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -925,6 +925,30 @@ static void handleWindowEnter() state.warpState = WARP_STATE_ARMED; } +// only called for X11 +static void keyboardGrab() +{ + // grab the keyboard so we can intercept WM keys + XGrabKeyboard( + state.wminfo.info.x11.display, + state.wminfo.info.x11.window, + true, + GrabModeAsync, + GrabModeAsync, + CurrentTime + ); +} + +// only called for X11 +static void keyboardUngrab() +{ + // ungrab the keyboard + XUngrabKeyboard( + state.wminfo.info.x11.display, + CurrentTime + ); +} + int eventFilter(void * userdata, SDL_Event * event) { switch(event->type) @@ -998,6 +1022,18 @@ int eventFilter(void * userdata, SDL_Event * event) state.haveCurLocal = true; handleWindowLeave(); break; + + case FocusIn: + if (xe.xfocus.mode == NotifyNormal || + xe.xfocus.mode == NotifyUngrab) + keyboardGrab(); + break; + + case FocusOut: + if (xe.xfocus.mode == NotifyNormal || + xe.xfocus.mode == NotifyWhileGrabbed) + keyboardUngrab(); + break; } }