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; } }