[gnome-shell/wip/fmuellner/gtk4: 59/75] shew: Use Xlib to set transient hint




commit 4335a799a20df2ae426b8bf2c3e41007992fd1a1
Author: Florian Müllner <fmuellner gnome org>
Date:   Wed Apr 15 20:27:15 2020 +0200

    shew: Use Xlib to set transient hint
    
    The GDK API for setting the hint has been removed in GDK4, so prepare
    for a port by using the underlying Xlib API directly.

 subprojects/shew/meson.build                    |  1 +
 subprojects/shew/src/meson.build                |  2 +-
 subprojects/shew/src/shew-external-window-x11.c | 51 +++++++++++++------------
 3 files changed, 29 insertions(+), 25 deletions(-)
---
diff --git a/subprojects/shew/meson.build b/subprojects/shew/meson.build
index 3accbe67af..c19653421f 100644
--- a/subprojects/shew/meson.build
+++ b/subprojects/shew/meson.build
@@ -23,5 +23,6 @@ girdir = join_paths(pkgdatadir, 'gir-1.0')
 typelibdir = join_paths(pkglibdir, 'girepository-1.0')
 
 gtk_dep = dependency('gtk+-3.0')
+x11_dep = dependency('x11', required: false)
 
 subdir('src')
diff --git a/subprojects/shew/src/meson.build b/subprojects/shew/src/meson.build
index c3b1a6b796..f3bff58271 100644
--- a/subprojects/shew/src/meson.build
+++ b/subprojects/shew/src/meson.build
@@ -12,7 +12,7 @@ shew_sources = [
 
 libshew = library(full_name,
   sources: shew_sources,
-  dependencies: [gtk_dep],
+  dependencies: [gtk_dep, x11_dep],
   install_dir: pkglibdir,
   install: true,
 )
diff --git a/subprojects/shew/src/shew-external-window-x11.c b/subprojects/shew/src/shew-external-window-x11.c
index 5c4c8e69e8..0504a30f7a 100644
--- a/subprojects/shew/src/shew-external-window-x11.c
+++ b/subprojects/shew/src/shew-external-window-x11.c
@@ -22,6 +22,7 @@
 #include <gdk/gdk.h>
 #ifdef GDK_WINDOWING_X11
 #include <gdk/gdkx.h>
+#include <X11/Xlib.h>
 #endif
 #include <stdlib.h>
 
@@ -33,7 +34,7 @@ struct _ShewExternalWindowX11
 {
   ShewExternalWindow parent;
 
-  GdkWindow *foreign_gdk_window;
+  int foreign_xid;
 };
 
 G_DEFINE_TYPE (ShewExternalWindowX11, shew_external_window_x11,
@@ -54,13 +55,29 @@ get_x11_display (void)
   return x11_display;
 }
 
+static gboolean
+check_foreign_xid (GdkDisplay *display,
+                   int         xid)
+{
+  gboolean result = FALSE;
+#ifdef GDK_WINDOWING_X11
+  XWindowAttributes attrs;
+
+  gdk_x11_display_error_trap_push (display);
+  result = XGetWindowAttributes (GDK_DISPLAY_XDISPLAY (display), xid, &attrs);
+  if (gdk_x11_display_error_trap_pop (display))
+    return FALSE;
+
+#endif
+  return result;
+}
+
 ShewExternalWindowX11 *
 shew_external_window_x11_new (const char *handle_str)
 {
   ShewExternalWindowX11 *external_window_x11;
   GdkDisplay *display;
   int xid;
-  GdkWindow *foreign_gdk_window = NULL;
 
   display = get_x11_display ();
   if (!display)
@@ -77,20 +94,16 @@ shew_external_window_x11_new (const char *handle_str)
       return NULL;
     }
 
-#ifdef GDK_WINDOWING_X11
-  foreign_gdk_window = gdk_x11_window_foreign_new_for_display (display, xid);
-#endif
-
-  if (!foreign_gdk_window)
+  if (!check_foreign_xid (display, xid))
     {
-      g_warning ("Failed to create foreign window for XID %d", xid);
+      g_warning ("Failed to find foreign window for XID %d", xid);
       return NULL;
     }
 
   external_window_x11 = g_object_new (SHEW_TYPE_EXTERNAL_WINDOW_X11,
                                       "display", display,
                                       NULL);
-  external_window_x11->foreign_gdk_window = foreign_gdk_window;
+  external_window_x11->foreign_xid = xid;
 
   return external_window_x11;
 }
@@ -102,18 +115,11 @@ shew_external_window_x11_set_parent_of (ShewExternalWindow *external_window,
   ShewExternalWindowX11 *external_window_x11 =
     SHEW_EXTERNAL_WINDOW_X11 (external_window);
 
-  gdk_window_set_transient_for (child_window,
-                                external_window_x11->foreign_gdk_window);
-}
-
-static void
-shew_external_window_x11_dispose (GObject *object)
-{
-  ShewExternalWindowX11 *external_window_x11 = SHEW_EXTERNAL_WINDOW_X11 (object);
-
-  g_clear_object (&external_window_x11->foreign_gdk_window);
-
-  G_OBJECT_CLASS (shew_external_window_x11_parent_class)->dispose (object);
+#ifdef GDK_WINDOWING_X11
+  XSetTransientForHint (GDK_WINDOW_XDISPLAY (child_window),
+                        GDK_WINDOW_XID (child_window),
+                        external_window_x11->foreign_xid);
+#endif
 }
 
 static void
@@ -124,10 +130,7 @@ shew_external_window_x11_init (ShewExternalWindowX11 *external_window_x11)
 static void
 shew_external_window_x11_class_init (ShewExternalWindowX11Class *klass)
 {
-  GObjectClass *object_class = G_OBJECT_CLASS (klass);
   ShewExternalWindowClass *external_window_class = SHEW_EXTERNAL_WINDOW_CLASS (klass);
 
-  object_class->dispose = shew_external_window_x11_dispose;
-
   external_window_class->set_parent_of = shew_external_window_x11_set_parent_of;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]