Skip to content

Commit d6b9c7a

Browse files
author
Jose Pereda
committed
8292922: [Linux] No more drag events when new Stage is created in drag handler
Backport-of: a35c3bf
1 parent efbbfcf commit d6b9c7a

File tree

2 files changed

+13
-91
lines changed

2 files changed

+13
-91
lines changed

modules/javafx.graphics/src/main/native-glass/gtk/glass_general.cpp

+3-79
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,6 @@ gboolean disableGrab = FALSE;
514514
static gboolean configure_transparent_window(GtkWidget *window);
515515
static void configure_opaque_window(GtkWidget *window);
516516

517-
static void grab_mouse_device(GdkDevice *device, DeviceGrabContext *context);
518-
static void ungrab_mouse_device(GdkDevice *device);
519-
520517
gint glass_gdk_visual_get_depth (GdkVisual * visual)
521518
{
522519
// gdk_visual_get_depth is GTK 2.2 +
@@ -535,35 +532,15 @@ GdkScreen * glass_gdk_window_get_screen(GdkWindow * gdkWindow)
535532

536533
gboolean
537534
glass_gdk_mouse_devices_grab(GdkWindow *gdkWindow) {
538-
#ifdef GLASS_GTK3_DISABLED
539-
//this GTK 3 approach has synchronization issues covered in JDK-8176844
540-
// As the approach is also deprecated in GTK 3.20+, revert back to using GTK 2 mechanism
541-
542-
if (disableGrab) {
543-
return TRUE;
544-
}
545-
DeviceGrabContext context;
546-
GList *devices = gdk_device_manager_list_devices (
547-
gdk_display_get_device_manager(
548-
gdk_display_get_default()),
549-
GDK_DEVICE_TYPE_MASTER);
550-
551-
context.window = gdkWindow;
552-
context.grabbed = FALSE;
553-
g_list_foreach(devices, (GFunc) grab_mouse_device, &context);
554-
g_list_free(devices);
555-
556-
return context.grabbed;
557-
#else
558535
return glass_gdk_mouse_devices_grab_with_cursor(gdkWindow, NULL, TRUE);
559-
#endif
560536
}
561537

562538
gboolean
563539
glass_gdk_mouse_devices_grab_with_cursor(GdkWindow *gdkWindow, GdkCursor *cursor, gboolean owner_events) {
564540
if (disableGrab) {
565541
return TRUE;
566542
}
543+
567544
GdkGrabStatus status = gdk_pointer_grab(gdkWindow, owner_events, (GdkEventMask)
568545
(GDK_POINTER_MOTION_MASK
569546
| GDK_POINTER_MOTION_HINT_MASK
@@ -580,18 +557,7 @@ glass_gdk_mouse_devices_grab_with_cursor(GdkWindow *gdkWindow, GdkCursor *cursor
580557

581558
void
582559
glass_gdk_mouse_devices_ungrab() {
583-
#ifdef GLASS_GTK3_DISABLED
584-
//this GTK 3 approach has synchronization issues covered in JDK-8176844
585-
// As the approach is also deprecated in GTK 3.20+, revert back to using GTK 2 mechanism
586-
GList *devices = gdk_device_manager_list_devices(
587-
gdk_display_get_device_manager(
588-
gdk_display_get_default()),
589-
GDK_DEVICE_TYPE_MASTER);
590-
g_list_foreach(devices, (GFunc) ungrab_mouse_device, NULL);
591-
g_list_free(devices);
592-
#else
593-
gdk_pointer_ungrab(GDK_CURRENT_TIME);
594-
#endif
560+
gdk_pointer_ungrab(GDK_CURRENT_TIME);
595561
}
596562

597563
void
@@ -625,6 +591,7 @@ glass_gdk_device_ungrab(GdkDevice *device) {
625591
#endif
626592
}
627593

594+
628595
GdkWindow *
629596
glass_gdk_device_get_window_at_position(GdkDevice *device, gint *x, gint *y) {
630597
#ifdef GLASS_GTK3
@@ -733,49 +700,6 @@ glass_configure_window_transparency(GtkWidget *window, gboolean transparent) {
733700
return FALSE;
734701
}
735702

736-
static void
737-
grab_mouse_device(GdkDevice *device, DeviceGrabContext *context) {
738-
GdkInputSource source = gdk_device_get_source(device);
739-
if (source == GDK_SOURCE_MOUSE) {
740-
#ifdef GLASS_GTK3
741-
GdkGrabStatus status = gdk_device_grab(device,
742-
context->window,
743-
GDK_OWNERSHIP_NONE,
744-
TRUE,
745-
GDK_FILTERED_EVENTS_MASK,
746-
NULL,
747-
GDK_CURRENT_TIME);
748-
#else
749-
GdkGrabStatus status = GDK_GRAB_SUCCESS;
750-
/* FIXME reachable by 2?
751-
GdkGrabStatus status = gdk_device_grab(device,
752-
context->window,
753-
GDK_OWNERSHIP_NONE,
754-
TRUE,
755-
GDK_FILTERED_EVENTS_MASK,
756-
NULL,
757-
GDK_CURRENT_TIME);
758-
*/
759-
#endif
760-
if (status == GDK_GRAB_SUCCESS) {
761-
context->grabbed = TRUE;
762-
}
763-
}
764-
}
765-
766-
static void
767-
ungrab_mouse_device(GdkDevice *device) {
768-
#ifdef GLASS_GTK3
769-
GdkInputSource source = gdk_device_get_source(device);
770-
if (source == GDK_SOURCE_MOUSE) {
771-
gdk_device_ungrab(device, GDK_CURRENT_TIME);
772-
}
773-
#else
774-
(void) device;
775-
// not used on the GTK2 path
776-
#endif
777-
}
778-
779703
GdkPixbuf *
780704
glass_pixbuf_from_window(GdkWindow *window,
781705
gint srcx, gint srcy,

modules/javafx.graphics/src/main/native-glass/gtk/glass_window.cpp

+10-12
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,6 @@ void WindowContextBase::process_state(GdkEventWindowState* event) {
133133
}
134134

135135
void WindowContextBase::process_focus(GdkEventFocus* event) {
136-
if (!event->in && WindowContextBase::sm_mouse_drag_window == this) {
137-
ungrab_mouse_drag_focus();
138-
}
139136
if (!event->in && WindowContextBase::sm_grab_window == this) {
140137
ungrab_focus();
141138
}
@@ -303,15 +300,8 @@ void WindowContextBase::process_mouse_button(GdkEventButton* event) {
303300
}
304301
}
305302

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

348+
if (isDrag && WindowContextBase::sm_mouse_drag_window == NULL) {
349+
// Upper layers expects from us Windows behavior:
350+
// all mouse events should be delivered to window where drag begins
351+
// and no exit/enter event should be reported during this drag.
352+
// We can grab mouse pointer for these needs.
353+
grab_mouse_drag_focus();
354+
}
355+
358356
if (glass_modifier & com_sun_glass_events_KeyEvent_MODIFIER_BUTTON_PRIMARY) {
359357
button = com_sun_glass_events_MouseEvent_BUTTON_LEFT;
360358
} else if (glass_modifier & com_sun_glass_events_KeyEvent_MODIFIER_BUTTON_MIDDLE) {

0 commit comments

Comments
 (0)