Revert "[client] spice: better x11 grab/ungrab behaviour"

This reverts commit 18f9d936c6.
This commit is contained in:
Geoffrey McRae 2021-01-10 01:00:40 +11:00
parent 176cc394d1
commit fa1deafd58

View File

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