Skip to content

Commit c8d99c9

Browse files
committed
[GTK4] Fix context menu not being shown
In GTK3, the menu is shown within gtk_button_press_event() iff the MENU bit is set. In GTK4, this check has been inverted. Given that this bit is always set, this means that the menu is never shown. Additionally, GTK4 needs to be informed that the event has been consumed by marking the event as claimed, to prevent bubbling. Practically speaking, this prevents the default menu for GtkEntry's to be shown together with the SWT menus.
1 parent 5d5ed86 commit c8d99c9

File tree

5 files changed

+48
-3
lines changed

5 files changed

+48
-3
lines changed

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,6 +1346,18 @@ JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1gesture_1drag_1new)
13461346
}
13471347
#endif
13481348

1349+
#ifndef NO_gtk_1gesture_1get_1last_1updated_1sequence
1350+
JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1gesture_1get_1last_1updated_1sequence)
1351+
(JNIEnv *env, jclass that, jlong arg0)
1352+
{
1353+
jlong rc = 0;
1354+
GTK4_NATIVE_ENTER(env, that, gtk_1gesture_1get_1last_1updated_1sequence_FUNC);
1355+
rc = (jlong)gtk_gesture_get_last_updated_sequence((GtkGesture *)arg0);
1356+
GTK4_NATIVE_EXIT(env, that, gtk_1gesture_1get_1last_1updated_1sequence_FUNC);
1357+
return rc;
1358+
}
1359+
#endif
1360+
13491361
#ifndef NO_gtk_1gesture_1rotate_1new
13501362
JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1gesture_1rotate_1new)
13511363
(JNIEnv *env, jclass that)
@@ -1358,6 +1370,18 @@ JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1gesture_1rotate_1new)
13581370
}
13591371
#endif
13601372

1373+
#ifndef NO_gtk_1gesture_1set_1sequence_1state
1374+
JNIEXPORT jboolean JNICALL GTK4_NATIVE(gtk_1gesture_1set_1sequence_1state)
1375+
(JNIEnv *env, jclass that, jlong arg0, jlong arg1, jint arg2)
1376+
{
1377+
jboolean rc = 0;
1378+
GTK4_NATIVE_ENTER(env, that, gtk_1gesture_1set_1sequence_1state_FUNC);
1379+
rc = (jboolean)gtk_gesture_set_sequence_state((GtkGesture *)arg0, (GdkEventSequence *)arg1, (GtkEventSequenceState)arg2);
1380+
GTK4_NATIVE_EXIT(env, that, gtk_1gesture_1set_1sequence_1state_FUNC);
1381+
return rc;
1382+
}
1383+
#endif
1384+
13611385
#ifndef NO_gtk_1gesture_1zoom_1new
13621386
JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1gesture_1zoom_1new)
13631387
(JNIEnv *env, jclass that)

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4_stats.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ typedef enum {
114114
gtk_1frame_1set_1child_FUNC,
115115
gtk_1gesture_1click_1new_FUNC,
116116
gtk_1gesture_1drag_1new_FUNC,
117+
gtk_1gesture_1get_1last_1updated_1sequence_FUNC,
117118
gtk_1gesture_1rotate_1new_FUNC,
119+
gtk_1gesture_1set_1sequence_1state_FUNC,
118120
gtk_1gesture_1zoom_1new_FUNC,
119121
gtk_1hsv_1to_1rgb_FUNC,
120122
gtk_1icon_1paintable_1get_1file_FUNC,

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk4/GTK4.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2021, 2024 Syntevo and others.
2+
* Copyright (c) 2021, 2025 Syntevo and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -22,6 +22,10 @@ public class GTK4 {
2222

2323
public static final int GTK_POPOVER_MENU_NESTED = 1 << 0;
2424

25+
public static final int GTK_EVENT_SEQUENCE_NONE = 0;
26+
public static final int GTK_EVENT_SEQUENCE_CLAIMED = 1;
27+
public static final int GTK_EVENT_SEQUENCE_DENIED = 2;
28+
2529
/**
2630
* @param context cast=(GtkIMContext *)
2731
* @param event cast=(GdkEvent *)
@@ -825,4 +829,16 @@ public class GTK4 {
825829

826830
public static final native long gtk_gesture_drag_new();
827831

832+
/**
833+
* @param gesture cast=(GtkGesture *)
834+
* @param sequence cast=(GdkEventSequence *)
835+
* @param state cast=(GtkEventSequenceState)
836+
*/
837+
public static final native boolean gtk_gesture_set_sequence_state(long gesture, long sequence, int state);
838+
839+
/**
840+
* @param gesture cast=(GtkGesture *)
841+
*/
842+
public static final native long gtk_gesture_get_last_updated_sequence(long gesture);
843+
828844
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3416,7 +3416,7 @@ void gtk_gesture_press_event (long gesture, int n_press, double x, double y, lon
34163416
display.clickCount = n_press;
34173417
if (n_press == 1) {
34183418
sendMouseEvent(SWT.MouseDown, eventButton, n_press, 0, false, eventTime, x, y, false, eventState);
3419-
if ((state & MENU) == 0) {
3419+
if ((state & MENU) != 0) {
34203420
if (eventButton == 3) {
34213421
showMenu ((int)x, (int)y);
34223422
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2024 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -2531,6 +2531,7 @@ boolean keyPressReleaseProc(long controller, int keyval, int keycode, int state,
25312531

25322532
void gesturePressReleaseProc(long gesture, int n_press, double x, double y, long user_data) {
25332533
long event = GTK4.gtk_event_controller_get_current_event(gesture);
2534+
long sequence = GTK4.gtk_gesture_get_last_updated_sequence(gesture);
25342535

25352536
switch ((int)user_data) {
25362537
case GESTURE_PRESSED:
@@ -2540,6 +2541,8 @@ void gesturePressReleaseProc(long gesture, int n_press, double x, double y, long
25402541
gtk_gesture_release_event(gesture, n_press, x, y, event);
25412542
break;
25422543
}
2544+
2545+
GTK4.gtk_gesture_set_sequence_state(gesture, sequence, GTK4.GTK_EVENT_SEQUENCE_CLAIMED);
25432546
}
25442547

25452548
void leaveProc(long controller, long handle, long user_data) {

0 commit comments

Comments
 (0)