GTK4 child windows/dialogs positioned incorrectly in multiple X11 WMs (KDE Plasma and Xfce)
KWin bug also filed at https://bugs.kde.org/show_bug.cgi?id=439137. I did not file a Xfce bug since I don't use Xfce (and only installed it to test this bug), but it may be worthwhile to let them know about this issue, investigate it if they want, and possibly fix on their end.
Steps to reproduce
- Launch KDE Plasma X11 or Xfce X11. I haven't tested other DEs yet, but I'm open to suggestions.
- Run gtk4-demo. Scroll down to "Dialogs" and press "Run" in the title bar.
- Push "Message Dialog" or "Interactive Dialog".
Current behavior
On KDE Plasma X11, with gtk4-demo, the "Dialogs" window has a 45%-ish chance of appearing at the top-left corner of the screen, a 45%-ish chance of appearing where there's empty room on the desktop, and a 10%-ish chance of appearing on top of the parent window. The "Message Dialog" (with title bar) and "Interactive Dialog" it creates have a 50%-ish chance of appearing at the top left corner of the screen, instead of on the window. If you killall kwin_x11
before opening the windows/dialogs, they will always appear in the top-left of the screen.
If you follow the same steps with gtk3-demo, the "Dialogs and Message Boxes" window always appears where there is room on-screen (otherwise on the top-left corner), and the Message/Interactive Dialogs always appear on top of their parent windows. With kwin_x11 killed, all windows and dialogs appear in the top-left corner of the screen.
On XFCE, with gtk4-demo, the "Dialogs" window, as well as "Message/Interactive Dialog" (Message Dialog has no title bar), always appear in the center of the screen. With xfwm4 killed (and stopped from respawning), they instead appear in the top-left corner of the screen.
If you follow the same steps with gtk3-demo, the "Dialogs and Message Boxes" window, and the dialogs it spawns, appears on top of their parents. With xfwm4 killed, they instead appear in the top-left corner of the screen.
Expected outcome
I expect GTK4 windows to not be positioned nondeterministically on KWin (which could be a KWin bug, or something more complex), and not be placed in the top-left corner of the screen. Ideally GTK4 windows would behave like GTK3 windows on all DEs.
Does GTK4 think it's the responsibility of the GUI toolkit or WM to position windows? I'm guessing both GTK3 and GTK4 do not communicate window positions to X, but instead supplies instructions to the WM, and GTK4 does so differently, and they're either wrong or misinterpreted by non-GNOME WMs. (I've heard on the gtk-rs Matrix that GTK4 doesn't compute window positions itself, and I observed that gtk3-demos's "Dialogs and Message Boxes" window is placed on the parent in XFCE, but in empty space on KDE.) And there are even bigger behavioral differences on GTK4.
I didn't take the time to test gtk3/4-demo's behavior on GNOME or any DE's Wayland, but I did test gtk3/4-widget-factory's behavior. See "Additional Information". Window positioning is much more consistent on Wayland. I suspect that's because the WM, not the toolkit, manages window positioning, so GTK4 has no room to screw positions up. But I don't know why GTK on X11 has inconsistent windowing behavior, since I think it delegates positioning to the WM like Wayland does. (I think so because it spawns windows at (0, 0) without a WM running.)
Version information
- GTK: 4.2.1
- OS: Arch Linux
- WM: kwin 5.22.2, Xfce 4.16
Additional information
Alternative instructions:
- Start a Linux desktop session using Plasma (X11) or Xfce (X11).
- Launch gtk4-widget-factory. Optionally move the window to various positions.
- Click on Page 2.
In the bottom-right, there are buttons saying Inform (opens a dialog), Act and Configure (which open a popup with a headerbar), and Select (I didn't test it since it's slow to load and has side effects).
- Click one of these buttons.
I assembled a spreadsheet of my experiment results with gtk4-widget-factory.
Theory: the "window reopens where it was closed" behavior arises because (theory:) gtk4-widget-factory keeps the dialogs around when closed, instead of destroying it and recreating it when you reopen the dialog. On the other hand, (theory:) gtk4-demo destroys and recreates the dialogs on every run, so they always spawn on top of the parent. Is keeping a closed dialog's state around a misuse of GTK3/4? Should GTK3/4 be changed to not remember dialog positions/state?