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
This commit is contained in:
Simon Ser 2022-05-11 13:57:51 +02:00 committed by Isaac Freund
parent 19896e7fb6
commit 8fe3aa29da
5 changed files with 19 additions and 8 deletions

View file

@ -169,7 +169,7 @@ int main(int argc, char *argv[]) {
struct wlr_compositor *compositor = struct wlr_compositor *compositor =
wlr_compositor_create(server.display, server.renderer); 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; server.new_output.notify = server_handle_new_output;
wl_signal_add(&server.backend->events.new_output, &server.new_output); wl_signal_add(&server.backend->events.new_output, &server.new_output);

View file

@ -17,6 +17,7 @@
struct wlr_xdg_shell { struct wlr_xdg_shell {
struct wl_global *global; struct wl_global *global;
uint32_t version;
struct wl_list clients; struct wl_list clients;
struct wl_list popup_grabs; struct wl_list popup_grabs;
uint32_t ping_timeout; uint32_t ping_timeout;
@ -263,7 +264,11 @@ struct wlr_xdg_toplevel_show_window_menu_event {
uint32_t x, y; 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. /** Get the corresponding wlr_xdg_surface from a resource.
* *

View file

@ -853,13 +853,14 @@ int main(int argc, char *argv[]) {
server.scene = wlr_scene_create(); server.scene = wlr_scene_create();
wlr_scene_attach_output_layout(server.scene, server.output_layout); 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 /* Set up xdg-shell version 2. The xdg-shell is a Wayland protocol which is
* for application windows. For more detail on shells, refer to my article: * used for application windows. For more detail on shells, refer to my
* article:
* *
* https://drewdevault.com/2018/07/29/Wayland-shells.html * https://drewdevault.com/2018/07/29/Wayland-shells.html
*/ */
wl_list_init(&server.views); 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; server.new_xdg_surface.notify = server_new_xdg_surface;
wl_signal_add(&server.xdg_shell->events.new_surface, wl_signal_add(&server.xdg_shell->events.new_surface,
&server.new_xdg_surface); &server.new_xdg_surface);

View file

@ -137,20 +137,24 @@ static void handle_display_destroy(struct wl_listener *listener, void *data) {
free(xdg_shell); 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 = struct wlr_xdg_shell *xdg_shell =
calloc(1, sizeof(struct wlr_xdg_shell)); calloc(1, sizeof(struct wlr_xdg_shell));
if (!xdg_shell) { if (!xdg_shell) {
return NULL; return NULL;
} }
xdg_shell->version = version;
xdg_shell->ping_timeout = 10000; xdg_shell->ping_timeout = 10000;
wl_list_init(&xdg_shell->clients); wl_list_init(&xdg_shell->clients);
wl_list_init(&xdg_shell->popup_grabs); wl_list_init(&xdg_shell->popup_grabs);
struct wl_global *global = wl_global_create(display, 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) { if (!global) {
free(xdg_shell); free(xdg_shell);
return NULL; return NULL;

View file

@ -114,7 +114,7 @@ void wlr_xdg_toplevel_set_parent(struct wlr_xdg_toplevel *toplevel,
if (toplevel->parent) { if (toplevel->parent) {
wl_list_remove(&toplevel->parent_unmap.link); wl_list_remove(&toplevel->parent_unmap.link);
} }
if (parent && parent->base->mapped) { if (parent && parent->base->mapped) {
toplevel->parent = parent; toplevel->parent = parent;
toplevel->parent_unmap.notify = handle_parent_unmap; 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 wlr_xdg_toplevel_set_tiled(struct wlr_xdg_toplevel *toplevel,
uint32_t tiled) { uint32_t tiled) {
assert(toplevel->base->client->shell->version >= 2);
toplevel->scheduled.tiled = tiled; toplevel->scheduled.tiled = tiled;
return wlr_xdg_surface_schedule_configure(toplevel->base); return wlr_xdg_surface_schedule_configure(toplevel->base);
} }