[gnome-maps/wip/mlundblad/touch-gestures] mainWindow: WIP: Add gestures to open and close sidebar
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/mlundblad/touch-gestures] mainWindow: WIP: Add gestures to open and close sidebar
- Date: Mon, 30 Oct 2017 21:45:08 +0000 (UTC)
commit 483e6d8b1b2c7e0d764dad05601646a250166aa3
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 ff76b8d..3161c0f 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,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]