Skip to content

[GTK] Do not pass a negative size to gtk_widget_size_allocate - #3590

Merged
akurtakov merged 1 commit into
eclipse-platform:masterfrom
vogella:gtk-shell-size-clamp
Sep 16, 2026
Merged

akurtakov merged 1 commit into
eclipse-platform:masterfrom
vogella:gtk-shell-size-clamp

Conversation

@vogella

@vogella vogella commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

A Shell with a container border (SWT.TOOL | SWT.ON_TOP, as used by the JFace information controls) that is asked for a height of 0 ends up with a client box of -1, because setBounds clamps the height to 1 and resizeBounds then subtracts the 2 pixel border. GTK rejects the negative allocation with a Gtk-CRITICAL, so the shell keeps its natural size while its content is never laid out, which shows up as a correctly sized but empty popup.

The box size is now clamped to zero, so a degenerate request stays degenerate instead of corrupting the layout. The added test fails without the clamp on both X11 and Wayland. Split out of #3541, which contains the actual coordinate fix for #3539.

Contributes to #3539

🤖 Generated with Claude Code

https://claude.ai/code/session_01M2iVTmY8ykUUVtSEJHNJtV

A Shell with a container border (SWT.TOOL | SWT.ON_TOP, as used by the JFace
information controls) that is asked for a height of 0 ends up with a client
box of -1: setBounds clamps the height to 1 and resizeBounds then subtracts
the 2 pixel border.

GTK rejects the negative allocation, so the shell keeps its natural size
while its content box is never laid out. That shows up as a correctly sized
but completely empty popup, together with

  Gtk-CRITICAL: gtk_widget_get_preferred_width_for_height: assertion 'height >= 0' failed
  Gtk-WARNING : gtk_widget_size_allocate(): attempt to allocate widget with width 226 and height -1

Clamp the box size to zero so a degenerate request stays degenerate instead
of corrupting the layout.

Contributes to eclipse-platform#3539
@github-actions

Copy link
Copy Markdown
Contributor

Test Results

  212 files  ±0    212 suites  ±0   28m 59s ⏱️ + 1m 34s
4 954 tests +1  4 928 ✅ +1   26 💤 ±0  0 ❌ ±0 
7 157 runs  +6  6 972 ✅ +1  185 💤 +5  0 ❌ ±0 

Results for commit d984622. ± Comparison against base commit af630a9.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused fix correctly addresses the invalid allocation and includes targeted regression coverage.

Pull request overview

Clamps GTK shell content dimensions to prevent invalid negative allocations for zero-height bordered popups.

Changes:

  • Clamp calculated content dimensions to zero.
  • Add a GTK3 regression test for degenerate popup sizing.
File summaries
File Description
Shell.java Prevents negative GTK widget allocations.
Test_org_eclipse_swt_widgets_Shell.java Verifies zero-height popups remain degenerate.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@akurtakov

Copy link
Copy Markdown
Member

This is clear move in the right direction so I'm merging it. The whole border story is quite problematic and needs bigger overhaul as on Gtk4 max(gtk_widget_get_margin_top|bottom|start|end) is used as border and luckily for us themes are not going wild and using different margins for each side to totally screw SWT.

@akurtakov
akurtakov merged commit 8fc64e7 into eclipse-platform:master Sep 16, 2026
23 checks passed
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