Replace nudge X11 events with pipe

Avoids the roundtrip through the X11 server. Avoids having to connect
to the X11 server from multiple threads.
This commit is contained in:
Simon Ser 2021-06-10 14:48:09 +02:00
parent 0194432185
commit 33f207d6a1
4 changed files with 42 additions and 37 deletions

View file

@ -171,7 +171,6 @@ bool focusControlled;
std::vector< uint32_t > vecFocuscontrolAppIDs; std::vector< uint32_t > vecFocuscontrolAppIDs;
static Window ourWindow; static Window ourWindow;
static XEvent nudgeEvent;
Bool gameFocused; Bool gameFocused;
@ -280,6 +279,8 @@ static Bool useXRes = True;
std::mutex wayland_commit_lock; std::mutex wayland_commit_lock;
std::vector<ResListEntry_t> wayland_commit_queue; std::vector<ResListEntry_t> wayland_commit_queue;
static int g_nudgePipe[2];
// poor man's semaphore // poor man's semaphore
class sem class sem
{ {
@ -361,9 +362,7 @@ retry:
listCommitsDone.push_back( commitID ); listCommitsDone.push_back( commitID );
} }
static Display *threadDPY = XOpenDisplay ( wlserver_get_nested_display_name() ); nudge_steamcompmgr();
XSendEvent( threadDPY, ourWindow, True, SubstructureRedirectMask, &nudgeEvent );
XFlush( threadDPY );
goto retry; goto retry;
} }
@ -733,8 +732,7 @@ void MouseCursor::checkSuspension()
// We're hiding the cursor, force redraw if we were showing it // We're hiding the cursor, force redraw if we were showing it
if (window && !m_imageEmpty ) { if (window && !m_imageEmpty ) {
hasRepaint = true; hasRepaint = true;
XSendEvent(m_display, ourWindow, true, SubstructureRedirectMask, &nudgeEvent); nudge_steamcompmgr();
XFlush(m_display);
} }
} }
} }
@ -2810,10 +2808,6 @@ register_cm (Display *dpy)
ourWindow = w; ourWindow = w;
nudgeEvent.xclient.type = ClientMessage;
nudgeEvent.xclient.window = ourWindow;
nudgeEvent.xclient.format = 32;
return True; return True;
} }
@ -2898,6 +2892,12 @@ void handle_done_commits( void )
listCommitsDone.clear(); 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 ) void check_new_wayland_res( void )
{ {
// When importing buffer, we'll potentially need to perform operations with // When importing buffer, we'll potentially need to perform operations with
@ -3217,9 +3217,25 @@ dispatch_vblank( int fd )
return vblank; 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 { enum event_type {
EVENT_X11, EVENT_X11,
EVENT_VBLANK, EVENT_VBLANK,
EVENT_NUDGE,
EVENT_COUNT // keep last 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" ); const char *pchEnableVkBasalt = getenv( "ENABLE_VKBASALT" );
if ( pchEnableVkBasalt != nullptr && pchEnableVkBasalt[0] == '1' ) if ( pchEnableVkBasalt != nullptr && pchEnableVkBasalt[0] == '1' )
{ {
@ -3463,6 +3485,10 @@ steamcompmgr_main (int argc, char **argv)
.fd = vblankFD, .fd = vblankFD,
.events = POLLIN, .events = POLLIN,
}, },
[ EVENT_NUDGE ] = {
.fd = g_nudgePipe[ 0 ],
.events = POLLIN,
},
}; };
for (;;) for (;;)
@ -3486,15 +3512,14 @@ steamcompmgr_main (int argc, char **argv)
} }
assert( !( pollfds[ EVENT_VBLANK ].revents & POLLHUP ) ); assert( !( pollfds[ EVENT_VBLANK ].revents & POLLHUP ) );
assert( !( pollfds[ EVENT_NUDGE ].revents & POLLHUP ) );
if ( pollfds[ EVENT_X11 ].revents & POLLIN ) if ( pollfds[ EVENT_X11 ].revents & POLLIN )
{
dispatch_x11( dpy, cursor.get() ); dispatch_x11( dpy, cursor.get() );
}
if ( pollfds[ EVENT_VBLANK ].revents & POLLIN ) if ( pollfds[ EVENT_VBLANK ].revents & POLLIN )
{
vblank = dispatch_vblank( vblankFD ); vblank = dispatch_vblank( vblankFD );
} if ( pollfds[ EVENT_NUDGE ].revents & POLLIN )
dispatch_nudge( g_nudgePipe[ 0 ] );
if ( run == false ) 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. // make sure we keep pushing frames even if the app isn't updating.
if (fadeOutWindow.id) if (fadeOutWindow.id)
{ {
XSendEvent(dpy, ourWindow, True, SubstructureRedirectMask, &nudgeEvent); nudge_steamcompmgr();
} }
cursor->updatePosition(); cursor->updatePosition();

View file

@ -87,3 +87,5 @@ extern float focusedWindowScaleX;
extern float focusedWindowScaleY; extern float focusedWindowScaleY;
extern float focusedWindowOffsetX; extern float focusedWindowOffsetX;
extern float focusedWindowOffsetY; extern float focusedWindowOffsetY;
void nudge_steamcompmgr( void );

View file

@ -78,26 +78,6 @@ void sig_handler(int signal)
run = false; 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; extern const struct wlr_surface_role xwayland_surface_role;
void xwayland_surface_role_commit(struct wlr_surface *wlr_surface) { void xwayland_surface_role_commit(struct wlr_surface *wlr_surface) {

View file

@ -70,8 +70,6 @@ int wlserver_init( int argc, char **argv, bool bIsNested );
int wlserver_run(void); int wlserver_run(void);
void nudge_steamcompmgr(void);
void wlserver_lock(void); void wlserver_lock(void);
void wlserver_unlock(void); void wlserver_unlock(void);