diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp index 5de0077..8c1cecf 100644 --- a/src/steamcompmgr.cpp +++ b/src/steamcompmgr.cpp @@ -171,7 +171,6 @@ bool focusControlled; std::vector< uint32_t > vecFocuscontrolAppIDs; static Window ourWindow; -static XEvent nudgeEvent; Bool gameFocused; @@ -280,6 +279,8 @@ static Bool useXRes = True; std::mutex wayland_commit_lock; std::vector wayland_commit_queue; +static int g_nudgePipe[2]; + // poor man's semaphore class sem { @@ -361,9 +362,7 @@ retry: listCommitsDone.push_back( commitID ); } - static Display *threadDPY = XOpenDisplay ( wlserver_get_nested_display_name() ); - XSendEvent( threadDPY, ourWindow, True, SubstructureRedirectMask, &nudgeEvent ); - XFlush( threadDPY ); + nudge_steamcompmgr(); goto retry; } @@ -733,8 +732,7 @@ void MouseCursor::checkSuspension() // We're hiding the cursor, force redraw if we were showing it if (window && !m_imageEmpty ) { hasRepaint = true; - XSendEvent(m_display, ourWindow, true, SubstructureRedirectMask, &nudgeEvent); - XFlush(m_display); + nudge_steamcompmgr(); } } } @@ -2810,10 +2808,6 @@ register_cm (Display *dpy) ourWindow = w; - nudgeEvent.xclient.type = ClientMessage; - nudgeEvent.xclient.window = ourWindow; - nudgeEvent.xclient.format = 32; - return True; } @@ -2898,6 +2892,12 @@ void handle_done_commits( void ) listCommitsDone.clear(); } +void nudge_steamcompmgr( void ) +{ + if ( write( g_nudgePipe[ 1 ], "\n", 1 ) < 0 ) + perror( "nudge_steamcompmgr: write failed" ); +} + void check_new_wayland_res( void ) { // When importing buffer, we'll potentially need to perform operations with @@ -3217,9 +3217,25 @@ dispatch_vblank( int fd ) return vblank; } +static void +dispatch_nudge( int fd ) +{ + for (;;) + { + static char buf[1024]; + if ( read( fd, buf, sizeof(buf) ) < 0 ) + { + if ( errno != EAGAIN ) + perror(" steamcompmgr: dispatch_nudge: read failed" ); + break; + } + } +} + enum event_type { EVENT_X11, EVENT_VBLANK, + EVENT_NUDGE, EVENT_COUNT // keep last }; @@ -3284,6 +3300,12 @@ steamcompmgr_main (int argc, char **argv) } } + if ( pipe2( g_nudgePipe, O_CLOEXEC | O_NONBLOCK ) != 0 ) + { + perror( "steamcompmgr: pipe failed" ); + exit( 1 ); + } + const char *pchEnableVkBasalt = getenv( "ENABLE_VKBASALT" ); if ( pchEnableVkBasalt != nullptr && pchEnableVkBasalt[0] == '1' ) { @@ -3463,6 +3485,10 @@ steamcompmgr_main (int argc, char **argv) .fd = vblankFD, .events = POLLIN, }, + [ EVENT_NUDGE ] = { + .fd = g_nudgePipe[ 0 ], + .events = POLLIN, + }, }; for (;;) @@ -3486,15 +3512,14 @@ steamcompmgr_main (int argc, char **argv) } assert( !( pollfds[ EVENT_VBLANK ].revents & POLLHUP ) ); + assert( !( pollfds[ EVENT_NUDGE ].revents & POLLHUP ) ); if ( pollfds[ EVENT_X11 ].revents & POLLIN ) - { dispatch_x11( dpy, cursor.get() ); - } if ( pollfds[ EVENT_VBLANK ].revents & POLLIN ) - { vblank = dispatch_vblank( vblankFD ); - } + if ( pollfds[ EVENT_NUDGE ].revents & POLLIN ) + dispatch_nudge( g_nudgePipe[ 0 ] ); if ( run == false ) { @@ -3556,7 +3581,7 @@ steamcompmgr_main (int argc, char **argv) // make sure we keep pushing frames even if the app isn't updating. if (fadeOutWindow.id) { - XSendEvent(dpy, ourWindow, True, SubstructureRedirectMask, &nudgeEvent); + nudge_steamcompmgr(); } cursor->updatePosition(); diff --git a/src/steamcompmgr.hpp b/src/steamcompmgr.hpp index 5af2ca5..0e54798 100644 --- a/src/steamcompmgr.hpp +++ b/src/steamcompmgr.hpp @@ -87,3 +87,5 @@ extern float focusedWindowScaleX; extern float focusedWindowScaleY; extern float focusedWindowOffsetX; extern float focusedWindowOffsetY; + +void nudge_steamcompmgr( void ); diff --git a/src/wlserver.cpp b/src/wlserver.cpp index d724329..e0e5d6a 100644 --- a/src/wlserver.cpp +++ b/src/wlserver.cpp @@ -78,26 +78,6 @@ void sig_handler(int signal) run = false; } -void nudge_steamcompmgr(void) -{ - static bool bHasNestedDisplay = false; - static XEvent XWLExposeEvent = {}; - - if ( bHasNestedDisplay == false ) - { - g_XWLDpy = XOpenDisplay( wlserver.wlr.xwayland_server->display_name ); - - XWLExposeEvent.xclient.type = ClientMessage; - XWLExposeEvent.xclient.window = DefaultRootWindow( g_XWLDpy ); - XWLExposeEvent.xclient.format = 32; - - bHasNestedDisplay = true; - } - - XSendEvent( g_XWLDpy , DefaultRootWindow( g_XWLDpy ), True, SubstructureRedirectMask, &XWLExposeEvent); - XFlush( g_XWLDpy ); -} - extern const struct wlr_surface_role xwayland_surface_role; void xwayland_surface_role_commit(struct wlr_surface *wlr_surface) { diff --git a/src/wlserver.hpp b/src/wlserver.hpp index bbcae82..08ac226 100644 --- a/src/wlserver.hpp +++ b/src/wlserver.hpp @@ -70,8 +70,6 @@ int wlserver_init( int argc, char **argv, bool bIsNested ); int wlserver_run(void); -void nudge_steamcompmgr(void); - void wlserver_lock(void); void wlserver_unlock(void);