Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXi Yan2019-01-31 15:21:28 -0500
committerXi Yan2019-02-04 13:26:08 -0500
commita43e2d35df296d43c4e345e18c2412744183d278 (patch)
tree03710542bd2bf5d0236ddaab871a1928d4b72d9b
parent796a41a7ac80115a4a90c80b42d2989134aed2ef (diff)
downloadeclipse.platform.swt-a43e2d35df296d43c4e345e18c2412744183d278.tar.gz
eclipse.platform.swt-a43e2d35df296d43c4e345e18c2412744183d278.tar.xz
eclipse.platform.swt-a43e2d35df296d43c4e345e18c2412744183d278.zip
Bug 543984 - [GTK4] Adapt to GdkEventType constants changes
- Add new GdkEventType constant values - Add pre-processing function to fix different GdkEventType values on GTK4 - Adapt all GdkEventType to use correct constant on GTK3 and GTK4 - Guard connecting to event signal in Shell to avoid duplicate mouse press/release events. Tested on GTK3 with ControlExample Listeners. Tested with attached snippet on GTK4. Change-Id: I43f139a0b8d8b41820c64189767377ebb6fc9db5 Signed-off-by: Xi Yan <xixiyan@redhat.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GDK.java17
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java4
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java32
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java1
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Link.java1
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java1
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java9
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ScrollBar.java1
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java32
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Slider.java1
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java2
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java1
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableColumn.java2
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java3
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java2
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tracker.java6
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TrayItem.java3
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java1
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeColumn.java2
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java2
-rw-r--r--tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug543984_GTK4EventTypeConstants.java82
21 files changed, 185 insertions, 20 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GDK.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GDK.java
index a819889460..564f80db17 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GDK.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GDK.java
@@ -41,14 +41,11 @@ public class GDK extends OS {
public static final int GDK_BUTTON2_MOTION_MASK = 1 << 6;
public static final int GDK_BUTTON3_MOTION_MASK = 1 << 7;
public static final int GDK_BUTTON_PRESS = 0x4;
- public static final int GDK4_BUTTON_PRESS = 0x5;
public static final int GDK_BUTTON_PRESS_MASK = 0x100;
public static final int GDK_BUTTON_RELEASE = 0x7;
- public static final int GDK4_BUTTON_RELEASE = 0x6;
public static final int GDK_BUTTON_RELEASE_MASK = 0x200;
public static final int GDK_COLORSPACE_RGB = 0;
public static final int GDK_CONFIGURE = 13;
- public static final int GDK4_CONFIGURE = 12;
public static final int GDK_CONTROL_MASK = 0x4;
public static final int GDK_CROSS = 0x1e;
public static final int GDK_CROSSING_NORMAL = 0;
@@ -260,6 +257,20 @@ public class GDK extends OS {
public static final int GDK_WINDOW_TYPE_HINT_UTILITY = 5;
public static final int GDK_WINDOW_TYPE_HINT_TOOLTIP = 10;
+ /** GdkEventType constants are different on GTK4 */
+ public static final int GDK4_EXPOSE = 3;
+ public static final int GDK4_MOTION_NOTIFY = 4;
+ public static final int GDK4_BUTTON_PRESS = 5;
+ public static final int GDK4_BUTTON_RELEASE = 6;
+ public static final int GDK4_KEY_PRESS = 7;
+ public static final int GDK4_KEY_RELEASE = 8;
+ public static final int GDK4_ENTER_NOTIFY = 9;
+ public static final int GDK4_LEAVE_NOTIFY = 10;
+ public static final int GDK4_FOCUS_CHANGE = 11;
+ public static final int GDK4_CONFIGURE = 12;
+ public static final int GDK4_MAP = 13;
+ public static final int GDK4_UNMAP = 14;
+
/** sizeof(TYPE) for 32/64 bit support */
public static final native int GdkKeymapKey_sizeof();
public static final native int GdkRGBA_sizeof();
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java
index 8e21524239..0eb94d213e 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java
@@ -1329,6 +1329,7 @@ long /*int*/ gtk_button_press_event (long /*int*/ widget, long /*int*/ event) {
int [] eventButton = new int [1];
GDK.gdk_event_get_button(event, eventButton);
int eventType = GDK.gdk_event_get_event_type(event);
+ eventType = fixGdkEventTypeValues(eventType);
if (eventType == GDK.GDK_BUTTON_PRESS && eventButton[0] == 1) {
return gtk_button_press_event(widget, event, false);
}
@@ -1370,6 +1371,7 @@ long /*int*/ gtk_changed (long /*int*/ widget) {
long /*int*/ eventPtr = GTK.gtk_get_current_event ();
if (eventPtr != 0) {
int eventType = GDK.gdk_event_get_event_type(eventPtr);
+ eventType = fixGdkEventTypeValues(eventType);
switch (eventType) {
case GDK.GDK_KEY_PRESS:
keyPress = true;
@@ -1535,6 +1537,7 @@ long /*int*/ gtk_event_after (long /*int*/ widget, long /*int*/ gdkEvent) {
* field.
*/
int eventType = GDK.gdk_event_get_event_type(gdkEvent);
+ eventType = fixGdkEventTypeValues(eventType);
switch (eventType) {
case GDK.GDK_BUTTON_PRESS: {
int [] eventButton = new int [1];
@@ -2618,6 +2621,7 @@ String verifyText (String string, int start, int end) {
long /*int*/ eventPtr = GTK.gtk_get_current_event ();
if (eventPtr != 0) {
int type = GDK.gdk_event_get_event_type(eventPtr);
+ type = fixGdkEventTypeValues(type);
switch (type) {
case GDK.GDK_KEY_PRESS:
setKeyState (event, eventPtr);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java
index 5f4da94ea5..5a7a42bf08 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java
@@ -294,6 +294,31 @@ long /*int*/ eventSurface () {
return gtk_widget_get_surface (eventHandle);
}
+/**
+ * GdkEventType constants different on GTK4 and GTK3.
+ * This checks for GTK versions and return the correct constants defined in GDK.java
+ * @param eventType
+ * @return constant defined
+ */
+static int fixGdkEventTypeValues(int eventType) {
+ if (GTK.GTK4) {
+ switch (eventType) {
+ case GDK.GDK4_EXPOSE: return GDK.GDK_EXPOSE;
+ case GDK.GDK4_MOTION_NOTIFY: return GDK.GDK_MOTION_NOTIFY;
+ case GDK.GDK4_BUTTON_PRESS: return GDK.GDK_BUTTON_PRESS;
+ case GDK.GDK4_BUTTON_RELEASE: return GDK.GDK_BUTTON_RELEASE;
+ case GDK.GDK4_KEY_PRESS: return GDK.GDK_KEY_PRESS;
+ case GDK.GDK4_ENTER_NOTIFY: return GDK.GDK_ENTER_NOTIFY;
+ case GDK.GDK4_LEAVE_NOTIFY: return GDK.GDK_LEAVE_NOTIFY;
+ case GDK.GDK4_FOCUS_CHANGE: return GDK.GDK_FOCUS_CHANGE;
+ case GDK.GDK4_CONFIGURE: return GDK.GDK_CONFIGURE;
+ case GDK.GDK4_MAP: return GDK.GDK_MAP;
+ case GDK.GDK4_UNMAP: return GDK.GDK_UNMAP;
+ }
+ }
+ return eventType;
+}
+
void fixFocus (Control focusControl) {
Shell shell = getShell ();
Control control = this;
@@ -2711,7 +2736,9 @@ boolean dragDetect (int x, int y, boolean filter, boolean dragOnTimeout, boolean
display.sendPostExternalEventDispatchEvent();
if (dragging) return true; //428852
if (eventPtr == 0) return dragOnTimeout;
- switch (GDK.GDK_EVENT_TYPE (eventPtr)) {
+ int eventType = GDK.gdk_event_get_event_type(eventPtr);
+ eventType = fixGdkEventTypeValues(eventType);
+ switch (eventType) {
case GDK.GDK_MOTION_NOTIFY: {
int [] state = new int[1];
GDK.gdk_event_get_state(eventPtr, state);
@@ -3408,6 +3435,7 @@ long /*int*/ gtk_button_press_event (long /*int*/ widget, long /*int*/ event, bo
double [] eventY = new double [1];
GDK.gdk_event_get_coords(event, eventX, eventY);
int eventType = GDK.gdk_event_get_event_type(event);
+ eventType = fixGdkEventTypeValues(eventType);
int [] eventButton = new int [1];
GDK.gdk_event_get_button(event, eventButton);
int eventTime = GDK.gdk_event_get_time(event);
@@ -3599,6 +3627,7 @@ boolean checkSubwindow () {
@Override
long /*int*/ gtk_event_after (long /*int*/ widget, long /*int*/ gdkEvent) {
int eventType = GDK.gdk_event_get_event_type(gdkEvent);
+ eventType = fixGdkEventTypeValues(eventType);
switch (eventType) {
case GDK.GDK_BUTTON_PRESS: {
if (widget != eventHandle ()) break;
@@ -3876,6 +3905,7 @@ long /*int*/ gtk_mnemonic_activate (long /*int*/ widget, long /*int*/ arg1) {
long /*int*/ eventPtr = GTK.gtk_get_current_event ();
if (eventPtr != 0) {
int type = GDK.gdk_event_get_event_type(eventPtr);
+ type = fixGdkEventTypeValues(type);
if (type == GDK.GDK_KEY_PRESS) {
Control focusControl = display.getFocusControl ();
long /*int*/ focusHandle = focusControl != null ? focusControl.focusHandle () : 0;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
index 20420d7353..afc2da5fea 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
@@ -1376,6 +1376,7 @@ long /*int*/ eventProc (long /*int*/ event, long /*int*/ data) {
if (time != 0) lastEventTime = time;
int eventType = GTK.GTK4 ? GDK.gdk_event_get_event_type(event) : GDK.GDK_EVENT_TYPE (event);
+ Control.fixGdkEventTypeValues(eventType);
switch (eventType) {
case GDK.GDK_BUTTON_PRESS:
case GDK.GDK_KEY_PRESS:
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Link.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Link.java
index 41a8950842..ef4ad77ac4 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Link.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Link.java
@@ -332,6 +332,7 @@ long /*int*/ gtk_button_press_event (long /*int*/ widget, long /*int*/ event) {
long /*int*/ result = super.gtk_button_press_event (widget, event);
if (result != 0) return result;
int eventType = GDK.gdk_event_get_event_type(event);
+ eventType = fixGdkEventTypeValues(eventType);
int [] eventButton = new int [1];
GDK.gdk_event_get_button(event, eventButton);
double [] eventX = new double [1];
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java
index 29f64fd599..a45d3560f4 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java
@@ -800,6 +800,7 @@ long /*int*/ gtk_button_press_event (long /*int*/ widget, long /*int*/ event) {
double [] eventY = new double [1];
GDK.gdk_event_get_coords(event, eventX, eventY);
int eventType = GDK.gdk_event_get_event_type(event);
+ eventType = fixGdkEventTypeValues(eventType);
int [] eventState = new int [1];
GDK.gdk_event_get_state(event, eventState);
int [] eventButton = new int [1];
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java
index 9eb7d92f94..24ec16a935 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java
@@ -256,9 +256,9 @@ void _setVisible (boolean visible) {
if (ableToSetLocation()) {
// Create the GdkEvent manually as we need to control
// certain fields like the event window
- eventPtr = GDK.gdk_event_new(GDK.GDK_BUTTON_PRESS);
+ eventPtr = GDK.gdk_event_new(GTK.GTK4 ? GDK.GDK4_BUTTON_PRESS : GDK.GDK_BUTTON_PRESS);
GdkEventButton event = new GdkEventButton ();
- event.type = GDK.GDK_BUTTON_PRESS;
+ event.type = GTK.GTK4 ? GDK.GDK4_BUTTON_PRESS : GDK.GDK_BUTTON_PRESS;
event.device = GDK.gdk_get_pointer(GDK.gdk_display_get_default());
event.time = display.getLastEventTime();
@@ -309,9 +309,9 @@ void _setVisible (boolean visible) {
*/
eventPtr = GTK.gtk_get_current_event();
if (eventPtr == 0) {
- eventPtr = GDK.gdk_event_new(GDK.GDK_BUTTON_PRESS);
+ eventPtr = GDK.gdk_event_new(GTK.GTK4 ? GDK.GDK4_BUTTON_PRESS : GDK.GDK_BUTTON_PRESS);
GdkEventButton event = new GdkEventButton ();
- event.type = GDK.GDK_BUTTON_PRESS;
+ event.type = GTK.GTK4 ? GDK.GDK4_BUTTON_PRESS : GDK.GDK_BUTTON_PRESS;
// Only assign a window on X11, as on Wayland the window is that of the mouse pointer
if (OS.isX11()) {
event.window = OS.g_object_ref(GTK.gtk_widget_get_window (getShell().handle));
@@ -1215,6 +1215,7 @@ void adjustParentWindowWayland (long /*int*/ eventPtr) {
}
OS.g_object_ref(deviceResource);
int eventType = GDK.gdk_event_get_event_type(eventPtr);
+ eventType = Control.fixGdkEventTypeValues(eventType);
switch (eventType) {
case GDK.GDK_BUTTON_PRESS:
GdkEventButton eventButton = new GdkEventButton();
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ScrollBar.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ScrollBar.java
index 9bbf761d5b..1ea85793cb 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ScrollBar.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ScrollBar.java
@@ -567,6 +567,7 @@ long /*int*/ gtk_value_changed (long /*int*/ adjustment) {
@Override
long /*int*/ gtk_event_after (long /*int*/ widget, long /*int*/ gdkEvent) {
int eventType = GDK.gdk_event_get_event_type(gdkEvent);
+ eventType = Control.fixGdkEventTypeValues(eventType);
switch (eventType) {
case GDK.GDK_BUTTON_RELEASE: {
int [] eventButton = new int [1];
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java
index de880e81f6..520fba47ff 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java
@@ -919,7 +919,9 @@ void hookEvents () {
super.hookEvents ();
if (GTK.GTK4) {
// Replace configure-event with generic event handler
- OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [EVENT], 0, display.getClosure (EVENT), false);
+ if (eventHandle() == 0) {
+ OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [EVENT], 0, display.getClosure (EVENT), false);
+ }
} else {
OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [WINDOW_STATE_EVENT], 0, display.getClosure (WINDOW_STATE_EVENT), false);
OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [CONFIGURE_EVENT], 0, display.getClosure (CONFIGURE_EVENT), false);
@@ -2674,15 +2676,25 @@ public void setVisible (boolean visible) {
}
if (isDisposed ()) return;
if (!(OS.isX11() && GTK.GTK_IS_PLUG (shellHandle))) {
- display.dispatchEvents = new int [] {
- GDK.GDK_EXPOSE,
- GDK.GDK_FOCUS_CHANGE,
- GDK.GDK_CONFIGURE,
- GDK.GDK_MAP,
- GDK.GDK_UNMAP,
- GDK.GDK_NO_EXPOSE,
- GDK.GDK_WINDOW_STATE
- };
+ if (GTK.GTK4) {
+ display.dispatchEvents = new int [] {
+ GDK.GDK4_EXPOSE,
+ GDK.GDK4_FOCUS_CHANGE,
+ GDK.GDK4_CONFIGURE,
+ GDK.GDK4_MAP,
+ GDK.GDK4_UNMAP,
+ };
+ } else {
+ display.dispatchEvents = new int [] {
+ GDK.GDK_EXPOSE,
+ GDK.GDK_FOCUS_CHANGE,
+ GDK.GDK_CONFIGURE,
+ GDK.GDK_MAP,
+ GDK.GDK_UNMAP,
+ GDK.GDK_NO_EXPOSE,
+ GDK.GDK_WINDOW_STATE
+ };
+ }
Display display = this.display;
display.putGdkEvents();
boolean iconic = false;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Slider.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Slider.java
index 86f1742aa2..494fc4efa5 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Slider.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Slider.java
@@ -224,6 +224,7 @@ long /*int*/ gtk_value_changed (long /*int*/ adjustment) {
@Override
long /*int*/ gtk_event_after (long /*int*/ widget, long /*int*/ gdkEvent) {
int eventType = GDK.gdk_event_get_event_type(gdkEvent);
+ eventType = Control.fixGdkEventTypeValues(eventType);
switch (eventType) {
case GDK.GDK_BUTTON_RELEASE: {
int [] eventButton = new int [1];
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java
index d2273fe6b4..9a8ade8c89 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java
@@ -605,6 +605,7 @@ long /*int*/ gtk_changed (long /*int*/ widget) {
long /*int*/ eventPtr = GTK.gtk_get_current_event ();
if (eventPtr != 0) {
int eventType = GDK.gdk_event_get_event_type(eventPtr);
+ eventType = fixGdkEventTypeValues(eventType);
switch (eventType) {
case GDK.GDK_KEY_PRESS:
keyPress = true;
@@ -1226,6 +1227,7 @@ String verifyText (String string, int start, int end) {
long /*int*/ eventPtr = GTK.gtk_get_current_event ();
if (eventPtr != 0) {
int type = GDK.gdk_event_get_event_type(eventPtr);
+ type = fixGdkEventTypeValues(type);
switch (type) {
case GDK.GDK_KEY_PRESS:
setKeyState (event, eventPtr);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java
index 42aa4372ec..98c5ade50a 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java
@@ -1988,6 +1988,7 @@ long /*int*/ gtk_button_press_event (long /*int*/ widget, long /*int*/ event) {
double [] eventY = new double [1];
GDK.gdk_event_get_coords(event, eventX, eventY);
int eventType = GDK.gdk_event_get_event_type(event);
+ eventType = fixGdkEventTypeValues(eventType);
int [] eventButton = new int [1];
GDK.gdk_event_get_button(event, eventButton);
double [] eventRX = new double [1];
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableColumn.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableColumn.java
index da4add2fad..d834d230f7 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableColumn.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableColumn.java
@@ -352,6 +352,7 @@ long /*int*/ gtk_clicked (long /*int*/ widget) {
int [] eventButton = new int [1];
GDK.gdk_event_get_button(eventPtr, eventButton);
int eventType = GDK.gdk_event_get_event_type(eventPtr);
+ eventType = Control.fixGdkEventTypeValues(eventType);
int eventTime = GDK.gdk_event_get_time(eventPtr);
switch (eventType) {
case GDK.GDK_BUTTON_RELEASE: {
@@ -373,6 +374,7 @@ long /*int*/ gtk_clicked (long /*int*/ widget) {
@Override
long /*int*/ gtk_event_after (long /*int*/ widget, long /*int*/ gdkEvent) {
int eventType = GDK.gdk_event_get_event_type(gdkEvent);
+ eventType = Control.fixGdkEventTypeValues(eventType);
switch (eventType) {
case GDK.GDK_BUTTON_PRESS: {
int [] eventButton = new int [1];
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java
index e293809a99..53ae4e8834 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java
@@ -1478,6 +1478,7 @@ long /*int*/ gtk_changed (long /*int*/ widget) {
long /*int*/ eventPtr = GTK.gtk_get_current_event ();
if (eventPtr != 0) {
int eventType = GDK.gdk_event_get_event_type(eventPtr);
+ eventType = fixGdkEventTypeValues(eventType);
switch (eventType) {
case GDK.GDK_KEY_PRESS:
keyPress = true;
@@ -1634,6 +1635,7 @@ long /*int*/ gtk_event_after (long /*int*/ widget, long /*int*/ gdkEvent) {
*/
if ((style & SWT.SINGLE) != 0 && display.entrySelectOnFocus) {
int eventType = GDK.gdk_event_get_event_type(gdkEvent);
+ eventType = fixGdkEventTypeValues(eventType);
switch (eventType) {
case GDK.GDK_FOCUS_CHANGE:
boolean [] focusIn = new boolean [1];
@@ -2848,6 +2850,7 @@ String verifyText (String string, int start, int end) {
long /*int*/ eventPtr = GTK.gtk_get_current_event ();
if (eventPtr != 0) {
int type = GDK.gdk_event_get_event_type(eventPtr);
+ type = fixGdkEventTypeValues(type);
switch (type) {
case GDK.GDK_KEY_PRESS:
setKeyState (event, eventPtr);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java
index 15755288c6..91b69c939e 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java
@@ -500,6 +500,7 @@ long /*int*/ gtk_clicked (long /*int*/ widget) {
long /*int*/ eventPtr = GTK.gtk_get_current_event ();
if (eventPtr != 0) {
int eventType = GDK.gdk_event_get_event_type(eventPtr);
+ eventType = Control.fixGdkEventTypeValues(eventType);
long /*int*/ topHandle = topHandle();
switch (eventType) {
case GDK.GDK_KEY_RELEASE: //Fall Through..
@@ -655,6 +656,7 @@ long /*int*/ gtk_enter_notify_event (long /*int*/ widget, long /*int*/ event) {
@Override
long /*int*/ gtk_event_after (long /*int*/ widget, long /*int*/ gdkEvent) {
int eventType = GDK.gdk_event_get_event_type(gdkEvent);
+ eventType = Control.fixGdkEventTypeValues(eventType);
switch (eventType) {
case GDK.GDK_BUTTON_PRESS: {
int [] eventButton = new int [1];
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tracker.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tracker.java
index ebc834e103..35412d74d9 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tracker.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tracker.java
@@ -478,7 +478,7 @@ boolean grab () {
@Override
long /*int*/ gtk_button_release_event (long /*int*/ widget, long /*int*/ event) {
Control.mouseDown = false;
- return gtk_mouse (GDK.GDK_BUTTON_RELEASE, widget, event);
+ return gtk_mouse (GTK.GTK4 ? GDK.GDK4_BUTTON_RELEASE : GDK.GDK_BUTTON_RELEASE, widget, event);
}
@Override
@@ -625,7 +625,7 @@ long /*int*/ gtk_motion_notify_event (long /*int*/ widget, long /*int*/ eventPtr
grabbed = grab ();
lastCursor = cursor;
}
- return gtk_mouse (GDK.GDK_MOTION_NOTIFY, widget, eventPtr);
+ return gtk_mouse (GTK.GTK4 ? GDK.GDK4_MOTION_NOTIFY : GDK.GDK_MOTION_NOTIFY, widget, eventPtr);
}
long /*int*/ gtk_mouse (int eventType, long /*int*/ widget, long /*int*/ eventPtr) {
@@ -736,6 +736,7 @@ long /*int*/ gtk_mouse (int eventType, long /*int*/ widget, long /*int*/ eventPt
oldX = newX [0];
oldY = newY [0];
}
+ eventType = Control.fixGdkEventTypeValues(eventType);
tracking = eventType != GDK.GDK_BUTTON_RELEASE;
return 0;
}
@@ -902,6 +903,7 @@ private void setTrackerBackground(boolean opaque) {
boolean processEvent (long /*int*/ eventPtr) {
int eventType = GDK.gdk_event_get_event_type(eventPtr);
+ eventType = Control.fixGdkEventTypeValues(eventType);
long /*int*/ widget = GTK.gtk_get_event_widget (eventPtr);
switch (eventType) {
case GDK.GDK_MOTION_NOTIFY: gtk_motion_notify_event (widget, eventPtr); break;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TrayItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TrayItem.java
index 0e49decdae..aaf48d9ff7 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TrayItem.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TrayItem.java
@@ -264,6 +264,8 @@ long /*int*/ gtk_activate (long /*int*/ widget) {
gdk_event_free(currEvent);
}
GDK.gdk_event_free (nextEvent);
+ currEventType = Control.fixGdkEventTypeValues(currEventType);
+ nextEventType = Control.fixGdkEventTypeValues(nextEventType);
if (currEventType == GDK.GDK_BUTTON_PRESS && nextEventType == GDK.GDK_2BUTTON_PRESS) {
sendSelectionEvent (SWT.DefaultSelection);
}
@@ -274,6 +276,7 @@ long /*int*/ gtk_activate (long /*int*/ widget) {
@Override
long /*int*/ gtk_button_press_event (long /*int*/ widget, long /*int*/ event) {
int eventType = GDK.gdk_event_get_event_type(event);
+ eventType = Control.fixGdkEventTypeValues(eventType);
int [] eventButton = new int [1];
GDK.gdk_event_get_button(event, eventButton);
if (eventType == GDK.GDK_3BUTTON_PRESS) return 0;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java
index 80af7c4ae6..a96dc3cb05 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java
@@ -2054,6 +2054,7 @@ long /*int*/ gtk_button_press_event (long /*int*/ widget, long /*int*/ event) {
double [] eventY = new double [1];
GDK.gdk_event_get_coords(event, eventX, eventY);
int eventType = GDK.gdk_event_get_event_type(event);
+ eventType = fixGdkEventTypeValues(eventType);
int [] eventButton = new int [1];
GDK.gdk_event_get_button(event, eventButton);
double [] eventRX = new double [1];
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeColumn.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeColumn.java
index 3f82e32523..a432648c50 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeColumn.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeColumn.java
@@ -354,6 +354,7 @@ long /*int*/ gtk_clicked (long /*int*/ widget) {
int [] eventButton = new int [1];
GDK.gdk_event_get_button(eventPtr, eventButton);
int eventType = GDK.gdk_event_get_event_type(eventPtr);
+ eventType = Control.fixGdkEventTypeValues(eventType);
int eventTime = GDK.gdk_event_get_time(eventPtr);
switch (eventType) {
case GDK.GDK_BUTTON_RELEASE: {
@@ -375,6 +376,7 @@ long /*int*/ gtk_clicked (long /*int*/ widget) {
@Override
long /*int*/ gtk_event_after (long /*int*/ widget, long /*int*/ gdkEvent) {
int eventType = GDK.gdk_event_get_event_type(gdkEvent);
+ eventType = Control.fixGdkEventTypeValues(eventType);
switch (eventType) {
case GDK.GDK_BUTTON_PRESS: {
int [] eventButton = new int [1];
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java
index 7001a6c20b..8590a03696 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java
@@ -1473,6 +1473,7 @@ char [] sendIMKeyEvent (int type, long /*int*/ event, char [] chars) {
ptr = GTK.gtk_get_current_event ();
if (ptr != 0) {
int eventType = GDK.gdk_event_get_event_type(ptr);
+ eventType = Control.fixGdkEventTypeValues(eventType);
switch (eventType) {
case GDK.GDK_KEY_PRESS:
case GDK.GDK_KEY_RELEASE:
@@ -1536,6 +1537,7 @@ void sendSelectionEvent (int eventType, Event event, boolean send) {
long /*int*/ ptr = GTK.gtk_get_current_event ();
if (ptr != 0) {
int currentEventType = GDK.gdk_event_get_event_type(ptr);
+ currentEventType = Control.fixGdkEventTypeValues(currentEventType);
switch (currentEventType) {
case GDK.GDK_KEY_PRESS:
case GDK.GDK_KEY_RELEASE:
diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug543984_GTK4EventTypeConstants.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug543984_GTK4EventTypeConstants.java
new file mode 100644
index 0000000000..7271c60794
--- /dev/null
+++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug543984_GTK4EventTypeConstants.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 2018 Red Hat and others. All rights reserved.
+ * The contents of this file are made available under the terms
+ * of the GNU Lesser General Public License (LGPL) Version 2.1 that
+ * accompanies this distribution (lgpl-v21.txt). The LGPL is also
+ * available at http://www.gnu.org/licenses/lgpl.html. If the version
+ * of the LGPL at http://www.gnu.org is different to the version of
+ * the LGPL accompanying this distribution and there is any conflict
+ * between the two license versions, the terms of the LGPL accompanying
+ * this distribution shall govern.
+ *
+ * Contributors:
+ * Red Hat - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swt.tests.gtk.snippets;
+
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+/*
+ * Title:
+ * How to run:
+ * Bug description:
+ * Expected results:
+ * GTK Version(s):
+ */
+public class Bug543984_GTK4EventTypeConstants {
+
+ public static void main(String[] args) {
+ Display display = new Display();
+ Shell shell = new Shell(display);
+ shell.setLayout(new FillLayout());
+ shell.setSize(500, 200);
+
+ shell.open();
+
+ shell.addMouseListener(new MouseListener() {
+
+ @Override
+ public void mouseUp(MouseEvent e) {
+ System.out.println("MouseUp");
+
+ }
+
+ @Override
+ public void mouseDown(MouseEvent e) {
+ System.out.println("MouseDown");
+
+ }
+
+ @Override
+ public void mouseDoubleClick(MouseEvent e) {
+ // TODO: GDK_2BUTTON_PRESS removed in GTK4, no signal for double click
+ System.out.println("MouseDoubleClick");
+
+ }
+ });
+
+ shell.addKeyListener(new KeyListener() {
+
+ @Override
+ public void keyReleased(KeyEvent e) {
+ System.out.println("KeyReleased " + e.character);
+ }
+
+ @Override
+ public void keyPressed(KeyEvent e) {
+ System.out.println("KeyPressed " + e.character);
+ }
+ });
+
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ }
+} \ No newline at end of file

Back to the top