From 2d4b7a4e233c989f0555c8a3ca88a3cabffa0a84 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Sat, 30 Sep 2023 13:40:33 +0200 Subject: [PATCH] shell: Use new map/unmap events For xwayland we must listen on associate/dissociate to set up and tear down the map/unmap event handlers instead of during surface create/destroy. --- xdg_shell.c | 4 ++-- xwayland.c | 39 +++++++++++++++++++++++++++++++++------ xwayland.h | 2 ++ 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/xdg_shell.c b/xdg_shell.c index 9d75b84..046dbd8 100644 --- a/xdg_shell.c +++ b/xdg_shell.c @@ -238,9 +238,9 @@ handle_xdg_shell_surface_new(struct wl_listener *listener, void *data) xdg_shell_view->xdg_toplevel = xdg_surface->toplevel; xdg_shell_view->map.notify = handle_xdg_shell_surface_map; - wl_signal_add(&xdg_surface->events.map, &xdg_shell_view->map); + wl_signal_add(&xdg_surface->surface->events.map, &xdg_shell_view->map); xdg_shell_view->unmap.notify = handle_xdg_shell_surface_unmap; - wl_signal_add(&xdg_surface->events.unmap, &xdg_shell_view->unmap); + wl_signal_add(&xdg_surface->surface->events.unmap, &xdg_shell_view->unmap); xdg_shell_view->destroy.notify = handle_xdg_shell_surface_destroy; wl_signal_add(&xdg_surface->events.destroy, &xdg_shell_view->destroy); xdg_shell_view->request_fullscreen.notify = handle_xdg_shell_surface_request_fullscreen; diff --git a/xwayland.c b/xwayland.c index ef37a49..eec7fb9 100644 --- a/xwayland.c +++ b/xwayland.c @@ -41,8 +41,15 @@ static void get_geometry(struct cg_view *view, int *width_out, int *height_out) { struct cg_xwayland_view *xwayland_view = xwayland_view_from_view(view); - *width_out = xwayland_view->xwayland_surface->surface->current.width; - *height_out = xwayland_view->xwayland_surface->surface->current.height; + struct wlr_xwayland_surface *xsurface = xwayland_view->xwayland_surface; + if (xsurface->surface == NULL) { + *width_out = 0; + *height_out = 0; + return; + } + + *width_out = xsurface->surface->current.width; + *height_out = xsurface->surface->current.height; } static bool @@ -151,6 +158,26 @@ static const struct cg_view_impl xwayland_view_impl = { .destroy = destroy, }; +void +handle_xwayland_associate(struct wl_listener *listener, void *data) +{ + struct cg_xwayland_view *xwayland_view = wl_container_of(listener, xwayland_view, associate); + struct wlr_xwayland_surface *xsurface = xwayland_view->xwayland_surface; + + xwayland_view->map.notify = handle_xwayland_surface_map; + wl_signal_add(&xsurface->surface->events.map, &xwayland_view->map); + xwayland_view->unmap.notify = handle_xwayland_surface_unmap; + wl_signal_add(&xsurface->surface->events.unmap, &xwayland_view->unmap); +} + +void +handle_xwayland_dissociate(struct wl_listener *listener, void *data) +{ + struct cg_xwayland_view *xwayland_view = wl_container_of(listener, xwayland_view, dissociate); + wl_list_remove(&xwayland_view->map.link); + wl_list_remove(&xwayland_view->unmap.link); +} + void handle_xwayland_surface_new(struct wl_listener *listener, void *data) { @@ -166,10 +193,10 @@ handle_xwayland_surface_new(struct wl_listener *listener, void *data) view_init(&xwayland_view->view, server, CAGE_XWAYLAND_VIEW, &xwayland_view_impl); xwayland_view->xwayland_surface = xwayland_surface; - xwayland_view->map.notify = handle_xwayland_surface_map; - wl_signal_add(&xwayland_surface->events.map, &xwayland_view->map); - xwayland_view->unmap.notify = handle_xwayland_surface_unmap; - wl_signal_add(&xwayland_surface->events.unmap, &xwayland_view->unmap); + xwayland_view->associate.notify = handle_xwayland_associate; + wl_signal_add(&xwayland_surface->events.associate, &xwayland_view->associate); + xwayland_view->dissociate.notify = handle_xwayland_dissociate; + wl_signal_add(&xwayland_surface->events.dissociate, &xwayland_view->dissociate); xwayland_view->destroy.notify = handle_xwayland_surface_destroy; wl_signal_add(&xwayland_surface->events.destroy, &xwayland_view->destroy); xwayland_view->request_fullscreen.notify = handle_xwayland_surface_request_fullscreen; diff --git a/xwayland.h b/xwayland.h index 31edb8f..bca4b02 100644 --- a/xwayland.h +++ b/xwayland.h @@ -10,6 +10,8 @@ struct cg_xwayland_view { struct cg_view view; struct wlr_xwayland_surface *xwayland_surface; struct wl_listener destroy; + struct wl_listener associate; + struct wl_listener dissociate; struct wl_listener unmap; struct wl_listener map; struct wl_listener request_fullscreen;