[gnome-shell/wip/carlosg/tablet-dnd-on-chrome: 4/4] dnd: Prevent simultaneous DnD operations from happening



commit 7fe87e79a27d9b7bf1d97aab6ecd6aaa81f01f61
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Sep 10 17:57:34 2018 +0200

    dnd: Prevent simultaneous DnD operations from happening
    
    Besides the device grab on the drag device, also set up a captured-event
    handler to catch other devices (except the keyboard) while the DnD
    operation is ongoing. This makes DnD operations exclusive to others.
    
    Also, disallow it in less aggressive ways if maybeStartDrag() gets called
    while there is a current draggable.
    
    This might definitely be nicer (eg. having other grabbed devices emit
    leave/end events), but can't be done without major surgery to Clutter.

 js/ui/dnd.js | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
---
diff --git a/js/ui/dnd.js b/js/ui/dnd.js
index 7f9bc65ff..364697a41 100644
--- a/js/ui/dnd.js
+++ b/js/ui/dnd.js
@@ -112,6 +112,7 @@ var _Draggable = new Lang.Class({
         this._dragCancellable = true;
 
         this._eventsGrabbed = false;
+        this._capturedEventId = 0;
     },
 
     _onButtonPress(actor, event) {
@@ -157,9 +158,22 @@ var _Draggable = new Lang.Class({
 
         this._grabbedDevice = pointer;
         this._touchSequence = touchSequence;
+
+        this._capturedEventId = global.stage.connect('captured-event', (actor, event) => {
+            let device = event.get_device();
+            if (device != this._grabbedDevice &&
+                device.get_device_type() != Clutter.InputDeviceType.KEYBOARD_DEVICE)
+                return Clutter.EVENT_STOP;
+            return Clutter.EVENT_PROPAGATE;
+        });
     },
 
     _ungrabDevice() {
+        if (this._capturedEventId != 0) {
+            global.stage.disconnect(this._capturedEventId);
+            this._capturedEventId = 0;
+        }
+
         if (this._touchSequence)
             this._grabbedDevice.sequence_ungrab (this._touchSequence);
         else
@@ -218,6 +232,13 @@ var _Draggable = new Lang.Class({
     },
 
     _onEvent(actor, event) {
+        let device = event.get_device();
+
+        if (this._grabbedDevice &&
+            device != this._grabbedDevice &&
+            device.get_device_type() != Clutter.InputDeviceType.KEYBOARD_DEVICE)
+            return Clutter.EVENT_PROPAGATE;
+
         // We intercept BUTTON_RELEASE event to know that the button was released in case we
         // didn't start the drag, to drop the draggable in case the drag was in progress, and
         // to complete the drag and ensure that whatever happens to be under the pointer does
@@ -424,7 +445,8 @@ var _Draggable = new Lang.Class({
 
         // See if the user has moved the mouse enough to trigger a drag
         let threshold = Gtk.Settings.get_default().gtk_dnd_drag_threshold;
-        if ((Math.abs(stageX - this._dragStartX) > threshold ||
+        if (!currentDraggable &&
+            (Math.abs(stageX - this._dragStartX) > threshold ||
              Math.abs(stageY - this._dragStartY) > threshold)) {
             this.startDrag(stageX, stageY, event.get_time(), this._touchSequence, event.get_device());
             this._updateDragPosition(event);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]