Skip to content

[GTK3] Measure the actual window size when learning the shell trim - #3878

Open
HeikoKlare wants to merge 1 commit into
eclipse-platform:masterfrom
HeikoKlare:gtk3-shell-trim-stale-allocation
Open

HeikoKlare wants to merge 1 commit into
eclipse-platform:masterfrom
HeikoKlare:gtk3-shell-trim-stale-allocation

Conversation

@HeikoKlare

Copy link
Copy Markdown
Contributor

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

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]>
@github-actions

Copy link
Copy Markdown
Contributor

Test Results

 1 102 files  ±0   1 102 suites  ±0   1h 39m 24s ⏱️ -12s
 5 232 tests +1   5 204 ✅ +1     28 💤 ±0  0 ❌ ±0 
30 940 runs  +6  27 708 ✅ +6  3 232 💤 ±0  0 ❌ ±0 

Results for commit 3b0aff4. ± Comparison against base commit 16080ee.

@HeikoKlare
HeikoKlare marked this pull request as ready for review November 20, 2026 07:24
@HeikoKlare

Copy link
Copy Markdown
Contributor Author

@akurtakov this was a side findings when working on test hardening. Maybe you as GTK expert can have a look?

@akurtakov

akurtakov commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

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.

@iloveeclipse

Copy link
Copy Markdown
Member

I'd rather remove the trim machinery than keep patching i

#1168

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants