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.
This commit is contained in:
Kenny Levinsen 2023-09-30 13:40:33 +02:00 committed by Simon Ser
parent 4ea6a8b1a7
commit 2d4b7a4e23
3 changed files with 37 additions and 8 deletions

View file

@ -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->xdg_toplevel = xdg_surface->toplevel;
xdg_shell_view->map.notify = handle_xdg_shell_surface_map; 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; 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; xdg_shell_view->destroy.notify = handle_xdg_shell_surface_destroy;
wl_signal_add(&xdg_surface->events.destroy, &xdg_shell_view->destroy); wl_signal_add(&xdg_surface->events.destroy, &xdg_shell_view->destroy);
xdg_shell_view->request_fullscreen.notify = handle_xdg_shell_surface_request_fullscreen; xdg_shell_view->request_fullscreen.notify = handle_xdg_shell_surface_request_fullscreen;

View file

@ -41,8 +41,15 @@ static void
get_geometry(struct cg_view *view, int *width_out, int *height_out) get_geometry(struct cg_view *view, int *width_out, int *height_out)
{ {
struct cg_xwayland_view *xwayland_view = xwayland_view_from_view(view); struct cg_xwayland_view *xwayland_view = xwayland_view_from_view(view);
*width_out = xwayland_view->xwayland_surface->surface->current.width; struct wlr_xwayland_surface *xsurface = xwayland_view->xwayland_surface;
*height_out = xwayland_view->xwayland_surface->surface->current.height; 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 static bool
@ -151,6 +158,26 @@ static const struct cg_view_impl xwayland_view_impl = {
.destroy = destroy, .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 void
handle_xwayland_surface_new(struct wl_listener *listener, void *data) 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); view_init(&xwayland_view->view, server, CAGE_XWAYLAND_VIEW, &xwayland_view_impl);
xwayland_view->xwayland_surface = xwayland_surface; xwayland_view->xwayland_surface = xwayland_surface;
xwayland_view->map.notify = handle_xwayland_surface_map; xwayland_view->associate.notify = handle_xwayland_associate;
wl_signal_add(&xwayland_surface->events.map, &xwayland_view->map); wl_signal_add(&xwayland_surface->events.associate, &xwayland_view->associate);
xwayland_view->unmap.notify = handle_xwayland_surface_unmap; xwayland_view->dissociate.notify = handle_xwayland_dissociate;
wl_signal_add(&xwayland_surface->events.unmap, &xwayland_view->unmap); wl_signal_add(&xwayland_surface->events.dissociate, &xwayland_view->dissociate);
xwayland_view->destroy.notify = handle_xwayland_surface_destroy; xwayland_view->destroy.notify = handle_xwayland_surface_destroy;
wl_signal_add(&xwayland_surface->events.destroy, &xwayland_view->destroy); wl_signal_add(&xwayland_surface->events.destroy, &xwayland_view->destroy);
xwayland_view->request_fullscreen.notify = handle_xwayland_surface_request_fullscreen; xwayland_view->request_fullscreen.notify = handle_xwayland_surface_request_fullscreen;

View file

@ -10,6 +10,8 @@ struct cg_xwayland_view {
struct cg_view view; struct cg_view view;
struct wlr_xwayland_surface *xwayland_surface; struct wlr_xwayland_surface *xwayland_surface;
struct wl_listener destroy; struct wl_listener destroy;
struct wl_listener associate;
struct wl_listener dissociate;
struct wl_listener unmap; struct wl_listener unmap;
struct wl_listener map; struct wl_listener map;
struct wl_listener request_fullscreen; struct wl_listener request_fullscreen;