Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Williams2019-04-16 15:51:13 -0400
committerEric Williams2019-04-17 09:49:43 -0400
commit43987e44f8a5a494a8bb49a18d0c9258dcbace1b (patch)
treeada5f5f21522a0297e94b09470213f7f3e11c7a5
parentf05aa6b2a7a23b2cadd893812efb505061017fcb (diff)
downloadeclipse.platform.swt-43987e44f8a5a494a8bb49a18d0c9258dcbace1b.tar.gz
eclipse.platform.swt-43987e44f8a5a494a8bb49a18d0c9258dcbace1b.tar.xz
eclipse.platform.swt-43987e44f8a5a494a8bb49a18d0c9258dcbace1b.zip
Bug 546493: [GTK4] Button click coordinates are incorrect for some cases
This is a two-part fix: 1) Adjust the sendMouseDown() function in Control, as event coordinates on GTK4 are already parent relative. 2) Table/Tree have headers built into the GtkTreeview's surface, meaning the y-coordinates will include the height of the header. This throws off any geometry-item querying code in Table/Tree. The fix is to adjust the coordinates to account for the size of the header. GTK3 doesn't have this problem because the header has its own GdkWindow which is separate from the rest of the Table/Tree. Tested using Snippet3 on GTK4. Change-Id: Ia68a6edb376a823dc3beb57e4db084075e42138b Signed-off-by: Eric Williams <ericwill@redhat.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java10
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java8
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java8
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java8
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java11
5 files changed, 42 insertions, 3 deletions
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 558caf1ad4..0dda66274d 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
@@ -3579,8 +3579,14 @@ long gtk_button_press_event (long widget, long event, boolean sendMouseDown) {
}
}
}
- if (sendMouseDown && !sendMouseEvent (SWT.MouseDown, eventButton[0], display.clickCount, 0, false, eventTime, eventRX[0], eventRY[0], false, eventState[0])) {
- result = 1;
+ if (sendMouseDown) {
+ boolean mouseEventSent;
+ if (GTK.GTK4) {
+ mouseEventSent = !sendMouseEvent (SWT.MouseDown, eventButton[0], display.clickCount, 0, false, eventTime, eventX[0], eventY[0], true, eventState[0]);
+ } else {
+ mouseEventSent = !sendMouseEvent (SWT.MouseDown, eventButton[0], display.clickCount, 0, false, eventTime, eventRX[0], eventRY[0], false, eventState[0]);
+ }
+ result = mouseEventSent ? 1 : 0;
}
if (isDisposed ()) return 1;
/*
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 3a8ed4dfe9..778f9eb401 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
@@ -1612,6 +1612,14 @@ TableItem getItemInPixels (Point point) {
long [] path = new long [1];
GTK.gtk_widget_realize (handle);
int y = point.y;
+ /*
+ * On GTK4 the header is included in the entire widget's surface, so we must subtract
+ * its size from the y-coordinate. This does not apply on GTK3 as the header and
+ * "main-widget" have separate GdkWindows.
+ */
+ if (getHeaderVisible() && GTK.GTK4) {
+ y -= getHeaderHeight();
+ }
if (!GTK.gtk_tree_view_get_path_at_pos (handle, point.x, y, path, null, null, null)) return null;
if (path [0] == 0) return null;
long indices = GTK.gtk_tree_path_get_indices (path [0]);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java
index 98eb2bf54e..e3f8da966c 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java
@@ -431,6 +431,14 @@ Rectangle getBoundsInPixels (int index) {
}
int width = GTK.gtk_tree_view_column_get_visible (column) ? rect.width + 1 : 0;
Rectangle r = new Rectangle (rect.x, rect.y, width, rect.height + 1);
+ /*
+ * On GTK4 the header is included in the entire widget's surface, so we must subtract
+ * its size from the y-coordinate. This does not apply on GTK3 as the header and
+ * "main-widget" have separate GdkWindows.
+ */
+ if (parent != null && parent.getHeaderVisible() && GTK.GTK4) {
+ r.y += parent.getHeaderHeight();
+ }
return r;
}
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 d4aa240e0c..080570b8a4 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
@@ -1668,6 +1668,14 @@ TreeItem getItemInPixels (Point point) {
GTK.gtk_widget_realize (handle);
int x = point.x;
int y = point.y;
+ /*
+ * On GTK4 the header is included in the entire widget's surface, so we must subtract
+ * its size from the y-coordinate. This does not apply on GTK3 as the header and
+ * "main-widget" have separate GdkWindows.
+ */
+ if (getHeaderVisible() && GTK.GTK4) {
+ y -= getHeaderHeight();
+ }
if ((style & SWT.MIRRORED) != 0) x = getClientWidth () - x;
long [] columnHandle = new long [1];
if (!GTK.gtk_tree_view_get_path_at_pos (handle, x, y, path, columnHandle, null, null)) return null;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java
index 8427b1b41d..e54631f4b8 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java
@@ -766,7 +766,16 @@ Rectangle getImageBoundsInPixels (int index) {
}
rect.width = w [0];
int width = GTK.gtk_tree_view_column_get_visible (column) ? rect.width : 0;
- return new Rectangle (rect.x, rect.y, width, rect.height + 1);
+ Rectangle r = new Rectangle (rect.x, rect.y, width, rect.height + 1);
+ /*
+ * On GTK4 the header is included in the entire widget's surface, so we must subtract
+ * its size from the y-coordinate. This does not apply on GTK3 as the header and
+ * "main-widget" have separate GdkWindows.
+ */
+ if (parent!= null && parent.getHeaderVisible () && GTK.GTK4) {
+ r.y += parent.getHeaderHeight();
+ }
+ return r;
}
/**

Back to the top