From fa901746071522b963de9c2ec7a380452ad65acd Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Sat, 24 Aug 2024 15:44:46 +0200 Subject: [PATCH] xdg_shell: configure surface on initial commit Instead of waiting for the surface to be mapped before sending a configure event, do it on initial commit. Note, wlroots 0.18 no longer sends automatic configure events on initial commit. --- view.c | 8 ++++++-- xdg_shell.c | 17 +++++++++++++++++ xdg_shell.h | 1 + 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/view.c b/view.c index 8948580..8cbeb5e 100644 --- a/view.c +++ b/view.c @@ -67,7 +67,9 @@ view_maximize(struct cg_view *view, struct wlr_box *layout_box) view->lx = layout_box->x; view->ly = layout_box->y; - wlr_scene_node_set_position(&view->scene_tree->node, view->lx, view->ly); + if (view->scene_tree) { + wlr_scene_node_set_position(&view->scene_tree->node, view->lx, view->ly); + } view->impl->maximize(view, layout_box->width, layout_box->height); } @@ -81,7 +83,9 @@ view_center(struct cg_view *view, struct wlr_box *layout_box) view->lx = (layout_box->width - width) / 2; view->ly = (layout_box->height - height) / 2; - wlr_scene_node_set_position(&view->scene_tree->node, view->lx, view->ly); + if (view->scene_tree) { + wlr_scene_node_set_position(&view->scene_tree->node, view->lx, view->ly); + } } void diff --git a/xdg_shell.c b/xdg_shell.c index c65c496..783e7f3 100644 --- a/xdg_shell.c +++ b/xdg_shell.c @@ -195,12 +195,27 @@ handle_xdg_shell_surface_map(struct wl_listener *listener, void *data) view_map(view, xdg_shell_view->xdg_toplevel->base->surface); } +static void +handle_xdg_shell_surface_commit(struct wl_listener *listener, void *data) +{ + struct cg_xdg_shell_view *xdg_shell_view = wl_container_of(listener, xdg_shell_view, commit); + + if (!xdg_shell_view->xdg_toplevel->base->initial_commit) { + return; + } + + /* When an xdg_surface performs an initial commit, the compositor must + * reply with a configure so the client can map the surface. */ + view_position(&xdg_shell_view->view); +} + static void handle_xdg_shell_surface_destroy(struct wl_listener *listener, void *data) { struct cg_xdg_shell_view *xdg_shell_view = wl_container_of(listener, xdg_shell_view, destroy); struct cg_view *view = &xdg_shell_view->view; + wl_list_remove(&xdg_shell_view->commit.link); wl_list_remove(&xdg_shell_view->map.link); wl_list_remove(&xdg_shell_view->unmap.link); wl_list_remove(&xdg_shell_view->destroy.link); @@ -235,6 +250,8 @@ handle_new_xdg_toplevel(struct wl_listener *listener, void *data) view_init(&xdg_shell_view->view, server, CAGE_XDG_SHELL_VIEW, &xdg_shell_view_impl); xdg_shell_view->xdg_toplevel = toplevel; + xdg_shell_view->commit.notify = handle_xdg_shell_surface_commit; + wl_signal_add(&toplevel->base->surface->events.commit, &xdg_shell_view->commit); xdg_shell_view->map.notify = handle_xdg_shell_surface_map; wl_signal_add(&toplevel->base->surface->events.map, &xdg_shell_view->map); xdg_shell_view->unmap.notify = handle_xdg_shell_surface_unmap; diff --git a/xdg_shell.h b/xdg_shell.h index 0175c70..077a9ae 100644 --- a/xdg_shell.h +++ b/xdg_shell.h @@ -12,6 +12,7 @@ struct cg_xdg_shell_view { struct wlr_xdg_toplevel *xdg_toplevel; struct wl_listener destroy; + struct wl_listener commit; struct wl_listener unmap; struct wl_listener map; struct wl_listener request_fullscreen;