Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8292922: [Linux] No more drag events when new Stage is created in dra…
…g handler

Reviewed-by: angorya, kcr
  • Loading branch information
Thiago Milczarek Sayao committed Dec 23, 2022
1 parent 48f6f5b commit a35c3bf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 91 deletions.
Expand Up @@ -514,9 +514,6 @@ gboolean disableGrab = FALSE;
static gboolean configure_transparent_window(GtkWidget *window);
static void configure_opaque_window(GtkWidget *window);

static void grab_mouse_device(GdkDevice *device, DeviceGrabContext *context);
static void ungrab_mouse_device(GdkDevice *device);

gint glass_gdk_visual_get_depth (GdkVisual * visual)
{
// gdk_visual_get_depth is GTK 2.2 +
Expand All @@ -535,35 +532,15 @@ GdkScreen * glass_gdk_window_get_screen(GdkWindow * gdkWindow)

gboolean
glass_gdk_mouse_devices_grab(GdkWindow *gdkWindow) {
#ifdef GLASS_GTK3_DISABLED
//this GTK 3 approach has synchronization issues covered in JDK-8176844
// As the approach is also deprecated in GTK 3.20+, revert back to using GTK 2 mechanism

if (disableGrab) {
return TRUE;
}
DeviceGrabContext context;
GList *devices = gdk_device_manager_list_devices (
gdk_display_get_device_manager(
gdk_display_get_default()),
GDK_DEVICE_TYPE_MASTER);

context.window = gdkWindow;
context.grabbed = FALSE;
g_list_foreach(devices, (GFunc) grab_mouse_device, &context);
g_list_free(devices);

return context.grabbed;
#else
return glass_gdk_mouse_devices_grab_with_cursor(gdkWindow, NULL, TRUE);
#endif
}

gboolean
glass_gdk_mouse_devices_grab_with_cursor(GdkWindow *gdkWindow, GdkCursor *cursor, gboolean owner_events) {
if (disableGrab) {
return TRUE;
}

GdkGrabStatus status = gdk_pointer_grab(gdkWindow, owner_events, (GdkEventMask)
(GDK_POINTER_MOTION_MASK
| GDK_POINTER_MOTION_HINT_MASK
Expand All @@ -580,18 +557,7 @@ glass_gdk_mouse_devices_grab_with_cursor(GdkWindow *gdkWindow, GdkCursor *cursor

void
glass_gdk_mouse_devices_ungrab() {
#ifdef GLASS_GTK3_DISABLED
//this GTK 3 approach has synchronization issues covered in JDK-8176844
// As the approach is also deprecated in GTK 3.20+, revert back to using GTK 2 mechanism
GList *devices = gdk_device_manager_list_devices(
gdk_display_get_device_manager(
gdk_display_get_default()),
GDK_DEVICE_TYPE_MASTER);
g_list_foreach(devices, (GFunc) ungrab_mouse_device, NULL);
g_list_free(devices);
#else
gdk_pointer_ungrab(GDK_CURRENT_TIME);
#endif
gdk_pointer_ungrab(GDK_CURRENT_TIME);
}

void
Expand Down Expand Up @@ -625,6 +591,7 @@ glass_gdk_device_ungrab(GdkDevice *device) {
#endif
}


GdkWindow *
glass_gdk_device_get_window_at_position(GdkDevice *device, gint *x, gint *y) {
#ifdef GLASS_GTK3
Expand Down Expand Up @@ -733,49 +700,6 @@ glass_configure_window_transparency(GtkWidget *window, gboolean transparent) {
return FALSE;
}

static void
grab_mouse_device(GdkDevice *device, DeviceGrabContext *context) {
GdkInputSource source = gdk_device_get_source(device);
if (source == GDK_SOURCE_MOUSE) {
#ifdef GLASS_GTK3
GdkGrabStatus status = gdk_device_grab(device,
context->window,
GDK_OWNERSHIP_NONE,
TRUE,
GDK_FILTERED_EVENTS_MASK,
NULL,
GDK_CURRENT_TIME);
#else
GdkGrabStatus status = GDK_GRAB_SUCCESS;
/* FIXME reachable by 2?
GdkGrabStatus status = gdk_device_grab(device,
context->window,
GDK_OWNERSHIP_NONE,
TRUE,
GDK_FILTERED_EVENTS_MASK,
NULL,
GDK_CURRENT_TIME);
*/
#endif
if (status == GDK_GRAB_SUCCESS) {
context->grabbed = TRUE;
}
}
}

static void
ungrab_mouse_device(GdkDevice *device) {
#ifdef GLASS_GTK3
GdkInputSource source = gdk_device_get_source(device);
if (source == GDK_SOURCE_MOUSE) {
gdk_device_ungrab(device, GDK_CURRENT_TIME);
}
#else
(void) device;
// not used on the GTK2 path
#endif
}

GdkPixbuf *
glass_pixbuf_from_window(GdkWindow *window,
gint srcx, gint srcy,
Expand Down
22 changes: 10 additions & 12 deletions modules/javafx.graphics/src/main/native-glass/gtk/glass_window.cpp
Expand Up @@ -133,9 +133,6 @@ void WindowContextBase::process_state(GdkEventWindowState* event) {
}

void WindowContextBase::process_focus(GdkEventFocus* event) {
if (!event->in && WindowContextBase::sm_mouse_drag_window == this) {
ungrab_mouse_drag_focus();
}
if (!event->in && WindowContextBase::sm_grab_window == this) {
ungrab_focus();
}
Expand Down Expand Up @@ -303,15 +300,8 @@ void WindowContextBase::process_mouse_button(GdkEventButton* event) {
}
}

// Upper layers expects from us Windows behavior:
// all mouse events should be delivered to window where drag begins
// and no exit/enter event should be reported during this drag.
// We can grab mouse pointer for these needs.
if (press) {
grab_mouse_drag_focus();
} else {
if ((event->state & MOUSE_BUTTONS_MASK)
&& !(state & MOUSE_BUTTONS_MASK)) { // all buttons released
if (!press) {
if ((event->state & MOUSE_BUTTONS_MASK) && !(state & MOUSE_BUTTONS_MASK)) { // all buttons released
ungrab_mouse_drag_focus();
} else if (event->button == 8 || event->button == 9) {
// GDK X backend interprets button press events for buttons 4-7 as
Expand Down Expand Up @@ -355,6 +345,14 @@ void WindowContextBase::process_mouse_motion(GdkEventMotion* event) {
com_sun_glass_events_KeyEvent_MODIFIER_BUTTON_FORWARD);
jint button = com_sun_glass_events_MouseEvent_BUTTON_NONE;

if (isDrag && WindowContextBase::sm_mouse_drag_window == NULL) {
// Upper layers expects from us Windows behavior:
// all mouse events should be delivered to window where drag begins
// and no exit/enter event should be reported during this drag.
// We can grab mouse pointer for these needs.
grab_mouse_drag_focus();
}

if (glass_modifier & com_sun_glass_events_KeyEvent_MODIFIER_BUTTON_PRIMARY) {
button = com_sun_glass_events_MouseEvent_BUTTON_LEFT;
} else if (glass_modifier & com_sun_glass_events_KeyEvent_MODIFIER_BUTTON_MIDDLE) {
Expand Down

1 comment on commit a35c3bf

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.