Fix MenuListener not fired for menubar DROP_DOWN menus on GTK4#102
Draft
Fix MenuListener not fired for menubar DROP_DOWN menus on GTK4#102
Conversation
In GTK4, DROP_DOWN menus use a GMenuModel as their handle (not a GTK widget), so SHOW/HIDE signals cannot be connected to them directly. The fix: when the GtkPopoverMenuBar (BAR menu) maps, traverse its GtkPopoverMenuBarItem children in order, find each child's internal GtkPopoverMenu widget by type name, register it in the SWT widget table associated with the corresponding SWT DROP_DOWN menu, and connect SHOW/HIDE GTK signals to it. These route via the existing gtk_show()/gtk_hide() handlers to fire SWT.Show/SWT.Hide events. Cleanup: deregister() is overridden to remove the popover from the widget table when the DROP_DOWN menu is disposed. Co-authored-by: akurtakov <574788+akurtakov@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix MenuListener on GTK4 not being called
Fix MenuListener not fired for menubar DROP_DOWN menus on GTK4
Mar 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On GTK4,
MenuListener.menuShown/menuHiddenare never fired forSWT.DROP_DOWNmenus attached to a menubar — only popup menus (SWT.POP_UP) work.Root Cause
In GTK4,
SWT.DROP_DOWNmenus use aGMenuModelas their handle (not a real GTK widget), so SHOW/HIDE signals cannot be connected to them directly. The visible popover widgets are created internally byGtkPopoverMenuBaras privateGtkPopoverMenuBarItemchildren, each owning aGtkPopoverMenu. SWT had no visibility into these internal widgets.Changes
Menu.javapopoverHandlefield on DROP_DOWN menus to track the GTK-internalGtkPopoverMenuMAPsignal to BAR menus inhookEvents()— the bar'sGtkPopoverMenuBarItemchildren exist by the time the bar mapsgtk_map(): when the bar maps, callconnectDropDownMenuSignals()to wire up signal routing for all submenusconnectDropDownMenuSignals(): iteratesGtkPopoverMenuBarItemchildren in lockstep withitems, finds each item'sGtkPopoverMenuby type name, registers it in SWT's widget table (keyed to the DROP_DOWNMenu), and connects SHOW/HIDE signals — these route through the existinggtk_show()/gtk_hide()handlers which fireSWT.Show/SWT.HidefindGtkPopoverMenuChild(): walks aGtkPopoverMenuBarItem's direct children looking for type name"GtkPopoverMenu"deregister()on DROP_DOWN menus to remove the popover from the widget table on dispose, preventing stale signal dispatchWarning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
repo.eclipse.org/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/21.0.10-7/x64/bin/java /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/21.0.10-7/x64/bin/java --enable-native-access=ALL-UNNAMED -classpath /opt/hostedtoolcache/maven/3.9.12/x64/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/opt/hostedtoolcache/maven/3.9.12/x64/bin/m2.conf -Dmaven.home=/opt/hostedtoolcache/maven/3.9.12/x64 -Dlibrary.jansi.path=/opt/hostedtoolcache/maven/3.9.12/x64/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/eclipse.platform.swt/eclipse.platform.swt org.codehaus.plexus.classworlds.launcher.Launcher compile -pl bundles/org.eclipse.swt -Dnative=gtk.linux.x86_64 -q -l as -lcairo rin-Hotspot_jdk/--norc rin-Hotspot_jdk/--noprofile b-2.0(dns block)/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/21.0.10-7/x64/bin/java /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/21.0.10-7/x64/bin/java --enable-native-access=ALL-UNNAMED -classpath /opt/hostedtoolcache/maven/3.9.12/x64/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/opt/hostedtoolcache/maven/3.9.12/x64/bin/m2.conf -Dmaven.home=/opt/hostedtoolcache/maven/3.9.12/x64 -Dlibrary.jansi.path=/opt/hostedtoolcache/maven/3.9.12/x64/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/eclipse.platform.swt/eclipse.platform.swt org.codehaus.plexus.classworlds.launcher.Launcher compile -pl bundles/org.eclipse.swt -Dnative=gtk.linux.x86_64 ableScrollsPastContent.java adioButtonNotRendered.java nu_setVisible.java sesHeader.java fbuzz(dns block)/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/21.0.10-7/x64/bin/java /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/21.0.10-7/x64/bin/java --enable-native-access=ALL-UNNAMED -classpath /opt/hostedtoolcache/maven/3.9.12/x64/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/opt/hostedtoolcache/maven/3.9.12/x64/bin/m2.conf -Dmaven.home=/opt/hostedtoolcache/maven/3.9.12/x64 -Dlibrary.jansi.path=/opt/hostedtoolcache/maven/3.9.12/x64/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/eclipse.platform.swt/eclipse.platform.swt org.codehaus.plexus.classworlds.launcher.Launcher test -pl tests/org.eclipse.swt.tests -Dtest=Test_org_eclipse_swt_widgets_Menu -q origin n-Hotspot_jdk/21.0.10-7/x64/include/linux(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.