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.
This commit is contained in:
Simon Ser 2024-08-24 15:44:46 +02:00
parent 17af2f7be9
commit fa90174607
3 changed files with 24 additions and 2 deletions

8
view.c
View file

@ -67,7 +67,9 @@ view_maximize(struct cg_view *view, struct wlr_box *layout_box)
view->lx = layout_box->x; view->lx = layout_box->x;
view->ly = layout_box->y; 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); 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->lx = (layout_box->width - width) / 2;
view->ly = (layout_box->height - height) / 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 void

View file

@ -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); 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 static void
handle_xdg_shell_surface_destroy(struct wl_listener *listener, void *data) 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_xdg_shell_view *xdg_shell_view = wl_container_of(listener, xdg_shell_view, destroy);
struct cg_view *view = &xdg_shell_view->view; 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->map.link);
wl_list_remove(&xdg_shell_view->unmap.link); wl_list_remove(&xdg_shell_view->unmap.link);
wl_list_remove(&xdg_shell_view->destroy.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); view_init(&xdg_shell_view->view, server, CAGE_XDG_SHELL_VIEW, &xdg_shell_view_impl);
xdg_shell_view->xdg_toplevel = toplevel; 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; xdg_shell_view->map.notify = handle_xdg_shell_surface_map;
wl_signal_add(&toplevel->base->surface->events.map, &xdg_shell_view->map); wl_signal_add(&toplevel->base->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;

View file

@ -12,6 +12,7 @@ struct cg_xdg_shell_view {
struct wlr_xdg_toplevel *xdg_toplevel; struct wlr_xdg_toplevel *xdg_toplevel;
struct wl_listener destroy; struct wl_listener destroy;
struct wl_listener commit;
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;