From 8fe3aa29da56be16faa73aca947647bd60cd4a94 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 11 May 2022 13:57:51 +0200 Subject: [PATCH] xdg-shell: specify version in wlr_xdg_shell_create With protocol additions such as [1], compositors currently have no way to opt out of the version upgrade. The protocol upgrade will always be backwards-compatible but may require new compositor features. The status quo doesn't make it possible to ship a protocol addition without breaking the wlroots API. This will be an issue for API stabilization [2]. To address this, let compositors provide a maximum version in the function creating the global. We need to support all previous versions of the interface anyways because of older clients. This mechanism works the same way as Wayland clients passing a version in wl_global.bind. [1]: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/3514 [2]: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/1008 References: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3397 --- examples/scene-graph.c | 2 +- include/wlr/types/wlr_xdg_shell.h | 7 ++++++- tinywl/tinywl.c | 7 ++++--- types/xdg_shell/wlr_xdg_shell.c | 8 ++++++-- types/xdg_shell/wlr_xdg_toplevel.c | 3 ++- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/examples/scene-graph.c b/examples/scene-graph.c index c3ce0589..f57ef1f2 100644 --- a/examples/scene-graph.c +++ b/examples/scene-graph.c @@ -169,7 +169,7 @@ int main(int argc, char *argv[]) { struct wlr_compositor *compositor = wlr_compositor_create(server.display, server.renderer); - wlr_xdg_shell_create(server.display); + wlr_xdg_shell_create(server.display, 2); server.new_output.notify = server_handle_new_output; wl_signal_add(&server.backend->events.new_output, &server.new_output); diff --git a/include/wlr/types/wlr_xdg_shell.h b/include/wlr/types/wlr_xdg_shell.h index 95c6ee6c..e6168317 100644 --- a/include/wlr/types/wlr_xdg_shell.h +++ b/include/wlr/types/wlr_xdg_shell.h @@ -17,6 +17,7 @@ struct wlr_xdg_shell { struct wl_global *global; + uint32_t version; struct wl_list clients; struct wl_list popup_grabs; uint32_t ping_timeout; @@ -263,7 +264,11 @@ struct wlr_xdg_toplevel_show_window_menu_event { uint32_t x, y; }; -struct wlr_xdg_shell *wlr_xdg_shell_create(struct wl_display *display); +/** + * Create the xdg_wm_base global with the specified version. + */ +struct wlr_xdg_shell *wlr_xdg_shell_create(struct wl_display *display, + uint32_t version); /** Get the corresponding wlr_xdg_surface from a resource. * diff --git a/tinywl/tinywl.c b/tinywl/tinywl.c index 633b3f25..783cc182 100644 --- a/tinywl/tinywl.c +++ b/tinywl/tinywl.c @@ -853,13 +853,14 @@ int main(int argc, char *argv[]) { server.scene = wlr_scene_create(); wlr_scene_attach_output_layout(server.scene, server.output_layout); - /* Set up the xdg-shell. The xdg-shell is a Wayland protocol which is used - * for application windows. For more detail on shells, refer to my article: + /* Set up xdg-shell version 2. The xdg-shell is a Wayland protocol which is + * used for application windows. For more detail on shells, refer to my + * article: * * https://drewdevault.com/2018/07/29/Wayland-shells.html */ wl_list_init(&server.views); - server.xdg_shell = wlr_xdg_shell_create(server.wl_display); + server.xdg_shell = wlr_xdg_shell_create(server.wl_display, 2); server.new_xdg_surface.notify = server_new_xdg_surface; wl_signal_add(&server.xdg_shell->events.new_surface, &server.new_xdg_surface); diff --git a/types/xdg_shell/wlr_xdg_shell.c b/types/xdg_shell/wlr_xdg_shell.c index 0b130262..0d40b553 100644 --- a/types/xdg_shell/wlr_xdg_shell.c +++ b/types/xdg_shell/wlr_xdg_shell.c @@ -137,20 +137,24 @@ static void handle_display_destroy(struct wl_listener *listener, void *data) { free(xdg_shell); } -struct wlr_xdg_shell *wlr_xdg_shell_create(struct wl_display *display) { +struct wlr_xdg_shell *wlr_xdg_shell_create(struct wl_display *display, + uint32_t version) { + assert(version <= WM_BASE_VERSION); + struct wlr_xdg_shell *xdg_shell = calloc(1, sizeof(struct wlr_xdg_shell)); if (!xdg_shell) { return NULL; } + xdg_shell->version = version; xdg_shell->ping_timeout = 10000; wl_list_init(&xdg_shell->clients); wl_list_init(&xdg_shell->popup_grabs); struct wl_global *global = wl_global_create(display, - &xdg_wm_base_interface, WM_BASE_VERSION, xdg_shell, xdg_shell_bind); + &xdg_wm_base_interface, version, xdg_shell, xdg_shell_bind); if (!global) { free(xdg_shell); return NULL; diff --git a/types/xdg_shell/wlr_xdg_toplevel.c b/types/xdg_shell/wlr_xdg_toplevel.c index 1cb12ec9..750efeda 100644 --- a/types/xdg_shell/wlr_xdg_toplevel.c +++ b/types/xdg_shell/wlr_xdg_toplevel.c @@ -114,7 +114,7 @@ void wlr_xdg_toplevel_set_parent(struct wlr_xdg_toplevel *toplevel, if (toplevel->parent) { wl_list_remove(&toplevel->parent_unmap.link); } - + if (parent && parent->base->mapped) { toplevel->parent = parent; toplevel->parent_unmap.notify = handle_parent_unmap; @@ -497,6 +497,7 @@ uint32_t wlr_xdg_toplevel_set_resizing(struct wlr_xdg_toplevel *toplevel, uint32_t wlr_xdg_toplevel_set_tiled(struct wlr_xdg_toplevel *toplevel, uint32_t tiled) { + assert(toplevel->base->client->shell->version >= 2); toplevel->scheduled.tiled = tiled; return wlr_xdg_surface_schedule_configure(toplevel->base); }