Bug 519808 - [GTK] Shell.getBounds returns obsolete values
Function gtk_window_get_position is unreliable due to specifics of WMs.
Use gdk_window_get_root_origin to get position in root window
coordinates.
Note: This will stay broken on Wayland as there are no root coordinates
on Wayland
Change-Id: Ie55ac57a60bae14fee2f9e13662e36cc9b4112aa
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c
index ec3558d..15faa90 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c
@@ -6372,6 +6372,23 @@
}
#endif
+#ifndef NO__1gdk_1window_1get_1root_1origin
+JNIEXPORT void JNICALL OS_NATIVE(_1gdk_1window_1get_1root_1origin)
+ (JNIEnv *env, jclass that, jintLong arg0, jintArray arg1, jintArray arg2)
+{
+ jint *lparg1=NULL;
+ jint *lparg2=NULL;
+ OS_NATIVE_ENTER(env, that, _1gdk_1window_1get_1root_1origin_FUNC);
+ if (arg1) if ((lparg1 = (*env)->GetIntArrayElements(env, arg1, NULL)) == NULL) goto fail;
+ if (arg2) if ((lparg2 = (*env)->GetIntArrayElements(env, arg2, NULL)) == NULL) goto fail;
+ gdk_window_get_root_origin((GdkWindow *)arg0, (gint *)lparg1, (gint *)lparg2);
+fail:
+ if (arg2 && lparg2) (*env)->ReleaseIntArrayElements(env, arg2, lparg2, 0);
+ if (arg1 && lparg1) (*env)->ReleaseIntArrayElements(env, arg1, lparg1, 0);
+ OS_NATIVE_EXIT(env, that, _1gdk_1window_1get_1root_1origin_FUNC);
+}
+#endif
+
#ifndef NO__1gdk_1window_1get_1user_1data
JNIEXPORT void JNICALL OS_NATIVE(_1gdk_1window_1get_1user_1data)
(JNIEnv *env, jclass that, jintLong arg0, jintLongArray arg1)
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c
index adc4328..0aa3d8a 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c
@@ -534,6 +534,7 @@
"_1gdk_1window_1get_1parent",
"_1gdk_1window_1get_1pointer",
"_1gdk_1window_1get_1position",
+ "_1gdk_1window_1get_1root_1origin",
"_1gdk_1window_1get_1user_1data",
"_1gdk_1window_1get_1visible_1region",
"_1gdk_1window_1get_1width",
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h
index c7ce376..8e4a2a8 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h
@@ -544,6 +544,7 @@
_1gdk_1window_1get_1parent_FUNC,
_1gdk_1window_1get_1pointer_FUNC,
_1gdk_1window_1get_1position_FUNC,
+ _1gdk_1window_1get_1root_1origin_FUNC,
_1gdk_1window_1get_1user_1data_FUNC,
_1gdk_1window_1get_1visible_1region_FUNC,
_1gdk_1window_1get_1width_FUNC,
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java
index bda14df..6fa9bed 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java
@@ -5353,6 +5353,20 @@
}
/**
* @param window cast=(GdkWindow *)
+ * @param x cast=(gint *)
+ * @param y cast=(gint *)
+ */
+public static final native void _gdk_window_get_root_origin(long /*int*/ window, int[] x, int[] y);
+public static final void gdk_window_get_root_origin(long /*int*/ window, int[] x, int[] y) {
+ lock.lock();
+ try {
+ _gdk_window_get_root_origin(window, x, y);
+ } finally {
+ lock.unlock();
+ }
+}
+/**
+ * @param window cast=(GdkWindow *)
* @param data cast=(gpointer *)
*/
public static final native void _gdk_window_get_user_data(long /*int*/ window, long /*int*/[] data);
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 f7288d3..5f51873 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
@@ -2730,7 +2730,7 @@
Rectangle getBoundsInPixels () {
checkWidget ();
int [] x = new int [1], y = new int [1];
- OS.gtk_window_get_position (shellHandle, x, y);
+ OS.gdk_window_get_root_origin(OS.gtk_widget_get_window(shellHandle), x, y);
GtkAllocation allocation = new GtkAllocation ();
OS.gtk_widget_get_allocation (vboxHandle, allocation);
int width = allocation.width;