wayland: Also support the v2 of the importer
authorMatthias Clasen <mclasen@redhat.com>
Fri, 18 Nov 2022 17:09:27 +0000 (12:09 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 18 Nov 2022 17:10:56 +0000 (12:10 -0500)
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
gdk/wayland/gdkdisplay-wayland.h
gdk/wayland/gdksurface-wayland.c

index 7013b2676ed379d5459f276ecf74a2be9675c815..a848a45b6db5c4486b35ea60481b21f9809920b7 100644 (file)
@@ -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 =
index b23c30a2080590d3c88a524eb99a7294a0f79372..40f101f9fffe91abb1dd3262e20905ed1efb36ed 100644 (file)
@@ -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;
index fb2842b44765e966716ff261dd61937926e1f307..0b0cbea3884fe18458daf9cc4cb589b1389eb19b 100644 (file)
@@ -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);