Merge pull request #526 from Consolatis/issue/317_gimp_remap

xwayland: Keep view->xwayland_surface and view->surface in sync
This commit is contained in:
Johan Malm 2022-09-09 15:32:14 +01:00 committed by GitHub
commit f47de15f98
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 0 deletions

View file

@ -349,6 +349,7 @@ struct view {
struct wl_listener map;
struct wl_listener unmap;
struct wl_listener destroy;
struct wl_listener surface_destroy;
struct wl_listener commit;
struct wl_listener request_move;
struct wl_listener request_resize;

View file

@ -68,6 +68,11 @@ static void
handle_map(struct wl_listener *listener, void *data)
{
struct view *view = wl_container_of(listener, view, map);
struct wlr_xwayland_surface *xsurface = data;
if (xsurface != view->xwayland_surface) {
xsurface->data = view;
view->xwayland_surface = xsurface;
}
view->impl->map(view);
}
@ -90,6 +95,18 @@ handle_unmap(struct wl_listener *listener, void *data)
}
}
static void
handle_surface_destroy(struct wl_listener *listener, void *data)
{
struct view *view = wl_container_of(listener, view, surface_destroy);
assert(view->type == LAB_XWAYLAND_VIEW);
struct wlr_surface *surface = data;
assert(surface == view->surface);
view->surface = NULL;
wl_list_remove(&view->surface_destroy.link);
}
static void
handle_destroy(struct wl_listener *listener, void *data)
{
@ -97,6 +114,15 @@ handle_destroy(struct wl_listener *listener, void *data)
assert(view->type == LAB_XWAYLAND_VIEW);
/* Reset XWayland specific surface for good measure */
if (view->surface) {
/*
* We got the destroy signal from
* wlr_xwayland_surface before the
* destroy signal from wlr_surface.
*/
wl_list_remove(&view->surface_destroy.link);
}
view->surface = NULL;
view->xwayland_surface = NULL;
/* Remove XWayland specific handlers */
@ -332,7 +358,16 @@ map(struct view *view)
}
if (view->surface != view->xwayland_surface->surface) {
if (view->surface) {
wl_list_remove(&view->surface_destroy.link);
}
view->surface = view->xwayland_surface->surface;
/* Required to set the surface to NULL when destroyed by the client */
view->surface_destroy.notify = handle_surface_destroy;
wl_signal_add(&view->surface->events.destroy, &view->surface_destroy);
/* Will be free'd automatically once the surface is being destroyed */
struct wlr_scene_tree *tree = wlr_scene_subsurface_tree_create(
view->scene_tree, view->surface);
if (!tree) {