From 6c2a7ab83b8849524737add7e427f9447bbc2f38 Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Sun, 8 Oct 2023 06:12:45 +0100 Subject: [PATCH] wlserver: Handle pending surfaces in set_wl_id when we already have an existing surface --- src/wlserver.cpp | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/wlserver.cpp b/src/wlserver.cpp index 33503d6f2..c28db9ea6 100644 --- a/src/wlserver.cpp +++ b/src/wlserver.cpp @@ -2046,21 +2046,29 @@ void gamescope_xwayland_server_t::set_wl_id( struct wlserver_x11_surface_info *s { if (surf->wl_id) { - struct wl_resource *old_resource = wl_client_get_object( xwayland_server->client, surf->wl_id ); - if (!old_resource) + if (surf->main_surface) { - wl_log.errorf("wlserver_x11_surface_info had bad wl_id? Oh no! %d", surf->wl_id); - return; + struct wl_resource *old_resource = wl_client_get_object( xwayland_server->client, surf->wl_id ); + if (!old_resource) + { + wl_log.errorf("wlserver_x11_surface_info had bad wl_id? Oh no! %d", surf->wl_id); + return; + } + wlr_surface *old_wlr_surf = wlr_surface_from_resource( old_resource ); + if (!old_wlr_surf) + { + wl_log.errorf("wlserver_x11_surface_info wl_id's was not a wlr_surf?! Oh no! %d", surf->wl_id); + return; + } + + wlserver_wl_surface_info *old_surface_info = get_wl_surface_info(old_wlr_surf); + old_surface_info->x11_surface = nullptr; } - wlr_surface *old_wlr_surf = wlr_surface_from_resource( old_resource ); - if (!old_wlr_surf) + else { - wl_log.errorf("wlserver_x11_surface_info wl_id's was not a wlr_surf?! Oh no! %d", surf->wl_id); - return; + wl_list_remove( &surf->pending_link ); + wl_list_init( &surf->pending_link ); } - - wlserver_wl_surface_info *old_surface_info = get_wl_surface_info(old_wlr_surf); - old_surface_info->x11_surface = nullptr; } surf->wl_id = id;