[gnome-shell/wip/exalm/long-swipes: 3/4] swipeTracker: Add allowLongSwipes property




commit 0b53d91b416d0938e800c646b547e584ed6c914d
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Mon Feb 8 01:02:58 2021 +0500

    swipeTracker: Add allowLongSwipes property
    
    Since we now have the ability to support swiping through multiple pages,
    expose it as a property.

 js/ui/swipeTracker.js | 37 ++++++++++++++++++++++++++++++++-----
 1 file changed, 32 insertions(+), 5 deletions(-)
---
diff --git a/js/ui/swipeTracker.js b/js/ui/swipeTracker.js
index cce137315b..44f16a700f 100644
--- a/js/ui/swipeTracker.js
+++ b/js/ui/swipeTracker.js
@@ -388,6 +388,10 @@ var SwipeTracker = GObject.registerClass({
             'distance', 'distance', 'distance',
             GObject.ParamFlags.READWRITE,
             0, Infinity, 0),
+        'allow-long-swipes': GObject.ParamSpec.boolean(
+            'allow-long-swipes', 'allow-long-swipes', 'allow-long-swipes',
+            GObject.ParamFlags.READWRITE,
+            false),
         'scroll-modifiers': GObject.ParamSpec.flags(
             'scroll-modifiers', 'scroll-modifiers', 'scroll-modifiers',
             GObject.ParamFlags.READWRITE,
@@ -405,6 +409,7 @@ var SwipeTracker = GObject.registerClass({
 
         this._allowedModes = allowedModes;
         this._enabled = true;
+        this._allowLongSwipes = false;
         this._distance = global.screen_height;
         this._history = new EventHistory();
         this._reset();
@@ -498,6 +503,18 @@ var SwipeTracker = GObject.registerClass({
         this.notify('distance');
     }
 
+    get allowLongSwipes() {
+        return this._allowLongSwipes;
+    }
+
+    set allowLongSwipes(allowLongSwipes) {
+        if (this._allowLongSwipes === allowLongSwipes)
+            return;
+
+        this._allowLongSwipes = allowLongSwipes;
+        this.notify('allow-long-swipes');
+    }
+
     _reset() {
         this._state = State.NONE;
 
@@ -596,8 +613,15 @@ var SwipeTracker = GObject.registerClass({
         this._progress += delta / distance;
         this._history.append(time, delta);
 
-        let [lower, upper] = this._getBounds(this._initialProgress);
-        this._progress = Math.clamp(this._progress, lower, upper);
+        if (this._allowLongSwipes) {
+            let firstPoint = this._snapPoints[0];
+            let lastPoint = this._snapPoints[this._snapPoints.length - 1];
+
+            this._progress = Math.clamp(this._progress, firstPoint, lastPoint);
+        } else {
+            let [lower, upper] = this._getBounds(this._initialProgress);
+            this._progress = Math.clamp(this._progress, lower, upper);
+        }
 
         this.emit('update', this._progress);
     }
@@ -626,10 +650,13 @@ var SwipeTracker = GObject.registerClass({
             pos = Math.abs(velocity) * slope;
         }
 
-        const [lower, upper] = this._getBounds(this._initialProgress);
-
         pos = pos * Math.sign(velocity) + this._progress;
-        pos = Math.clamp(pos, lower, upper);
+
+        if (!this._allowLongSwipes) {
+            const [lower, upper] = this._getBounds(this._initialProgress);
+
+            pos = Math.clamp(pos, lower, upper);
+        }
 
         return this._snapPoints[this._findPointForProjection(pos, velocity)];
     }


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