Skip to content

Commit 38e1395

Browse files
Copilotakurtakov
andcommitted
GTK4: Use eager CASCADE menu population with recursive sendEvent
Co-authored-by: akurtakov <574788+akurtakov@users.noreply.github.com>
1 parent 984867b commit 38e1395

2 files changed

Lines changed: 25 additions & 30 deletions

File tree

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -862,33 +862,6 @@ long gtk_show (long widget) {
862862
return 0;
863863
}
864864

865-
@Override
866-
long notifyProc (long object, long arg0, long user_data) {
867-
switch ((int)user_data) {
868-
case NOTIFY_VISIBLE:
869-
// GTK4: When a BAR or POP_UP menu becomes visible,
870-
// fire SWT.Show on all CASCADE sub-menus to enable lazy population
871-
if (GTK.GTK4 && (style & SWT.DROP_DOWN) == 0) {
872-
// Check if the menu is becoming visible
873-
boolean visible = GTK.gtk_widget_get_visible(handle);
874-
if (visible) {
875-
MenuItem[] items = getItems();
876-
for (int i = 0; i < items.length; i++) {
877-
MenuItem item = items[i];
878-
if ((item.style & SWT.CASCADE) != 0) {
879-
Menu subMenu = item.getMenu();
880-
if (subMenu != null && !subMenu.isDisposed()) {
881-
subMenu.sendEvent(SWT.Show);
882-
}
883-
}
884-
}
885-
}
886-
}
887-
return 0;
888-
}
889-
return super.notifyProc(object, arg0, user_data);
890-
}
891-
892865

893866
@Override
894867
long gtk3_show_help (long widget, long helpType) {
@@ -938,9 +911,6 @@ void hookEvents() {
938911
if ((style & SWT.DROP_DOWN) == 0) {
939912
OS.g_signal_connect_closure_by_id(handle, display.signalIds[SHOW], 0, display.getClosure(SHOW), false);
940913
OS.g_signal_connect_closure_by_id(handle, display.signalIds[HIDE], 0, display.getClosure(HIDE), false);
941-
942-
// Hook notify::visible to fire SWT.Show on CASCADE sub-menus when parent becomes visible
943-
OS.g_signal_connect(handle, OS.notify_visible, display.notifyProc, NOTIFY_VISIBLE);
944914
}
945915

946916
} else {
@@ -1303,6 +1273,25 @@ void setOrientation (boolean create) {
13031273
}
13041274
}
13051275

1276+
@Override
1277+
void sendEvent (int eventType) {
1278+
super.sendEvent(eventType);
1279+
// GTK4: When sending SWT.Show to a menu, recursively send it to CASCADE sub-menus
1280+
// This is needed because DROP_DOWN menus don't have widget handles and can't receive signals
1281+
if (GTK.GTK4 && eventType == SWT.Show) {
1282+
MenuItem[] items = getItems();
1283+
for (int i = 0; i < items.length; i++) {
1284+
MenuItem item = items[i];
1285+
if ((item.style & SWT.CASCADE) != 0) {
1286+
Menu subMenu = item.getMenu();
1287+
if (subMenu != null && !subMenu.isDisposed()) {
1288+
subMenu.sendEvent(SWT.Show);
1289+
}
1290+
}
1291+
}
1292+
}
1293+
}
1294+
13061295
/**
13071296
* Lack of absolute coordinates make Wayland event windows inaccurate.
13081297
* Currently the best approach is to the use the GdkWindow of the mouse

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,12 @@ public void setMenu (Menu menu) {
11361136
if (menu != null) {
11371137
menu.cascade = this;
11381138
OS.g_menu_item_set_submenu(handle, menu.modelHandle);
1139+
1140+
// GTK4: Manually trigger SWT.Show for DROP_DOWN sub-menu
1141+
// In GTK4, DROP_DOWN menus don't have widget handles and can't receive signals.
1142+
// Fire SWT.Show now to populate the menu. The recursive sendEvent override
1143+
// will also populate nested CASCADE menus.
1144+
menu.sendEvent(SWT.Show);
11391145
} else {
11401146
oldMenu.cascade = null;
11411147
OS.g_menu_item_set_submenu(handle, 0);

0 commit comments

Comments
 (0)