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: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1495>
This commit is contained in:
Florian Müllner 2020-04-15 20:27:15 +02:00 committed by Marge Bot
parent f87f9848c3
commit eb0339e223
3 changed files with 29 additions and 25 deletions

View File

@ -23,5 +23,6 @@ girdir = join_paths(pkgdatadir, 'gir-1.0')
typelibdir = join_paths(pkglibdir, 'girepository-1.0') typelibdir = join_paths(pkglibdir, 'girepository-1.0')
gtk_dep = dependency('gtk+-3.0') gtk_dep = dependency('gtk+-3.0')
x11_dep = dependency('x11', required: false)
subdir('src') subdir('src')

View File

@ -12,7 +12,7 @@ shew_sources = [
libshew = library(full_name, libshew = library(full_name,
sources: shew_sources, sources: shew_sources,
dependencies: [gtk_dep], dependencies: [gtk_dep, x11_dep],
install_dir: pkglibdir, install_dir: pkglibdir,
install: true, install: true,
) )

View File

@ -22,6 +22,7 @@
#include <gdk/gdk.h> #include <gdk/gdk.h>
#ifdef GDK_WINDOWING_X11 #ifdef GDK_WINDOWING_X11
#include <gdk/gdkx.h> #include <gdk/gdkx.h>
#include <X11/Xlib.h>
#endif #endif
#include <stdlib.h> #include <stdlib.h>
@ -33,7 +34,7 @@ struct _ShewExternalWindowX11
{ {
ShewExternalWindow parent; ShewExternalWindow parent;
GdkWindow *foreign_gdk_window; int foreign_xid;
}; };
G_DEFINE_TYPE (ShewExternalWindowX11, shew_external_window_x11, G_DEFINE_TYPE (ShewExternalWindowX11, shew_external_window_x11,
@ -54,13 +55,29 @@ get_x11_display (void)
return x11_display; 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 * ShewExternalWindowX11 *
shew_external_window_x11_new (const char *handle_str) shew_external_window_x11_new (const char *handle_str)
{ {
ShewExternalWindowX11 *external_window_x11; ShewExternalWindowX11 *external_window_x11;
GdkDisplay *display; GdkDisplay *display;
int xid; int xid;
GdkWindow *foreign_gdk_window = NULL;
display = get_x11_display (); display = get_x11_display ();
if (!display) if (!display)
@ -77,20 +94,16 @@ shew_external_window_x11_new (const char *handle_str)
return NULL; return NULL;
} }
#ifdef GDK_WINDOWING_X11 if (!check_foreign_xid (display, xid))
foreign_gdk_window = gdk_x11_window_foreign_new_for_display (display, xid);
#endif
if (!foreign_gdk_window)
{ {
g_warning ("Failed to create foreign window for XID %d", xid); g_warning ("Failed to find foreign window for XID %d", xid);
return NULL; return NULL;
} }
external_window_x11 = g_object_new (SHEW_TYPE_EXTERNAL_WINDOW_X11, external_window_x11 = g_object_new (SHEW_TYPE_EXTERNAL_WINDOW_X11,
"display", display, "display", display,
NULL); NULL);
external_window_x11->foreign_gdk_window = foreign_gdk_window; external_window_x11->foreign_xid = xid;
return external_window_x11; return external_window_x11;
} }
@ -102,18 +115,11 @@ shew_external_window_x11_set_parent_of (ShewExternalWindow *external_window,
ShewExternalWindowX11 *external_window_x11 = ShewExternalWindowX11 *external_window_x11 =
SHEW_EXTERNAL_WINDOW_X11 (external_window); SHEW_EXTERNAL_WINDOW_X11 (external_window);
gdk_window_set_transient_for (child_window, #ifdef GDK_WINDOWING_X11
external_window_x11->foreign_gdk_window); XSetTransientForHint (GDK_WINDOW_XDISPLAY (child_window),
} GDK_WINDOW_XID (child_window),
external_window_x11->foreign_xid);
static void #endif
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);
} }
static void static void
@ -124,10 +130,7 @@ shew_external_window_x11_init (ShewExternalWindowX11 *external_window_x11)
static void static void
shew_external_window_x11_class_init (ShewExternalWindowX11Class *klass) shew_external_window_x11_class_init (ShewExternalWindowX11Class *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass);
ShewExternalWindowClass *external_window_class = SHEW_EXTERNAL_WINDOW_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; external_window_class->set_parent_of = shew_external_window_x11_set_parent_of;
} }