Skip to content

[GTK4] Cleanup GtkEventControllerMotion Enter/Leave events #2008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4.c
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,18 @@ JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1named_1action_1new)
}
#endif

#ifndef NO_gtk_1native_1get_1for_1surface
JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1native_1get_1for_1surface)
(JNIEnv *env, jclass that, jlong arg0)
{
jlong rc = 0;
GTK4_NATIVE_ENTER(env, that, gtk_1native_1get_1for_1surface_FUNC);
rc = (jlong)gtk_native_get_for_surface((GdkSurface *)arg0);
GTK4_NATIVE_EXIT(env, that, gtk_1native_1get_1for_1surface_FUNC);
return rc;
}
#endif

#ifndef NO_gtk_1native_1get_1surface
JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1native_1get_1surface)
(JNIEnv *env, jclass that, jlong arg0)
Expand Down Expand Up @@ -2178,6 +2190,18 @@ JNIEXPORT void JNICALL GTK4_NATIVE(gtk_1widget_1measure)
}
#endif

#ifndef NO_gtk_1widget_1pick
JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1widget_1pick)
(JNIEnv *env, jclass that, jlong arg0, jdouble arg1, jdouble arg2, jint arg3)
{
jlong rc = 0;
GTK4_NATIVE_ENTER(env, that, gtk_1widget_1pick_FUNC);
rc = (jlong)gtk_widget_pick((GtkWidget *)arg0, (double)arg1, (double)arg2, (GtkPickFlags)arg3);
GTK4_NATIVE_EXIT(env, that, gtk_1widget_1pick_FUNC);
return rc;
}
#endif

