[gnome-maps/wip/mlundblad/touch-gestures: 8/8] mainWindow: WIP: Add gestures to open and close sidebar



commit 836ab889b8fcd996e166f55cc80ca6a3e2afece3
Author: Marcus Lundblad <ml update uu se>
Date:   Sat Oct 21 13:28:34 2017 +0200

    mainWindow: WIP: Add gestures to open and close sidebar

 src/mainWindow.js |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)
---
diff --git a/src/mainWindow.js b/src/mainWindow.js
index f9b80d5..915e54d 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -48,6 +48,8 @@ const _CONFIGURE_ID_TIMEOUT = 100; // msecs
 const _WINDOW_MIN_WIDTH = 600;
 const _WINDOW_MIN_HEIGHT = 500;
 
+const SWIPE_EDGE_THREASHHOLD = 20;
+
 var ShapeLayerFileChooser = new Lang.Class({
     Name: 'ShapeLayerFileChooser',
     Extends: Gtk.FileChooserNative,
@@ -128,6 +130,7 @@ var MainWindow = new Lang.Class({
         this._initSignals();
         this._restoreWindowGeometry();
         this._initDND();
+        this._initGestures();
 
         this._busySignalId = 0;
 
@@ -136,6 +139,49 @@ var MainWindow = new Lang.Class({
         this._grid.show_all();
     },
 
+    _initGestures: function() {
+        this._swipeInGesture =
+            new Gtk.GestureSwipe({ widget: this.mapView, 'touch-only': true });
+        this._panInGesture = new Gtk.GesturePan({ widget: this.mapView,
+                                                'touch-only': true,
+                                                orientation: Gtk.Orientation.HORIZONTAL });
+        this._swipeOutGesture =
+            new Gtk.GestureSwipe({ widget: this._sidebar, 'touch-only': true });
+        this._panOutGesture = new Gtk.GesturePan({ widget: this._sidebar,
+                                                   'touch-only': true,
+                                                   orientation: Gtk.Orientation.HORIZONTAL });
+
+        // restrict to horizontal swiping by grouping with a horizontal pan
+        this._swipeInGesture.group(this._panInGesture);
+        this._swipeInGesture.connect('swipe', this._onSwipeIn.bind(this));
+        this._swipeInGesture.connect('begin', this._onSwipeInBegin.bind(this));
+        this._swipeOutGesture.connect('swipe', this._onSwipeOut.bind(this));
+    },
+
+    _onSwipeInBegin: function(gesture, sequence) {
+        let rtl = Gtk.get_locale_direction() === Gtk.TextDirection.RTL;
+        Utils.debug('swipe begin');
+        let [_, x, y] = gesture.get_point(sequence);
+        Utils.debug('point: ' + x + ',' + y);
+        this._recognizeEdgeSwipe = rtl ?
+                                   x < SWIPE_EDGE_THREASHHOLD :
+                                   x > this.mapView.get_allocated_width() - SWIPE_EDGE_THREASHHOLD;
+        Utils.debug('recognized: ' + this._recognizeEdgeSwipe);
+    },
+
+    _onSwipeIn: function(gesture, velocityX, velocityY) {
+        Utils.debug('swipe: ' + velocityX + ', ' + velocityY);
+        if (this._recognizeEdgeSwipe)
+            this._setRevealSidebar(true);
+    },
+
+    _onSwipeOut: function(gesture, velocityX, velocityY) {
+        let rtl = Gtk.get_locale_direction() === Gtk.TextDirection.RTL;
+
+        if ((rtl && velocityX < 0) || (!rtl && velocityX > 0))
+            this._setRevealSidebar(false);
+    },
+
     _createPlaceEntry: function() {
         let placeEntry = new PlaceEntry.PlaceEntry({ mapView: this._mapView,
                                                      visible: true,


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