[gnome-shell/wip/exalm/gestures: 7/21] d



commit a56bc250529dae214f57664e932603c360751889
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Sun Jun 23 17:21:21 2019 +0500

    d

 js/ui/swipeTracker.js  | 37 ++++++++++++++------
 js/ui/windowManager.js | 94 ++++++++++++++++++++++++++++++++++++++------------
 2 files changed, 98 insertions(+), 33 deletions(-)
---
diff --git a/js/ui/swipeTracker.js b/js/ui/swipeTracker.js
index 078065cc3..ab8f395e2 100644
--- a/js/ui/swipeTracker.js
+++ b/js/ui/swipeTracker.js
@@ -14,6 +14,7 @@ const MAX_ANIMATION_DURATION = 0.4;
 const CANCEL_AREA = 0.5;
 const VELOCITY_THRESHOLD = 0.001;
 const DURATION_MULTIPLIER = 3;
+const ANIMATION_BASE_VELOCITY = 0.002;
 
 /*var Direction = {
     NEGATIVE: -1,
@@ -30,6 +31,10 @@ function clamp(value, min, max) {
     return Math.max(min, Math.min(max, value));
 }
 
+// TODO: support scrolling
+// TODO: support touch
+// TODO: support horizontal
+
 var SwipeTracker = class {
     constructor(actor, allowedModes) {
         this.actor = actor;
@@ -93,7 +98,7 @@ var SwipeTracker = class {
     }
 
     _cancel() {
-        this.emit('end', true, 0);
+        this.emit('cancel', 0);
         this._reset();
     }
 
@@ -118,9 +123,11 @@ var SwipeTracker = class {
 
         if (event.get_gesture_phase() == Clutter.TouchpadGesturePhase.UPDATE) {
 //        if ((event.get_scroll_finish_flags() & Clutter.ScrollFinishFlags.VERTICAL == 0) || (dx == 0 && dy 
== 0))
-            if(!(this._touchpadSettings.get_boolean('natural-scroll')))
+            if(!(this._touchpadSettings.get_boolean('natural-scroll'))) {
+                dx = -dx;
                 dy = -dy;
-            this._updateGesture(time, -dy / TOUCHPAD_BASE_DISTANCE * SCROLL_MULTIPLIER); // TODO: multiply 
on actor diman
+            }
+            this._updateGesture(time, -dy / TOUCHPAD_BASE_DISTANCE * SCROLL_MULTIPLIER); // TODO: multiply 
on actor dimen for touch
         } else if (event.get_gesture_phase() == Clutter.TouchpadGesturePhase.END)
             this._endGesture(time);
         else if (event.get_gesture_phase() == Clutter.TouchpadGesturePhase.CANCEL)
@@ -188,15 +195,25 @@ var SwipeTracker = class {
         if (!cancelled)
             endProgress = (this._progress > 0) ? 1 : -1;
 
-        let duration = MAX_ANIMATION_DURATION;
-        if ((endProgress - this._progress) * this._velocity > 0) {
-            duration = Math.abs((this._progress - endProgress) / this._velocity * DURATION_MULTIPLIER) / 
1000;
-            if (duration != 0)
-                duration = clamp(duration, MIN_ANIMATION_DURATION, MAX_ANIMATION_DURATION);
-        }
+        let velocity = ANIMATION_BASE_VELOCITY;
+        if ((endProgress - this._progress) * this._velocity > 0)
+            velocity = this._velocity;
 
-        this.emit('end', cancelled, duration);
+        let duration = Math.abs((this._progress - endProgress) / velocity * DURATION_MULTIPLIER) / 1000;
+        duration = clamp(duration, MIN_ANIMATION_DURATION, MAX_ANIMATION_DURATION);
+
+        if (cancelled)
+            this.emit('cancel', duration);
+        else
+            this.emit('end', duration, this._progress > 0);
         this._reset();
     }
+
+    continueFrom(progress) {
+        this._progress = progress;
+        this._velocity = 0;
+        this._state = State.SCROLLING;
+    }
+
 };
 Signals.addSignalMethods(SwipeTracker.prototype);
diff --git a/js/ui/windowManager.js b/js/ui/windowManager.js
index 79a8ee03b..95a0148b8 100644
--- a/js/ui/windowManager.js
+++ b/js/ui/windowManager.js
@@ -1078,6 +1078,7 @@ var WindowManager = class {
         gesture.connect('begin', this._switchWorkspaceBegin.bind(this));
         gesture.connect('update', this._switchWorkspaceUpdate.bind(this));
         gesture.connect('end', this._switchWorkspaceEnd.bind(this));
+        gesture.connect('cancel', this._switchWorkspaceCancel.bind(this));
         this._swipeTracker = gesture;
 
         gesture = new AppSwitchAction();
@@ -1123,8 +1124,23 @@ var WindowManager = class {
         let workspaceManager = global.workspace_manager;
         let activeWorkspace = workspaceManager.get_active_workspace();
 
-        if (!this._switchData)
-            this._prepareWorkspaceSwitch(activeWorkspace.index(), -1);
+        if (this._switchData && this._switchData.gestureActivated) {
+            let currWs = global.workspace_manager.get_active_workspace();
+            let topWs = activeWorkspace.get_neighbor(Meta.MotionDirection.UP);
+            let bottomWs = activeWorkspace.get_neighbor(Meta.MotionDirection.DOWN);
+            let [xDestTop, yDestTop] = this._getPositionForDirection(direction, currWs, topWs);
+            let [xDestBottom, yDestBottom] = this._getPositionForDirection(direction, currWs, bottomWs);
+
+//            xDestTop = -xDestTop;
+            yDestTop = -yDestTop;
+//            xDestBottom = -xDestBottom;
+            yDestBottom = -yDestBottom;
+
+            this._swipeTracker.continueFrom(0);
+            return;
+        }
+
+        this._prepareWorkspaceSwitch(activeWorkspace.index(), -1);
 
         // TODO: horizontal
         this._swipeTracker.can_swipe_forward = this._switchData.surroundings[Meta.MotionDirection.UP];
@@ -1138,25 +1154,72 @@ var WindowManager = class {
         this._switchData.container.set_position(0, -progress * 1080);
     }
 
-    _switchWorkspaceEnd(tracker, cancelled, duration) {
+    _switchWorkspaceEnd(tracker, duration, isBack) {
         if (!this._switchData)
             return;
 
-        if (cancelled)
-            this._switchWorkspaceCancel();
-        let direction = Meta.MotionDirection.DOWN;
+        let direction = isBack ? Meta.MotionDirection.DOWN : Meta.MotionDirection.UP;
 
         let workspaceManager = global.workspace_manager;
         let activeWorkspace = workspaceManager.get_active_workspace();
         let newWs = activeWorkspace.get_neighbor(direction);
 
         if (newWs == activeWorkspace) {
-            this._switchWorkspaceCancel();
+            // FIXME: throw an error
+            log('this should never happen')
         } else {
             this._switchData.gestureActivated = true;
-            this.actionMoveWorkspace(newWs);
+            this._switchWorkspaceAnimate(direction, duration, newWs);
         }
     }
+
+    _switchWorkspaceCancel(tracker, duration) {
+        if (!this._switchData || this._switchData.inProgress)
+            return;
+
+        let switchData = this._switchData;
+        this._switchData = null;
+        Tweener.addTween(switchData.container,
+                         { x: 0,
+                           y: 0,
+                           time: duration,
+                           transition: 'easeOutQuad',
+                           onComplete: this._finishWorkspaceSwitch,
+                           onCompleteScope: this,
+                           onCompleteParams: [switchData],
+                         });
+    }
+
+    _switchWorkspaceAnimate(direction, duration, newWs) {
+        let switchData = this._switchData;
+        this._switchData = null;
+
+        let oldWs = global.workspace_manager.get_active_workspace();
+        let [xDest, yDest] = this._getPositionForDirection(direction, oldWs, newWs);
+
+        xDest = -xDest;
+        yDest = -yDest;
+
+        Tweener.addTween(switchData.container,
+                         { x: xDest,
+                           y: yDest,
+                           time: duration,
+                           transition: 'easeOutQuad',
+                           onComplete: this._switchAndFinishWorkspaceSwitch,
+                           onCompleteScope: this,
+                           onCompleteParams: [newWs, switchData],
+                         });
+    }
+
+    _switchAndFinishWorkspaceSwitch(newWs, switchData) {
+        // We've already animated the transition, don't animate it again
+        this._blockAnimations = true;
+        this.actionMoveWorkspace(newWs);
+        this._blockAnimations = false;
+
+        this._finishWorkspaceSwitch(switchData);
+    }
+
 /*
     _switchWorkspaceMotion(action, xRel, yRel) {
         let workspaceManager = global.workspace_manager;
@@ -1177,21 +1240,6 @@ var WindowManager = class {
         this._switchData.container.set_position(xRel, yRel);
     }
 */
-    _switchWorkspaceCancel() {
-        if (!this._switchData || this._switchData.inProgress)
-            return;
-        let switchData = this._switchData;
-        this._switchData = null;
-        Tweener.addTween(switchData.container,
-                         { x: 0,
-                           y: 0,
-                           time: WINDOW_ANIMATION_TIME,
-                           transition: 'easeOutQuad',
-                           onComplete: this._finishWorkspaceSwitch,
-                           onCompleteScope: this,
-                           onCompleteParams: [switchData],
-                         });
-    }
 /*
     _actionSwitchWorkspace(action, direction) {
         let workspaceManager = global.workspace_manager;


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