[gnome-shell/wip/exalm/gestures] app drawer



commit e10dbd71ea4260a0340761e656ab22b102e52d64
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Sat Jun 29 18:21:08 2019 +0500

    app drawer

 js/ui/appDisplay.js   | 139 +++++++++++++++++++++++++++-----------------------
 js/ui/swipeTracker.js |   2 -
 2 files changed, 75 insertions(+), 66 deletions(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index ea86c81b9..2375567d4 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -14,6 +14,7 @@ const PageIndicators = imports.ui.pageIndicators;
 const PopupMenu = imports.ui.popupMenu;
 const Tweener = imports.ui.tweener;
 const Search = imports.ui.search;
+const SwipeTracker = imports.ui.swipeTracker;
 const Params = imports.misc.params;
 const Util = imports.misc.util;
 const SystemActions = imports.misc.systemActions;
@@ -258,7 +259,9 @@ var AllView = class AllView extends BaseAppView {
             (indicators, pageIndex) => {
                 this.goToPage(pageIndex);
             });
-        this._pageIndicators.connect('scroll-event', this._onScroll.bind(this));
+        this._pageIndicators.connect('scroll-event', (actor, event) => {
+            return this._scrollView.event (event, false);
+        });
         this.actor.add_actor(this._pageIndicators);
 
         this.folderIcons = [];
@@ -276,13 +279,14 @@ var AllView = class AllView extends BaseAppView {
 
         this._scrollView.connect('scroll-event', this._onScroll.bind(this));
 
-        let panAction = new Clutter.PanAction({ interpolate: false });
-        panAction.connect('pan', this._onPan.bind(this));
-        panAction.connect('gesture-cancel', this._onPanEnd.bind(this));
-        panAction.connect('gesture-end', this._onPanEnd.bind(this));
-        this._panAction = panAction;
-        this._scrollView.add_action(panAction);
-        this._panning = false;
+        let allowedModes = Shell.ActionMode.OVERVIEW;
+        let swipeTracker = new SwipeTracker.SwipeTracker(this._scrollView, allowedModes);
+        swipeTracker.connect('begin', this._swipeBegin.bind(this));
+        swipeTracker.connect('update', this._swipeUpdate.bind(this));
+        swipeTracker.connect('end', this._swipeEnd.bind(this));
+        swipeTracker.connect('cancel', this._swipeCancel.bind(this));
+
+        this._gestureActive = false;
         this._clickAction = new Clutter.ClickAction();
         this._clickAction.connect('clicked', () => {
             if (!this._currentPopup)
@@ -322,6 +326,7 @@ var AllView = class AllView extends BaseAppView {
                     global.stage.disconnect(this._keyPressEventId);
                 this._keyPressEventId = 0;
             }
+            swipeTracker.enabled = this.actor.mapped;
         });
 
         this._redisplayWorkId = Main.initializeDeferredWork(this.actor, this._redisplay.bind(this));
@@ -466,43 +471,16 @@ var AllView = class AllView extends BaseAppView {
         if (this._displayingPopup && this._currentPopup)
             this._currentPopup.popdown();
 
-        let velocity;
-        if (!this._panning)
-            velocity = 0;
-        else
-            velocity = Math.abs(this._panAction.get_velocity(0)[2]);
-        // Tween the change between pages.
-        // If velocity is not specified (i.e. scrolling with mouse wheel),
-        // use the same speed regardless of original position
-        // if velocity is specified, it's in pixels per milliseconds
-        let diffToPage = this._diffToPage(pageNumber);
-        let childBox = this._scrollView.get_allocation_box();
-        let totalHeight = childBox.y2 - childBox.y1;
-        let time;
-        // Only take the velocity into account on page changes, otherwise
-        // return smoothly to the current page using the default velocity
-        if (this._grid.currentPage != pageNumber) {
-            let minVelocity = totalHeight / (PAGE_SWITCH_TIME * 1000);
-            velocity = Math.max(minVelocity, velocity);
-            time = (diffToPage / velocity) / 1000;
-        } else {
-            time = PAGE_SWITCH_TIME * diffToPage / totalHeight;
-        }
-        // When changing more than one page, make sure to not take
-        // longer than PAGE_SWITCH_TIME
-        time = Math.min(time, PAGE_SWITCH_TIME);
-
         this._grid.currentPage = pageNumber;
-        Tweener.addTween(this._adjustment,
-                         { value: this._grid.getPageY(this._grid.currentPage),
-                           time: time,
-                           transition: 'easeOutQuad' });
-        this._pageIndicators.setCurrentPage(pageNumber);
-    }
 
-    _diffToPage(pageNumber) {
-        let currentScrollPosition = this._adjustment.value;
-        return Math.abs(currentScrollPosition - this._grid.getPageY(pageNumber));
+        if (!this._gestureActive)
+            // Tween the change between pages.
+            Tweener.addTween(this._adjustment,
+                             { value: this._grid.getPageY(this._grid.currentPage),
+                               time: PAGE_SWITCH_TIME,
+                               transition: 'easeOutCubic' });
+
+        this._pageIndicators.setCurrentPage(pageNumber);
     }
 
     openSpaceForPopup(item, side, nRows) {
@@ -525,6 +503,9 @@ var AllView = class AllView extends BaseAppView {
         if (this._displayingPopup || !this._scrollView.reactive)
             return Clutter.EVENT_STOP;
 
+        if (event.get_scroll_source() == Clutter.ScrollSource.FINGER || 
event.get_source_device().get_device_type() == Clutter.InputDeviceType.TOUCHPAD_DEVICE) // TODO: remove this 
and handle it in SwipeTracker too
+            return Clutter.EVENT_PROPAGATE;
+
         let direction = event.get_scroll_direction();
         if (direction == Clutter.ScrollDirection.UP)
             this.goToPage(this._grid.currentPage - 1);
@@ -534,34 +515,64 @@ var AllView = class AllView extends BaseAppView {
         return Clutter.EVENT_STOP;
     }
 
-    _onPan(action) {
-        if (this._displayingPopup)
-            return false;
-        this._panning = true;
-        this._clickAction.release();
-        let [dist, dx, dy] = action.get_motion_delta(0);
-        let adjustment = this._adjustment;
-        adjustment.value -= (dy / this._scrollView.height) * adjustment.page_size;
-        return false;
-    }
+    _swipeBegin(tracker) {
+        if (this._gestureActive) {
+            let adjustment = this._adjustment;
+            Tweener.removeTweens(adjustment);
 
-    _onPanEnd(action) {
-         if (this._displayingPopup)
+            let progress = this._adjustment.value / adjustment.page_size - this._grid.currentPage;
+            tracker.continueFrom(progress);
             return;
+        }
 
-        let pageHeight = this._grid.getPageHeight();
+        let canSwipeForward = this._grid.currentPage > 0;
+        let canSwipeBack = this._grid.currentPage < this._grid.nPages() - 1;
+        tracker.startSwipe(canSwipeBack, canSwipeForward, this._scrollView.height, 0, 0);
 
-        // Calculate the scroll value we'd be at, which is our current
-        // scroll plus any velocity the user had when they released
-        // their finger.
+        this._gestureActive = true;
+    }
 
-        let velocity = -action.get_velocity(0)[2];
-        let endPanValue = this._adjustment.value + velocity;
+    _swipeUpdate(tracker, progress) {
+        let adjustment = this._adjustment;
+        adjustment.value = (this._grid.currentPage + progress) * adjustment.page_size;
+    }
+
+    _swipeEnd(tracker, duration, isBack) {
+        let adjustment = this._adjustment;
+        let page = this._grid.currentPage + (isBack ? 1 : -1);
+        let value = page * adjustment.page_size;
+
+        Tweener.addTween(adjustment,
+                         { value: value,
+                           time: duration,
+                           transition: 'easeOutCubic',
+                           onComplete: () => {
+                               this.goToPage(page);
+                               this._gestureActive = false;
+                           },
+                           onCompleteScope: this
+                         });
+    }
+
+    _swipeCancel(tracker, duration) {
+        let adjustment = this._adjustment;
+        let value = this._grid.currentPage * adjustment.page_size;
 
-        let closestPage = Math.round(endPanValue / pageHeight);
-        this.goToPage(closestPage);
+        if (duration == 0) {
+            adjustment.value = value;
+            this._gestureActive = false;
+            return;
+        }
 
-        this._panning = false;
+        Tweener.addTween(adjustment,
+                         { value: value,
+                           time: duration,
+                           transition: 'easeOutCubic',
+                           onComplete: () => {
+                               this._gestureActive = false;
+                           },
+                           onCompleteScope: this
+                         });
     }
 
     _onKeyPressEvent(actor, event) {
diff --git a/js/ui/swipeTracker.js b/js/ui/swipeTracker.js
index 8a126460a..4261635b4 100644
--- a/js/ui/swipeTracker.js
+++ b/js/ui/swipeTracker.js
@@ -367,8 +367,6 @@ var SwipeTracker = class {
         this._touchGesture.setDistance(distance);
         if (this._dragGesture)
             this._dragGesture.setDistance(distance);
-
-        log("start", canSwipeBack, canSwipeForward, distance, backExtent, forwardExtent);
     }
 
     continueFrom(progress) {


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