From e76954e1cf9fd1b89ac6c6cf27c977cbf955daee Mon Sep 17 00:00:00 2001 From: Ryan Neph Date: Tue, 13 Feb 2024 15:53:15 -0800 Subject: [PATCH] vm_tools: sommelier: no need to require xdg_wm_base version 3 Requiring version 3 of the actual server seems to have been unintentionally enforced when support for it was added to Sommelier. I saw no internal reliance on version 3 in other aspects of Sommelier's implementation, so we should remain flexible and only passthrough requirements of the guest-side client, filtered by Sommelier's highest level of support. BUG=b:325125144 TEST=run sommelier with host-side sway as wayland server. TEST=(in borealis vm) steam Change-Id: Ic16080fdce66af5857efecafb143710d58863537 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/5293079 Reviewed-by: Max Lee Reviewed-by: Chloe Pelling Tested-by: Ryan Neph Commit-Queue: Ryan Neph --- sommelier-xdg-shell.cc | 15 ++++++++------- sommelier-xdg-shell.h | 2 ++ sommelier.cc | 7 +++++-- sommelier.h | 5 +++-- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/sommelier-xdg-shell.cc b/sommelier-xdg-shell.cc index 6a4f21d..3ec2f59 100644 --- a/sommelier-xdg-shell.cc +++ b/sommelier-xdg-shell.cc @@ -440,17 +440,18 @@ static void sl_bind_host_xdg_shell(struct wl_client* client, struct sl_context* ctx = (struct sl_context*)data; struct sl_host_xdg_shell* host = new sl_host_xdg_shell(); host->ctx = ctx; - host->resource = wl_resource_create(client, &xdg_wm_base_interface, - std::min(version, XDG_SHELL_VERSION), id); + host->resource = + wl_resource_create(client, &xdg_wm_base_interface, version, id); wl_resource_set_implementation(host->resource, &sl_xdg_shell_implementation, host, sl_destroy_host_xdg_shell); - host->proxy = static_cast(wl_registry_bind( - wl_display_get_registry(ctx->display), ctx->xdg_shell->id, - &xdg_wm_base_interface, std::min(version, XDG_SHELL_VERSION))); + host->proxy = static_cast( + wl_registry_bind(wl_display_get_registry(ctx->display), + ctx->xdg_shell->id, &xdg_wm_base_interface, version)); xdg_wm_base_shim()->add_listener(host->proxy, &sl_xdg_shell_listener, host); } -struct sl_global* sl_xdg_shell_global_create(struct sl_context* ctx) { - return sl_global_create(ctx, &xdg_wm_base_interface, XDG_SHELL_VERSION, ctx, +struct sl_global* sl_xdg_shell_global_create(struct sl_context* ctx, + uint32_t version) { + return sl_global_create(ctx, &xdg_wm_base_interface, version, ctx, sl_bind_host_xdg_shell); } diff --git a/sommelier-xdg-shell.h b/sommelier-xdg-shell.h index 23efb3d..bff60a0 100644 --- a/sommelier-xdg-shell.h +++ b/sommelier-xdg-shell.h @@ -11,6 +11,8 @@ #include "sommelier-util.h" // NOLINT(build/include_directory) #include "xdg-shell-client-protocol.h" // NOLINT(build/include_directory) +#define SL_XDG_SHELL_MAX_VERSION 3u + struct sl_host_xdg_shell { struct sl_context* ctx; struct wl_resource* resource; diff --git a/sommelier.cc b/sommelier.cc index a13137a..7e2bc74 100644 --- a/sommelier.cc +++ b/sommelier.cc @@ -10,6 +10,7 @@ #include "sommelier-tracing.h" // NOLINT(build/include_directory) #include "sommelier-transform.h" // NOLINT(build/include_directory) #include "sommelier-window.h" // NOLINT(build/include_directory) +#include "sommelier-xdg-shell.h" // NOLINT(build/include_directory) #include "sommelier-xshape.h" // NOLINT(build/include_directory) #ifdef GAMEPAD_SUPPORT #include "libevdev/libevdev-shim.h" @@ -597,17 +598,19 @@ void sl_registry_handler(void* data, assert(xdg_shell); xdg_shell->ctx = ctx; xdg_shell->id = id; + xdg_shell->version = MIN(SL_XDG_SHELL_MAX_VERSION, version); xdg_shell->internal = nullptr; xdg_shell->host_global = nullptr; assert(!ctx->xdg_shell); ctx->xdg_shell = xdg_shell; if (ctx->xwayland) { xdg_shell->internal = static_cast(wl_registry_bind( - registry, id, &xdg_wm_base_interface, XDG_SHELL_VERSION)); + registry, id, &xdg_wm_base_interface, xdg_shell->version)); xdg_wm_base_add_listener(xdg_shell->internal, &sl_internal_xdg_shell_listener, nullptr); } else { - xdg_shell->host_global = sl_xdg_shell_global_create(ctx); + xdg_shell->host_global = + sl_xdg_shell_global_create(ctx, xdg_shell->version); } } else if (strcmp(interface, "zaura_shell") == 0) { if (version >= MIN_AURA_SHELL_VERSION) { diff --git a/sommelier.h b/sommelier.h index 9297086..d6cdb3f 100644 --- a/sommelier.h +++ b/sommelier.h @@ -22,7 +22,6 @@ #include "weak-resource-ptr.h" // NOLINT(build/include_directory) #define SOMMELIER_VERSION "0.20" -#define XDG_SHELL_VERSION 3u #define APPLICATION_ID_FORMAT_PREFIX "org.chromium.guest_os.%s" #define NATIVE_WAYLAND_APPLICATION_ID_FORMAT \ APPLICATION_ID_FORMAT_PREFIX ".wayland.%s" @@ -401,6 +400,7 @@ struct sl_viewporter { struct sl_xdg_shell { struct sl_context* ctx; uint32_t id; + uint32_t version; struct sl_global* host_global; struct xdg_wm_base* internal; }; @@ -565,7 +565,8 @@ struct sl_global* sl_data_device_manager_global_create(struct sl_context* ctx); struct sl_global* sl_viewporter_global_create(struct sl_context* ctx); -struct sl_global* sl_xdg_shell_global_create(struct sl_context* ctx); +struct sl_global* sl_xdg_shell_global_create(struct sl_context* ctx, + uint32_t version); struct sl_global* sl_gtk_shell_global_create(struct sl_context* ctx);