steamcompmgr: Defer focus setting in X event loop

Otherwise we can get BadWindow errors as the window may have been destroyed later in the event list.
This commit is contained in:
Joshua Ashton 2021-12-14 13:40:08 +00:00 committed by Pierre-Loup A. Griffais
parent bb3fd430eb
commit 966439e84b

View file

@ -3605,6 +3605,9 @@ spawn_client( char **argv )
static void
dispatch_x11( Display *dpy, MouseCursor *cursor )
{
bool bShouldResetCursor = false;
bool bSetFocus = false;
do {
XEvent ev;
int ret = XNextEvent(dpy, &ev);
@ -3676,7 +3679,7 @@ dispatch_x11( Display *dpy, MouseCursor *cursor )
else
{
// focus went elsewhere, correct it
XSetInputFocus(dpy, currentKeyboardFocusWindow, RevertToNone, CurrentTime);
bSetFocus = true;
}
}
}
@ -3730,10 +3733,9 @@ dispatch_x11( Display *dpy, MouseCursor *cursor )
case LeaveNotify:
if (ev.xcrossing.window == currentInputFocusWindow)
{
// This shouldn't happen due to our pointer barriers,
// but there is a known X server bug; warp to last good
// position.
cursor->resetPosition();
// Josh: need to defer this as we could have a destroy later on
// and end up submitting commands with the currentInputFocusWIndow
bShouldResetCursor = true;
}
break;
case MotionNotify:
@ -3758,6 +3760,19 @@ dispatch_x11( Display *dpy, MouseCursor *cursor )
}
XFlush(dpy);
} while (XPending(dpy));
if ( bShouldResetCursor )
{
// This shouldn't happen due to our pointer barriers,
// but there is a known X server bug; warp to last good
// position.
cursor->resetPosition();
}
if ( bSetFocus )
{
XSetInputFocus(dpy, currentKeyboardFocusWindow, RevertToNone, CurrentTime);
}
}
static bool