[gnome-shell/wip/exalm/gestures: 1/6] drag



commit 66111005b914f10a0e9e6ace96ae2e1f0a5bc360
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Thu Jun 27 20:51:18 2019 +0500

    drag

 js/ui/swipeTracker.js       | 44 ++++++++++++++----------
 js/ui/workspaceThumbnail.js |  1 -
 js/ui/workspacesView.js     | 83 +++++++--------------------------------------
 3 files changed, 39 insertions(+), 89 deletions(-)
---
diff --git a/js/ui/swipeTracker.js b/js/ui/swipeTracker.js
index 45cffeb42..eae8e052b 100644
--- a/js/ui/swipeTracker.js
+++ b/js/ui/swipeTracker.js
@@ -26,15 +26,14 @@ function clamp(value, min, max) {
 }
 
 // TODO: support scrolling
-// TODO: support dragging
 // TODO: support horizontal
 
 var TouchpadSwipeGesture = class TouchpadSwipeGesture {
-    constructor(actor, shouldSkip) {
+    constructor(shouldSkip) {
+        this._shouldSkip = shouldSkip;
         this._touchpadSettings = new Gio.Settings({schema_id: 'org.gnome.desktop.peripherals.touchpad'});
 
-        actor.connect('captured-event', this._handleEvent.bind(this));
-        this._shouldSkip = shouldSkip;
+        global.stage.connect('captured-event', this._handleEvent.bind(this));
     }
 
     _handleEvent(actor, event) {
@@ -69,10 +68,11 @@ var TouchSwipeGesture = GObject.registerClass({
     Signals: { 'update': { param_types: [GObject.TYPE_UINT, GObject.TYPE_DOUBLE] },
                'end':    { param_types: [GObject.TYPE_UINT] },
                'cancel': { param_types: [GObject.TYPE_UINT] }},
-}, class TouchSwipeGesture extends Clutter.GestureAction {
-    _init(actor, shouldSkip) {
+}, class TouchSwipeGesture extends Clutter.TriggerAction {
+    _init(actor, shouldSkip, n_touch_points, trigger_edge = Clutter.TriggerEdge.NONE) {
         super._init();
-        this.set_n_touch_points(4);
+        this.set_n_touch_points(n_touch_points);
+        this.set_trigger_edge(trigger_edge);
 
         this._actor = actor;
         this._shouldSkip = shouldSkip;
@@ -153,16 +153,22 @@ var SwipeTracker = class {
         let shouldSkip = () =>
             ((this._allowedModes & Main.actionMode) == 0 || !this._enabled);
 
-        let gesture = new TouchpadSwipeGesture(actor, shouldSkip);
-        gesture.connect('update', this._updateGesture.bind(this));
-        gesture.connect('end', this._endGesture.bind(this));
-//        gesture.connect('cancel', this._cancelGesture.bind(this)); // End the gesture normally for 
touchpads
-
-        gesture = new TouchSwipeGesture(actor, shouldSkip);
-        gesture.connect('update', this._updateGesture.bind(this));
-        gesture.connect('end', this._endGesture.bind(this));
-        gesture.connect('cancel', this._cancelGesture.bind(this));
-        actor.add_action(gesture);
+        let touchpadGesture = new TouchpadSwipeGesture(shouldSkip);
+        touchpadGesture.connect('update', this._updateGesture.bind(this));
+        touchpadGesture.connect('end', this._endGesture.bind(this));
+//        touchpadGesture.connect('cancel', this._cancelGesture.bind(this)); // End the gesture normally for 
touchpads
+
+        let touchGesture = new TouchSwipeGesture(actor, shouldSkip, 4, Clutter.TriggerEdge.NONE);
+        touchGesture.connect('update', this._updateGesture.bind(this));
+        touchGesture.connect('end', this._endGesture.bind(this));
+        touchGesture.connect('cancel', this._cancelGesture.bind(this));
+        global.stage.add_action(touchGesture);
+
+        let dragGesture = new TouchSwipeGesture(actor, shouldSkip, 1, Clutter.TriggerEdge.AFTER);
+        dragGesture.connect('update', this._updateGesture.bind(this));
+        dragGesture.connect('end', this._endGesture.bind(this));
+        dragGesture.connect('cancel', this._cancelGesture.bind(this));
+        actor.add_action(dragGesture);
     }
 
     get enabled() {
@@ -271,8 +277,10 @@ var SwipeTracker = class {
     }
 
     _endGesture(gesture, time) {
-        if ((this._allowedModes & Main.actionMode) == 0 || !this._enabled)
+        if ((this._allowedModes & Main.actionMode) == 0 || !this._enabled) {
+//            this._cancel();
             return;
+        }
 
         if (this._state != State.SCROLLING)
             return;
diff --git a/js/ui/workspaceThumbnail.js b/js/ui/workspaceThumbnail.js
index ceb61fcbf..b747da25d 100644
--- a/js/ui/workspaceThumbnail.js
+++ b/js/ui/workspaceThumbnail.js
@@ -1357,7 +1357,6 @@ class ThumbnailsBox extends St.Widget {
                            transition: 'easeOutCubic',
                            onComplete() {
                                this._animatingIndicator = false;
-                               this._queue_relayout();
                                this._queueUpdateStates();
                            },
                            onCompleteScope: this
diff --git a/js/ui/workspacesView.js b/js/ui/workspacesView.js
index 9f249a62c..54f583dcd 100644
--- a/js/ui/workspacesView.js
+++ b/js/ui/workspacesView.js
@@ -82,7 +82,6 @@ var WorkspacesView = class extends WorkspacesViewBase {
         super(monitorIndex);
 
         this._animating = false; // tweening
-        this._scrolling = false; // swipe-scrolling
         this._gestureActive = false; // touch(pad) gestures
         this._animatingScroll = false; // programmatically updating the adjustment
 
@@ -213,7 +212,7 @@ var WorkspacesView = class extends WorkspacesViewBase {
 
         for (let w = 0; w < this._workspaces.length; w++) {
             let workspace = this._workspaces[w];
-            if (this._animating || this._scrolling || this._gestureActive) {
+            if (this._animating || this._gestureActive) {
                 workspace.actor.show();
             } else {
                 if (this._inDrag)
@@ -225,7 +224,7 @@ var WorkspacesView = class extends WorkspacesViewBase {
     }
 
     _updateScrollAdjustment(index) {
-        if (this._scrolling || this._gestureActive)
+        if (this._gestureActive)
             return;
 
         this._animatingScroll = true;
@@ -274,7 +273,7 @@ var WorkspacesView = class extends WorkspacesViewBase {
     }
 
     _activeWorkspaceChanged(wm, from, to, direction) {
-        if (this._scrolling)
+        if (this._gestureActive)
             return;
 
         this._scrollToActive();
@@ -290,23 +289,12 @@ var WorkspacesView = class extends WorkspacesViewBase {
         workspaceManager.disconnect(this._updateWorkspacesId);
     }
 
-    startSwipeScroll() {
-        this._scrolling = true;
-    }
-
-    endSwipeScroll() {
-        this._scrolling = false;
-
-        // Make sure title captions etc are shown as necessary
-        this._scrollToActive();
-        this._updateVisibility();
-    }
-
     startTouchGesture() {
         this._gestureActive = true;
     }
 
     endTouchGesture() {
+        // Make sure title captions etc are shown as necessary
         this._scrollToActive(false);
         this._updateVisibility();
 
@@ -399,12 +387,6 @@ var ExtraWorkspaceView = class extends WorkspacesViewBase {
         this._workspace.syncStacking(stackIndices);
     }
 
-    startSwipeScroll() {
-    }
-
-    endSwipeScroll() {
-    }
-
     startTouchGesture() {
     }
 
@@ -428,8 +410,8 @@ var WorkspacesDisplay = class {
         this.actor.connect('notify::allocation', this._updateWorkspacesActualGeometry.bind(this));
         this.actor.connect('parent-set', this._parentSet.bind(this));
 
-        let clickAction = new Clutter.ClickAction();
-        clickAction.connect('clicked', action => {
+        this._clickAction = new Clutter.ClickAction();
+        this._clickAction.connect('clicked', action => {
             // Only switch to the workspace when there's no application
             // windows open. The problem is that it's too easy to miss
             // an app window and get the wrong one focused.
@@ -439,34 +421,11 @@ var WorkspacesDisplay = class {
                 this._workspacesViews[index].getActiveWorkspace().isEmpty())
                 Main.overview.hide();
         });
-        Main.overview.addAction(clickAction);
-        this.actor.bind_property('mapped', clickAction, 'enabled', GObject.BindingFlags.SYNC_CREATE);
-
-        let panAction = new Clutter.PanAction({ trigger_edge: Clutter.TriggerEdge.AFTER });
-        panAction.connect('pan', this._onPan.bind(this));
-        panAction.connect('gesture-begin', () => {
-            if (this._workspacesOnlyOnPrimary) {
-                let event = Clutter.get_current_event();
-                if (this._getMonitorIndexForEvent(event) != this._primaryIndex)
-                    return false;
-            }
-
-            this._startSwipeScroll();
-            return true;
-        });
-        panAction.connect('gesture-cancel', () => {
-            clickAction.release();
-            this._endSwipeScroll();
-        });
-        panAction.connect('gesture-end', () => {
-            clickAction.release();
-            this._endSwipeScroll();
-        });
-        Main.overview.addAction(panAction);
-        this.actor.bind_property('mapped', panAction, 'enabled', GObject.BindingFlags.SYNC_CREATE);
+        Main.overview.addAction(this._clickAction);
+        this.actor.bind_property('mapped', this._clickAction, 'enabled', GObject.BindingFlags.SYNC_CREATE);
 
         let allowedModes = Shell.ActionMode.OVERVIEW;
-        let swipeTracker = new SwipeTracker.SwipeTracker(global.stage, allowedModes); // TODO: somehow teach 
it to work with addAction() too
+        let swipeTracker = new SwipeTracker.SwipeTracker(Main.overview._backgroundGroup, allowedModes); // 
TODO: somehow teach it to work with addAction() too
         swipeTracker.connect('begin', this._switchWorkspaceBegin.bind(this));
         swipeTracker.connect('update', this._switchWorkspaceUpdate.bind(this));
         swipeTracker.connect('end', this._switchWorkspaceEnd.bind(this));
@@ -495,26 +454,6 @@ var WorkspacesDisplay = class {
         this._gestureActive = false;
     }
 
-    _onPan(action) {
-        let [dist, dx, dy] = action.get_motion_delta(0);
-        let adjustment = this._scrollAdjustment;
-        adjustment.value -= (dy / this.actor.height) * adjustment.page_size;
-        return false;
-    }
-
-    _startSwipeScroll() {
-        for (let i = 0; i < this._workspacesViews.length; i++)
-            this._workspacesViews[i].startSwipeScroll();
-        this._gestureActive = true;
-    }
-
-    _endSwipeScroll() {
-        for (let i = 0; i < this._workspacesViews.length; i++)
-            this._workspacesViews[i].endSwipeScroll();
-        this._gestureActive = false;
-        this._thumbnailsBox.resetIndicatorProgress();
-    }
-
     _switchWorkspaceBegin(tracker) {
         if (this._gestureActive) {
             let workspaceManager = global.workspace_manager;
@@ -548,6 +487,8 @@ var WorkspacesDisplay = class {
     }
 
     _switchWorkspaceEnd(tracker, duration, isBack) {
+        this._clickAction.release();
+
         let direction = isBack ? Meta.MotionDirection.DOWN : Meta.MotionDirection.UP;
 
         let workspaceManager = global.workspace_manager;
@@ -571,6 +512,8 @@ var WorkspacesDisplay = class {
     }
 
     _switchWorkspaceCancel(tracker, duration) {
+        this._clickAction.release();
+
         if (duration == 0) {
             this._endTouchGesture();
             return;


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