From b3821b19b52fc18a0e86f35d482769cbebe79705 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 18 Nov 2022 12:09:27 -0500 Subject: [PATCH] wayland: Also support the v2 of the importer Commit 0ba8e16e1417fdb added support for the export part of zxdg_foreign_v2, but neglected that the importer has a v2 as well. Support it. --- gdk/wayland/gdkdisplay-wayland.c | 6 ++++ gdk/wayland/gdkdisplay-wayland.h | 1 + gdk/wayland/gdksurface-wayland.c | 52 ++++++++++++++++++++++++-------- 3 files changed, 46 insertions(+), 13 deletions(-) diff --git a/gdk/wayland/gdkdisplay-wayland.c b/gdk/wayland/gdkdisplay-wayland.c index 7013b2676e..a848a45b6d 100644 --- a/gdk/wayland/gdkdisplay-wayland.c +++ b/gdk/wayland/gdkdisplay-wayland.c @@ -469,6 +469,12 @@ gdk_registry_handle_global (void *data, wl_registry_bind (display_wayland->wl_registry, id, &zxdg_importer_v1_interface, 1); } + else if (strcmp (interface, "zxdg_importer_v2") == 0) + { + display_wayland->xdg_importer_v2 = + wl_registry_bind (display_wayland->wl_registry, id, + &zxdg_importer_v2_interface, 1); + } else if (strcmp (interface, "zwp_keyboard_shortcuts_inhibit_manager_v1") == 0) { display_wayland->keyboard_shortcuts_inhibit = diff --git a/gdk/wayland/gdkdisplay-wayland.h b/gdk/wayland/gdkdisplay-wayland.h index b23c30a208..40f101f9ff 100644 --- a/gdk/wayland/gdkdisplay-wayland.h +++ b/gdk/wayland/gdkdisplay-wayland.h @@ -106,6 +106,7 @@ struct _GdkWaylandDisplay struct zxdg_exporter_v1 *xdg_exporter; struct zxdg_exporter_v2 *xdg_exporter_v2; struct zxdg_importer_v1 *xdg_importer; + struct zxdg_importer_v2 *xdg_importer_v2; struct zwp_keyboard_shortcuts_inhibit_manager_v1 *keyboard_shortcuts_inhibit; struct org_kde_kwin_server_decoration_manager *server_decoration_manager; struct zxdg_output_manager_v1 *xdg_output_manager; diff --git a/gdk/wayland/gdksurface-wayland.c b/gdk/wayland/gdksurface-wayland.c index fb2842b447..0b0cbea388 100644 --- a/gdk/wayland/gdksurface-wayland.c +++ b/gdk/wayland/gdksurface-wayland.c @@ -185,6 +185,7 @@ struct _GdkWaylandSurface int state_freeze_count; struct zxdg_imported_v1 *imported_transient_for; + struct zxdg_imported_v2 *imported_transient_for_v2; GHashTable *shortcuts_inhibitors; }; @@ -1159,14 +1160,18 @@ gdk_wayland_surface_sync_parent_of_imported (GdkWaylandSurface *impl) if (!impl->display_server.wl_surface) return; - if (!impl->imported_transient_for) + if (!impl->imported_transient_for && !impl->imported_transient_for_v2) return; if (!is_realized_toplevel (impl)) return; - zxdg_imported_v1_set_parent_of (impl->imported_transient_for, - impl->display_server.wl_surface); + if (impl->imported_transient_for) + zxdg_imported_v1_set_parent_of (impl->imported_transient_for, + impl->display_server.wl_surface); + else + zxdg_imported_v2_set_parent_of (impl->imported_transient_for_v2, + impl->display_server.wl_surface); } static void @@ -4680,21 +4685,31 @@ unset_transient_for_exported (GdkSurface *surface) GdkWaylandSurface *impl = GDK_WAYLAND_SURFACE (surface); g_clear_pointer (&impl->imported_transient_for, zxdg_imported_v1_destroy); + g_clear_pointer (&impl->imported_transient_for_v2, zxdg_imported_v2_destroy); } static void xdg_imported_destroyed (void *data, - struct zxdg_imported_v1 *zxdg_imported_v1) + struct zxdg_imported_v1 *imported) { - GdkSurface *surface = data; - - unset_transient_for_exported (surface); + unset_transient_for_exported (GDK_SURFACE (data)); } static const struct zxdg_imported_v1_listener xdg_imported_listener = { xdg_imported_destroyed, }; +static void +xdg_imported_v2_destroyed (void *data, + struct zxdg_imported_v2 *imported) +{ + unset_transient_for_exported (GDK_SURFACE (data)); +} + +static const struct zxdg_imported_v2_listener xdg_imported_listener_v2 = { + xdg_imported_v2_destroyed, +}; + /** * gdk_wayland_toplevel_set_transient_for_exported: * @toplevel: (type GdkWaylandToplevel): the `GdkToplevel` to make as transient @@ -4726,7 +4741,7 @@ gdk_wayland_toplevel_set_transient_for_exported (GdkToplevel *toplevel, impl = GDK_WAYLAND_SURFACE (toplevel); display_wayland = GDK_WAYLAND_DISPLAY (display); - if (!display_wayland->xdg_importer) + if (!display_wayland->xdg_importer && !display_wayland->xdg_importer_v2) { g_warning ("Server is missing xdg_foreign support"); return FALSE; @@ -4734,11 +4749,22 @@ gdk_wayland_toplevel_set_transient_for_exported (GdkToplevel *toplevel, gdk_wayland_toplevel_set_transient_for (GDK_WAYLAND_TOPLEVEL (impl), NULL); - impl->imported_transient_for = - zxdg_importer_v1_import (display_wayland->xdg_importer, parent_handle_str); - zxdg_imported_v1_add_listener (impl->imported_transient_for, - &xdg_imported_listener, - toplevel); + if (display_wayland->xdg_importer) + { + impl->imported_transient_for = + zxdg_importer_v1_import (display_wayland->xdg_importer, parent_handle_str); + zxdg_imported_v1_add_listener (impl->imported_transient_for, + &xdg_imported_listener, + toplevel); + } + else + { + impl->imported_transient_for_v2 = + zxdg_importer_v2_import_toplevel (display_wayland->xdg_importer_v2, parent_handle_str); + zxdg_imported_v2_add_listener (impl->imported_transient_for_v2, + &xdg_imported_listener_v2, + toplevel); + } gdk_wayland_surface_sync_parent_of_imported (impl); -- 2.30.2