Skip to content

[Gtk4] Support MenuItem images on GTK4 - #3441

Merged
akurtakov merged 1 commit into
eclipse-platform:masterfrom
akurtakov:gtk4-menu-icons
Sep 18, 2026
Merged

akurtakov merged 1 commit into
eclipse-platform:masterfrom
akurtakov:gtk4-menu-icons

Conversation

@akurtakov

@akurtakov akurtakov commented Jul 15, 2026

Copy link
Copy Markdown
Member

GtkModelButton (GTK4's native menu row) never shows both an icon and
text, so menu items with images rendered without their icon. Work
around this by embedding a custom icon+label(+accelerator) GtkButton
into the popover via gtk_popover_menu_add_child() for PUSH and CHECK
items. The custom row uses the "modelbutton" node name so the menu row
rules apply to it, and announces itself as a menu item like
GtkModelButton does. Its leading box and the native rows'
indicator boxes share one GtkSizeGroup, so icons and the check marks
of native CHECK rows sit in one column and all labels line up. CHECK
rows carry a GtkCheckButton bound to the item's action in front of the
icon, and while a menu has such a row the other custom rows keep that
check column in front of their icons, so the icons line up too;
CASCADE and RADIO items keep the native GtkModelButton.

The custom rows take part in the popover's row selection sync through
the "selected" state the theme paints, and hovering one closes a
sibling's open submenu after a short delay, as GtkModelButton does.

Injection is self-healing: GTK's "custom" ids are single-use, so a
detached or rebuilt row is re-injected under a fresh id.

Contributes to #2511

@akurtakov
akurtakov marked this pull request as draft July 15, 2026 16:36
@github-actions

github-actions Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Test Results

  212 files  ±0    212 suites  ±0   25m 11s ⏱️ - 3m 22s
4 959 tests ±0  4 932 ✅ ±0   27 💤 ±0  0 ❌ ±0 
7 187 runs  ±0  6 996 ✅ ±0  191 💤 ±0  0 ❌ ±0 

Results for commit befbf90. ± Comparison against base commit c93196d.

♻️ This comment has been updated with latest results.

@akurtakov
akurtakov force-pushed the gtk4-menu-icons branch 7 times, most recently from 924149f to 9f101f4 Compare August 4, 2026 07:21
@akurtakov
akurtakov force-pushed the gtk4-menu-icons branch 2 times, most recently from 8b1bbe3 to fead2fd Compare September 11, 2026 11:17
@akurtakov
akurtakov marked this pull request as ready for review September 17, 2026 18:04
@akurtakov
akurtakov requested a balanced review from Copilot September 17, 2026 18:09

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.

🟡 Changes recommended

HiDPI sizing, accessibility semantics, theme overriding, and integration coverage need correction.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds GTK4 menu-item images using custom popover rows while preserving alignment, selection, actions, and submenu behavior.

Changes:

  • Adds custom image-capable PUSH and CHECK menu rows.
  • Adds GTK4/JNI APIs for custom popover children and sizing.
  • Re-enables the GTK4 image test.
File summaries
File Description
Test_org_eclipse_swt_widgets_MenuItem.java Re-enables image API testing.
MenuItem.java Implements custom image menu rows.
Menu.java Injects, aligns, and synchronizes custom rows.
Display.java Adds custom-row highlight styling.
GTK4.java Declares required GTK4 APIs.
OS.java Declares supporting GLib APIs.
GTK.java Declares widget construction and CSS APIs.
os.c Adds generated JNI implementations.
os_stats.h Updates generated OS JNI statistics.
gtk4.c Adds generated GTK4 JNI implementations.
gtk4_stats.h Updates generated GTK4 JNI statistics.
Review details
  • Files reviewed: 11/11 changed files
  • Comments generated: 4
  • Review effort level: Balanced

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

Comment thread bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java Outdated
Comment thread bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java Outdated

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.

🟡 Changes recommended

Custom-row highlighting, CHECK accessibility state, and teardown state handling remain incomplete.

Get a fresh assessment by requesting another Copilot review.

Review details
  • Files reviewed: 11/11 changed files
  • Comments generated: 3
  • Review effort level: Balanced

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.

🟡 Changes recommended

Image-bearing CHECK items regress native Space-key behavior by closing the menu.

Get a fresh assessment by requesting another Copilot review.

Review details
  • Files reviewed: 11/11 changed files
  • Comments generated: 2
  • Review effort level: Balanced

Comment thread bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java Outdated
GtkModelButton (GTK4's native menu row) never shows both an icon and
text, so menu items with images rendered without their icon. Work
around this by embedding a custom icon+label(+accelerator) GtkButton
into the popover via gtk_popover_menu_add_child() for PUSH and CHECK
items. The custom row uses the "modelbutton" node name so the menu row
rules apply to it, and announces itself as a menu item like
GtkModelButton does. Its leading box and the native rows'
indicator boxes share one GtkSizeGroup, so icons and the check marks
of native CHECK rows sit in one column and all labels line up. CHECK
rows carry a GtkCheckButton bound to the item's action in front of the
icon, and while a menu has such a row the other custom rows keep that
check column in front of their icons, so the icons line up too;
CASCADE and RADIO items keep the native GtkModelButton.

The custom rows take part in the popover's row selection sync through
the "selected" state the theme paints, and hovering one closes a
sibling's open submenu after a short delay, as GtkModelButton does.

Injection is self-healing: GTK's "custom" ids are single-use, so a
detached or rebuilt row is re-injected under a fresh id.

Contributes to eclipse-platform#2511

Assisted-by: Anthropic Claude Code (claude-sonnet-5)
Assisted-by: Anthropic Claude Code (claude-fable-5-1)

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.

🟡 Changes recommended

The complex native row lifecycle lacks regression coverage beyond basic image property storage.

Get a fresh assessment by requesting another Copilot review.

Review details
  • Files reviewed: 12/12 changed files
  • Comments generated: 1
  • Review effort level: Balanced

@akurtakov

Copy link
Copy Markdown
Member Author

Good enough state for initial support. Whatever problems are found from now on should be handled in separate issues/PRs

@akurtakov
akurtakov merged commit c009df6 into eclipse-platform:master Sep 18, 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

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants