[client] grab the keyboard when the window has focus

This commit is contained in:
Geoffrey McRae 2020-11-28 10:05:02 +11:00
parent db51acdd8a
commit 4a823d0e4f

View File

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