From eb0339e223d69289171c0f53eb6de4f290ce4551 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Wed, 15 Apr 2020 20:27:15 +0200 Subject: [PATCH] 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. Part-of: --- subprojects/shew/meson.build | 1 + subprojects/shew/src/meson.build | 2 +- .../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 3accbe67a..c19653421 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 c3b1a6b79..f3bff5827 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 5c4c8e69e..0504a30f7 100644 --- a/subprojects/shew/src/shew-external-window-x11.c +++ b/subprojects/shew/src/shew-external-window-x11.c @@ -22,6 +22,7 @@ #include #ifdef GDK_WINDOWING_X11 #include +#include #endif #include @@ -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; }