Skip to content

Commit

Permalink
steamcompmgr: Track X-dirtying outside of dispatch
Browse files Browse the repository at this point in the history
If we dirty the X server outside of the dispatch, xlib can flush its events, leading us to a state where XPending(dpy) is true but the poll returns false.

Fixes: f51a05b ("steamcompmgr: use poll() to wait for X11 events")
  • Loading branch information
Joshua-Ashton committed Jan 12, 2022
1 parent 9b6a748 commit dd68d7b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/steamcompmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2103,6 +2103,8 @@ determine_and_apply_focus(xwayland_ctx_t *ctx, std::vector<win*>& vecGlobalPossi
}

XFree(children);

ctx->dirty_x = true;
}

wlr_surface *win_surface(win *window)
Expand Down Expand Up @@ -4043,6 +4045,7 @@ void init_xwayland_ctx(gamescope_xwayland_server_t *xwayland_server)

ctx->xwayland_server = xwayland_server;
ctx->dpy = xwayland_server->get_xdisplay();
ctx->dirty_x = true;
if (!ctx->dpy)
{
xwm_log.errorf("Can't open display");
Expand Down Expand Up @@ -4351,6 +4354,16 @@ steamcompmgr_main(int argc, char **argv)
focusDirty = false;
bool vblank = false;

{
gamescope_xwayland_server_t *server = NULL;
for ( size_t i = 0; (server = wlserver_get_xwayland_server(i)); i++ )
{
assert( server );
if ( server->ctx->dirty_x && XPending( server->ctx->dpy ) )
dispatch_x11( server->ctx.get() );
}
}

if ( poll( pollfds.data(), pollfds.size(), -1 ) < 0)
{
if ( errno == EAGAIN )
Expand All @@ -4374,9 +4387,9 @@ steamcompmgr_main(int argc, char **argv)

for (size_t i = EVENT_X11; i < pollfds.size(); i++)
{
if ( pollfds[ i ].revents & POLLIN )
gamescope_xwayland_server_t *server = wlserver_get_xwayland_server(i - EVENT_X11);
if ( ( pollfds[ i ].revents & POLLIN ) )
{
gamescope_xwayland_server_t *server = wlserver_get_xwayland_server(i - EVENT_X11);
assert(server);
dispatch_x11( server->ctx.get() );
}
Expand All @@ -4397,6 +4410,7 @@ steamcompmgr_main(int argc, char **argv)
(unsigned char *)&inputCounter, 1 );

lastPublishedInputCounter = inputCounter;
root_ctx->dirty_x = true;
}

if (focusDirty == true)
Expand Down
1 change: 1 addition & 0 deletions src/xwayland_ctx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct xwayland_ctx_t
{
gamescope_xwayland_server_t *xwayland_server;
Display *dpy;
bool dirty_x;

win *list;
int scr;
Expand Down

0 comments on commit dd68d7b

Please sign in to comment.