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:
parent
f87f9848c3
commit
eb0339e223
@ -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')
|
||||
|
@ -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,
|
||||
)
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user