Skip to content

Commit

Permalink
Fix getWindowPointerPosition on Wayland eclipse-platform#177
Browse files Browse the repository at this point in the history
Depending on the window currently focused the
coordinates returned may be wrong (sometimes even
negative). This happens mainly with popup windows.

Fixes eclipse-platform#177
  • Loading branch information
simon-spinner committed Jan 6, 2024
1 parent 56989d6 commit a4167a2
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6203,7 +6203,28 @@ long getWindowPointerPosition(long window, int[] x, int[] y, int[] mask) {
}

long pointer = GDK.gdk_get_pointer(display);
return GDK.gdk_window_get_device_position(window, pointer, x, y, mask);
if (OS.isWayland()) {
// Read the current mask value. but not the position. The position is not reliable on Wayland because
// the origin of the coordinates returned may change depending on the currently focused window.
// For instance, if a popup window is currently focused and this method is called with a window outside
// of the popup window, the returned coordinates are in relation to the root coordinate system of the
// popup (possibly negative values). See also issue GH-177.
GDK.gdk_window_get_device_position(window, pointer, null, null, mask);
// Instead as for the current window under the cursor and translate the position manually between the windows.
var windowAtPosition = GDK.gdk_device_get_window_at_position(pointer, x, y);
if (windowAtPosition != 0 && windowAtPosition != window) {
int[] origin_x = new int[1], origin_y = new int[1];
GDK.gdk_window_get_origin(windowAtPosition, origin_x, origin_y);
x[0] += origin_x[0];
y[0] += origin_y[0];
GDK.gdk_window_get_origin(window, origin_x, origin_y);
x[0] -= origin_x[0];
y[0] -= origin_y[0];
}
return 0;
} else {
return GDK.gdk_window_get_device_position(window, pointer, x, y, mask);
}
}

/**
Expand Down

0 comments on commit a4167a2

Please sign in to comment.