#ifndef NO_gtk_1widget_1set_1cursor
JNIEXPORT void JNICALL GTK4_NATIVE(gtk_1widget_1set_1cursor)
(JNIEnv *env, jclass that, jlong arg0, jlong arg1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ typedef enum {
gtk_1label_1set_1wrap_1mode_FUNC,
gtk_1menu_1button_1set_1use_1underline_FUNC,
gtk_1named_1action_1new_FUNC,
gtk_1native_1get_1for_1surface_FUNC,
gtk_1native_1get_1surface_FUNC,
gtk_1picture_1new_FUNC,
gtk_1picture_1set_1can_1shrink_FUNC,
Expand Down Expand Up @@ -180,6 +181,7 @@ typedef enum {
gtk_1widget_1insert_1after_FUNC,
gtk_1widget_1insert_1before_FUNC,
gtk_1widget_1measure_FUNC,
gtk_1widget_1pick_FUNC,
gtk_1widget_1set_1cursor_FUNC,
gtk_1widget_1set_1focusable_FUNC,
gtk_1widget_1size_1allocate_FUNC,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public class GTK4 {
public static final int GTK_EVENT_SEQUENCE_CLAIMED = 1;
public static final int GTK_EVENT_SEQUENCE_DENIED = 2;

public static final int GTK_PICK_DEFAULT = 0;
public static final int GTK_PICK_INSENSITIVE = 1;
public static final int GTK_PICK_NON_TARGETABLE = 2;

/**
* @param context cast=(GtkIMContext *)
* @param event cast=(GdkEvent *)
Expand Down Expand Up @@ -130,6 +134,10 @@ public class GTK4 {
/* GTK Initialization */
public static final native boolean gtk_init_check();

/* GtkNative */
/** @param surface cast=(GdkSurface *) */
public static final native long gtk_native_get_for_surface(long surface);

/* GdkToplevel */
/** @param toplevel cast=(GdkToplevel *) */
public static final native int gdk_toplevel_get_state(long toplevel);
Expand Down Expand Up @@ -667,6 +675,13 @@ public class GTK4 {
* @param next_sibling cast=(GtkWidget *)
*/
public static final native void gtk_widget_insert_before(long widget, long parent, long next_sibling);
/**
* @param widget cast=(GtkWidget *)
* @param x cast=(double)
* @param y cast=(double)
* @param flags cast=(GtkPickFlags)
*/
public static final native long gtk_widget_pick(long widget, double x, double y, int flags);

/* GtkComboBox */
/** @param combo_box cast=(GtkComboBox *) */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3622,7 +3622,7 @@ void gtk4_enter_event(long controller, double x, double y, long event) {
char [] chars = fixMnemonic (toolTipText, false, true);
buffer = Converter.wcsToMbcs (chars, true);
}
long toolHandle = getShell().handle;
long toolHandle = handle;
GTK.gtk_widget_set_tooltip_text (toolHandle, buffer);

if (display.currentControl == this) return;
Expand Down Expand Up @@ -4044,6 +4044,7 @@ void gtk4_leave_event(long controller, long event) {

if (sendLeaveNotify() || display.getCursorControl() == null) {
sendMouseEvent(SWT.MouseExit, 0, 0, 0, 0, false, 0);
display.currentControl = null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1900,46 +1900,48 @@ public Control getCursorControl () {
gdkResource = gdk_device_get_surface_at_position (xDouble, yDouble);
x[0] = (int) xDouble[0];
y[0] = (int) yDouble[0];
if (gdkResource != 0) {
long gtkWindow = GTK4.gtk_native_get_for_surface(gdkResource);
if (gtkWindow != 0) {
handle = GTK4.gtk_widget_pick(gtkWindow, xDouble[0], yDouble[0], GTK4.GTK_PICK_DEFAULT);
}
}
} else {
gdkResource = gdk_device_get_window_at_position (x,y);
}
if (gdkResource != 0) {
if (GTK.GTK4) {
// TODO: GTK4 need to retrieve handle
} else {
if (gdkResource != 0) {
GDK.gdk_window_get_user_data (gdkResource, user_data);
}
handle = user_data [0];
} else {
// Feature in GTK. The gdk_device_get_[surface/window]_at_position() functions will not return a
// surface/window if the pointer is over a foreign embedded window. The fix is to use XQueryPointer
// to find the containing GDK window (see bug 177368.)
// However embedding foreign windows is not supported by the Wayland backend for GTK3 and is not
// supported at all on GTK4, so skip the heuristic in these situations.
if (OS.isWayland() || GTK.GTK4) return null;
long gdkDisplay = GDK.gdk_display_get_default();
if (OS.isX11()) {
GDK.gdk_x11_display_error_trap_push(gdkDisplay);
}
int[] unusedInt = new int[1];
long [] unusedPtr = new long [1], buffer = new long [1];
long xWindow, xParent = OS.XDefaultRootWindow (xDisplay);
do {
if (OS.XQueryPointer (xDisplay, xParent, unusedPtr, buffer, unusedInt, unusedInt, unusedInt, unusedInt, unusedInt) == 0) {
handle = 0;
break;
handle = user_data [0];
} else {
// Feature in GTK. The gdk_device_get_[surface/window]_at_position() functions will not return a
// surface/window if the pointer is over a foreign embedded window. The fix is to use XQueryPointer
// to find the containing GDK window (see bug 177368.)
// However embedding foreign windows is not supported by the Wayland backend for GTK3 and is not
// supported at all on GTK4, so skip the heuristic in these situations.
if (OS.isWayland() || GTK.GTK4) return null;
long gdkDisplay = GDK.gdk_display_get_default();
if (OS.isX11()) {
GDK.gdk_x11_display_error_trap_push(gdkDisplay);
}
if ((xWindow = buffer [0]) != 0) {
xParent = xWindow;
long gdkWindow = GDK.gdk_x11_window_lookup_for_display(gdkDisplay, xWindow);
if (gdkWindow != 0) {
GDK.gdk_window_get_user_data (gdkWindow, user_data);
if (user_data[0] != 0) handle = user_data[0];
int[] unusedInt = new int[1];
long [] unusedPtr = new long [1], buffer = new long [1];
long xWindow, xParent = OS.XDefaultRootWindow (xDisplay);
do {
if (OS.XQueryPointer (xDisplay, xParent, unusedPtr, buffer, unusedInt, unusedInt, unusedInt, unusedInt, unusedInt) == 0) {
handle = 0;
break;
}
if ((xWindow = buffer [0]) != 0) {
xParent = xWindow;
long gdkWindow = GDK.gdk_x11_window_lookup_for_display(gdkDisplay, xWindow);
if (gdkWindow != 0) {
GDK.gdk_window_get_user_data (gdkWindow, user_data);
if (user_data[0] != 0) handle = user_data[0];
}
}
} while (xWindow != 0);
if (OS.isX11()) {
GDK.gdk_x11_display_error_trap_pop_ignored(gdkDisplay);
}
} while (xWindow != 0);
if (OS.isX11()) {
GDK.gdk_x11_display_error_trap_pop_ignored(gdkDisplay);
}
}
if (handle == 0) return null;
Expand Down
Loading