diff --git a/src/steamcompmgr.c b/src/steamcompmgr.c index 155900d..7715aaf 100644 --- a/src/steamcompmgr.c +++ b/src/steamcompmgr.c @@ -1416,6 +1416,8 @@ static void handle_wl_surface_id(Display *dpy, win *w, long surfaceID) { struct wlr_surface *surface = NULL; + + wlserver_lock(); struct wl_resource *resource = wl_client_get_object(wlserver.wlr.xwayland->client, surfaceID); if (resource) { @@ -1424,14 +1426,18 @@ handle_wl_surface_id(Display *dpy, win *w, long surfaceID) else { fprintf (stderr, "wayland surface for window not found, implement pending list for late surface notification\n"); + wlserver_unlock(); return; } if (!wlr_surface_set_role(surface, &xwayland_surface_role, w, NULL, 0)) { fprintf (stderr, "Failed to set xwayland surface role"); + wlserver_unlock(); return; } + + wlserver_unlock(); w->wlrsurface = surface; } @@ -1587,7 +1593,9 @@ void check_new_wayland_res(void) // Acknowledge previous one, seems we can get hangs if we don't. struct timespec now; clock_gettime(CLOCK_MONOTONIC, &now); + wlserver_lock(); wlr_surface_send_frame_done(w->wlrsurface, &now); + wlserver_unlock(); } w->committed = True; @@ -2056,7 +2064,9 @@ steamcompmgr_main (int argc, char **argv) if ( w->wlrsurface && w->committed == True ) { // Acknowledge commit once. + wlserver_lock(); wlr_surface_send_frame_done(w->wlrsurface, &now); + wlserver_unlock(); w->committed = False; } diff --git a/src/wlserver.c b/src/wlserver.c index 39d4264..0393d20 100644 --- a/src/wlserver.c +++ b/src/wlserver.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -164,9 +165,31 @@ int wlserver_init(int argc, char **argv, Bool bIsNested) { return 0; } +pthread_mutex_t waylock = PTHREAD_MUTEX_INITIALIZER; + +void wlserver_lock(void) +{ + pthread_mutex_lock(&waylock); +} + +void wlserver_unlock(void) +{ + pthread_mutex_unlock(&waylock); +} + int wlserver_run(void) { - wl_display_run(wlserver.wl_display); + while ( 1 ) + { + wlserver_lock(); + wl_display_flush_clients(wlserver.wl_display); + int ret = wl_event_loop_dispatch(wlserver.wl_event_loop, 0); + wlserver_unlock(); + if (ret < 0) { + break; + } + } + // We need to shutdown Xwayland before disconnecting all clients, otherwise // wlroots will restart it automatically. wlr_xwayland_destroy(wlserver.wlr.xwayland); diff --git a/src/wlserver.h b/src/wlserver.h index 3ed57f2..2878f1c 100644 --- a/src/wlserver.h +++ b/src/wlserver.h @@ -46,6 +46,9 @@ int wlserver_run(void); void nudge_steamcompmgr(void); +void wlserver_lock(void); +void wlserver_unlock(void); + #ifndef C_SIDE } #endif