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



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

    mainWindow: WIP: Add gesture to open sidebar

 src/mainWindow.js |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)
---
diff --git a/src/mainWindow.js b/src/mainWindow.js
index ff76b8d..52c8f6a 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,
@@ -126,6 +128,7 @@ var MainWindow = new Lang.Class({
         this._initSignals();
         this._restoreWindowGeometry();
         this._initDND();
+        this._initGestures();
 
         this._busySignalId = 0;
 
@@ -134,6 +137,35 @@ var MainWindow = new Lang.Class({
         this._grid.show_all();
     },
 
+    _initGestures: function() {
+        this._swipeGesture =
+            new Gtk.GestureSwipe({ widget: this.mapView, 'touch-only': true });
+        this._panGesture = new Gtk.GesturePan({ widget: this.mapView,
+                                                'touch-only': true,
+                                                orientation: Gtk.Orientation.HORIZONTAL });
+        // restrict to horizontal swiping by grouping with a horizontal pan
+        this._swipeGesture.group(this._panGesture);
+        this._swipeGesture.connect('swipe', this._onSwipe.bind(this));
+        this._swipeGesture.connect('begin', this._onSwipeBegin.bind(this));
+    },
+
+    _onSwipeBegin: 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);
+    },
+
+    _onSwipe: function(gesture, velocityX, velocityY) {
+        Utils.debug('swipe: ' + velocityX + ', ' + velocityY);
+        if (this._recognizeEdgeSwipe)
+            this._setRevealSidebar(true);
+    },
+
     _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]