From f51a05b2dcfbae0b807547c2d24c708ce7caddca Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 9 Jun 2021 17:22:53 +0200 Subject: [PATCH] steamcompmgr: use poll() to wait for X11 events References: https://github.com/Plagman/gamescope/issues/201 --- src/steamcompmgr.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp index 9ddf163..1258eea 100644 --- a/src/steamcompmgr.cpp +++ b/src/steamcompmgr.cpp @@ -3284,11 +3284,36 @@ steamcompmgr_main (int argc, char **argv) std::thread imageWaitThread( imageWaitThreadMain ); imageWaitThread.detach(); + struct pollfd x11_pollfd = { + .fd = XConnectionNumber(dpy), + .events = POLLIN, + }; + for (;;) { focusDirty = False; bool vblank = false; + if ( poll( &x11_pollfd, 1, -1 ) < 0) + { + if ( errno == EAGAIN ) + continue; + + perror( "poll failed" ); + break; + } + + if ( x11_pollfd.revents & POLLHUP ) + { + fprintf( stderr, "Lost connection to the X11 server\n" ); + break; + } + + if ( !( x11_pollfd.revents & POLLIN ) ) + { + continue; + } + do { XNextEvent (dpy, &ev); if ((ev.type & 0x7f) != KeymapNotify)