From f6a67aeb202c1338a27f5fd92bb9ce79511a2764 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 19 Mar 2024 17:28:25 -0400 Subject: [PATCH 1/3] wayland: Check some required globals This may be largely cosmetics, since these are core protocols that are unlikely to ever be missing. But lets check anyway. --- gdk/wayland/gdkdisplay-wayland.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/gdk/wayland/gdkdisplay-wayland.c b/gdk/wayland/gdkdisplay-wayland.c index a65dbca530..cde54170ac 100644 --- a/gdk/wayland/gdkdisplay-wayland.c +++ b/gdk/wayland/gdkdisplay-wayland.c @@ -95,7 +95,6 @@ #define GTK_SHELL1_VERSION 5 #define OUTPUT_VERSION_WITH_DONE 2 #define NO_XDG_OUTPUT_DONE_SINCE_VERSION 3 -#define XDG_ACTIVATION_VERSION 1 #define OUTPUT_VERSION 3 #ifdef HAVE_TOPLEVEL_STATE_SUSPENDED @@ -585,22 +584,19 @@ gdk_registry_handle_global (void *data, { display_wayland->xdg_activation = wl_registry_bind (display_wayland->wl_registry, id, - &xdg_activation_v1_interface, - MIN (version, XDG_ACTIVATION_VERSION)); + &xdg_activation_v1_interface, 1); } else if (strcmp (interface, "wp_fractional_scale_manager_v1") == 0) { display_wayland->fractional_scale = wl_registry_bind (display_wayland->wl_registry, id, - &wp_fractional_scale_manager_v1_interface, - MIN (version, 1)); + &wp_fractional_scale_manager_v1_interface, 1); } else if (strcmp (interface, "wp_viewporter") == 0) { display_wayland->viewporter = wl_registry_bind (display_wayland->wl_registry, id, - &wp_viewporter_interface, - MIN (version, 1)); + &wp_viewporter_interface, 1); } @@ -700,7 +696,8 @@ _gdk_wayland_display_open (const char *display_name) process_on_globals_closures (display_wayland); /* Wait for initializing to complete. This means waiting for all - * asynchronous roundtrips that were triggered during initial roundtrip. */ + * asynchronous roundtrips that were triggered during initial roundtrip. + */ while (display_wayland->async_roundtrips != NULL) { if (wl_display_dispatch (display_wayland->wl_display) < 0) @@ -710,6 +707,18 @@ _gdk_wayland_display_open (const char *display_name) } } + /* Check that we got all the required globals */ + if (display_wayland->compositor == NULL || + display_wayland->shm == NULL || + display_wayland->data_device_manager == NULL) + { + g_warning ("The Wayland compositor does not provide one or more of the required interfaces, " + "not using Wayland display"); + g_object_unref (display); + + return NULL; + } + if (display_wayland->xdg_wm_base_id) { display_wayland->shell_variant = GDK_WAYLAND_SHELL_VARIANT_XDG_SHELL; From 5d52c43074c1b31e817e5dba06f25e3908ee15af Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 19 Mar 2024 17:29:10 -0400 Subject: [PATCH 2/3] wayland: Check all required globals for subsurfaces Before trying to use subsurfaces, make sure we have both a subcompositor and a viewporter. --- gdk/wayland/gdksubsurface-wayland.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gdk/wayland/gdksubsurface-wayland.c b/gdk/wayland/gdksubsurface-wayland.c index a0c8ca9db5..588974812d 100644 --- a/gdk/wayland/gdksubsurface-wayland.c +++ b/gdk/wayland/gdksubsurface-wayland.c @@ -466,9 +466,9 @@ gdk_wayland_surface_create_subsurface (GdkSurface *surface) GdkWaylandSubsurface *sub; struct wl_region *region; - if (disp->viewporter == NULL) + if (disp->subcompositor == NULL || disp->viewporter == NULL) { - GDK_DISPLAY_DEBUG (display, OFFLOAD, "Can't use subsurfaces without viewporter"); + GDK_DISPLAY_DEBUG (display, OFFLOAD, "Can't use subsurfaces without subcompositor and viewporter"); return NULL; } From 191f826075a15bff8d5f5816de7ff5966ca0f791 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 19 Mar 2024 17:50:43 -0400 Subject: [PATCH 3/3] wayland: Only set buffer scale if we can We check this in some other places, so be consistent. --- gdk/wayland/gdkdevice-wayland.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gdk/wayland/gdkdevice-wayland.c b/gdk/wayland/gdkdevice-wayland.c index 9cb3cfbfda..2df94d1516 100644 --- a/gdk/wayland/gdkdevice-wayland.c +++ b/gdk/wayland/gdkdevice-wayland.c @@ -310,7 +310,8 @@ gdk_wayland_device_update_surface_cursor (GdkDevice *device) if (buffer) { wl_surface_attach (pointer->pointer_surface, buffer, 0, 0); - wl_surface_set_buffer_scale (pointer->pointer_surface, scale); + if (wl_surface_get_version (pointer->pointer_surface) >= WL_SURFACE_SET_BUFFER_SCALE_SINCE_VERSION) + wl_surface_set_buffer_scale (pointer->pointer_surface, scale); wl_surface_damage (pointer->pointer_surface, 0, 0, w, h); wl_surface_commit (pointer->pointer_surface); }