Gtk (on X11) creates top-level windows with BackgroundPixmap = ParentRelative
Steps to reproduce
- Run any Gtk application on awesomeWM or i3
- The window is mis-managed and is visible as a top-level window at 0x0 without window decorations
References
- https://forum.manjaro.org/t/strange-always-on-top-window-placement-for-some-clients-in-awesomewm/48506/10
- https://github.com/awesomeWM/awesome/issues/2279
- https://github.com/i3/i3/issues/3297
Some details
Since https://github.com/GNOME/gtk/commit/2ce63a86ba689aa41eb47409c889c469497478b0, Gtk tries to get rid of the BackgroundPixel = black
that it sets on its own windows. However gdk_window_x11_set_background
with second argument NULL
actually sets the background to ParentRelative
instead of None
, which means that the same background as the parent window is used. Thus, the patch only works if the WM creates its window with background set to None
. If instead it uses e.g. black, then the patch does not help.
This patch is no problem for reparenting window managers that use a window of the same depth as Gtk, but other WMs (that e.g. want to offer transparency in their titlebars) get an error on their ReparentWindow
request, because ParentRelative
backgrounds only work when the parent has the same depth. i3 seems to semi-gracefully handle this and just does not manage the window. The code in AwesomeWM totally does not expect ReparentWindow
to fail and the behaviour under "steps to reproduce" is seen.
Suggested fix
Just do not set BackgroundPixel = black
and then try to undo it. You are doing it wrong anyway (BlackPixel
is only valid for the root window's visual, but I guess in practice this does not matter).
Completely untested patch that you are free to commit with a commit message of your choice and which I release under the LGPL 2.1 (which seems to be Gtk's license):
--- gdkwindow-x11-orig.c 2018-06-03 11:11:25.935598120 +0200
+++ gdkwindow-x11.c 2018-06-03 11:11:49.751191376 +0200
@@ -1066,10 +1066,8 @@ _gdk_x11_display_create_window_impl (Gdk
{
class = InputOutput;
- xattributes.background_pixel = BlackPixel (xdisplay, x11_screen->screen_num);
-
xattributes.border_pixel = BlackPixel (xdisplay, x11_screen->screen_num);
- xattributes_mask |= CWBorderPixel | CWBackPixel;
+ xattributes_mask |= CWBorderPixel;
xattributes.bit_gravity = NorthWestGravity;
xattributes_mask |= CWBitGravity;
@@ -1147,9 +1145,6 @@ _gdk_x11_display_create_window_impl (Gdk
if (attributes_mask & GDK_WA_TYPE_HINT)
gdk_window_set_type_hint (window, attributes->type_hint);
- if (!window->input_only)
- gdk_window_x11_set_background (window, NULL);
-
gdk_x11_event_source_select_events ((GdkEventSource *) display_x11->event_source,
GDK_WINDOW_XID (window), event_mask,
StructureNotifyMask | PropertyChangeMask);
Version information
I have no idea. I did not experience myself and I am just the person reacting to the bug report on AwesomeWM. According to https://github.com/awesomeWM/awesome/issues/2279#issuecomment-394077787, this occurs with gtk3 from the gtk-3-22 branch.