Repository navigation
[GTK3] Measure the actual window size when learning the shell trim - #3878
HeikoKlare wants to merge 1 commit into
Conversation
When a shell opens, adjustTrim derives the trim from the difference between the frame extents and the allocation of the window, and stores it on the display for all later shells. The allocation can still be the one from before the window was resized, so the shell measures a trim that does not exist and every later shell reports a size that is off by it. For example, a shell opened with 300x200 reports a width of 400. Use the current size of the window instead. This was hidden in the test suite as long as an earlier test had opened a shell with a trim above the maximum, which disables learning the trim for the rest of the lifetime of the display. The new test therefore opens its shells on a new display. Assisted-by: Claude Opus 5.5 <[email protected]>
|
@akurtakov this was a side findings when working on test hardening. Maybe you as GTK expert can have a look? |
|
Thanks for looking into this. The stale allocation is a real problem; Lars's first version of #3832 made almost the same change. On X11 this PR works, but on Wayland it causes a regression (weston and headless mutter, like CI). gtk_window_get_size() subtracts GTK's client-side decorations, but gdk_window_get_frame_extents() includes them. The display then learns a trim of about 52×97 that doesn't exist, and resizable shells get a client area that much too small: a 400×300 shell gets 348×203. Master learns 0×0 there. Lars's version doesn't have this problem, because both sizes include the decorations. On X11 it gives the same result as this PR: if (rect.width > 1 || rect.height > 1) {
widthHint = rect.width;
heightHint = rect.height;
width = GDK.gdk_window_get_width (window);
height = GDK.gdk_window_get_height (window);
}The test passes in CI mostly because of trims.prefs. Surefire sets user.home to target/, so a new display starts with the trims an earlier test stored there. That's also why CI didn't catch the Wayland problem: the test checks only getSize(), not the client area. With -Dorg.eclipse.swt.internal.gtk.ignoreTrimPrefs=true, the first 300×200 shell reports 294×171 even with the fix. Resizable shells are never resized back after the trim is learned. Suggestions: use gdk_window_get_width/height() as above, and run the test with prefs ignored and an extra getClientArea() check. I'd rather remove the trim machinery than keep patching it. Learning the trim from the first shell and storing it in ~/.swt/trims.prefs comes from the Motif days. Today a wrong value carries over to later shells, later displays and even later runs of every SWT application, which is exactly what makes these bugs so hard to track down. I plan to drop trims.prefs early in the next release cycle. The trim measurement would go too, or be replaced by reading _NET_FRAME_EXTENTS from the window manager on X11, which gives the frame size directly. |
|
Problem
When a shell opens on GTK3, SWT learns the size of the window frame (the trim) and stores it on the display for all later shells. It computes the trim from the frame extents and the allocation of the window. But the allocation can still be the one from before the window was resized. The display then stores a trim that doesn't exist, and every later shell reports a size that is off by it. For example, a shell opened with 300×200 reports a width of 400.
The test suite hasn't caught this so far. As soon as an earlier test opens a shell whose measured trim is implausibly large, SWT stops learning the trim for the rest of the display's lifetime. The size tests then pass only because some earlier test happened to switch trim learning off.
Solution
The trim is now computed from the current size of the window instead of its allocation. A new test opens shells on a new display, where the trim is still learned, and checks that they report the size they were opened with.
This prepares #3873, which uses a new display for every test class and therefore exposed the problem.
🤖 Generated with Claude Code