[gnome-shell/wip/garnacho/touchpad-gestures: 2/2] windowManager: Add TouchpadWorkspaceSwitchAction



commit 2f1b3d53214d954aba9ac76a69a5c68f398cc2cc
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Jul 1 15:53:24 2015 +0200

    windowManager: Add TouchpadWorkspaceSwitchAction
    
    This object (not really a Clutter.GestureAction) sets up a captured-event
    handler, which exclusively looks for 4 finger touchpad swipes, emitting
    an ::activated signal under the same terms than WorkspaceSwitchAction.

 js/ui/windowManager.js |   62 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 62 insertions(+), 0 deletions(-)
---
diff --git a/js/ui/windowManager.js b/js/ui/windowManager.js
index b020bf7..abb4f99 100644
--- a/js/ui/windowManager.js
+++ b/js/ui/windowManager.js
@@ -478,6 +478,64 @@ const TilePreview = new Lang.Class({
     }
 });
 
+const TouchpadWorkspaceSwitchAction = new Lang.Class({
+    Name: 'TouchpadWorkspaceSwitchAction',
+
+    _checkActivated: function() {
+        const MOTION_THRESHOLD = 50;
+        let allowedModes = Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW;
+        let dir;
+
+        if ((allowedModes & Main.actionMode) == 0)
+            return;
+
+        if (this._dy < MOTION_THRESHOLD)
+            dir = Meta.MotionDirection.DOWN;
+        else if (this._dy > MOTION_THRESHOLD)
+            dir = Meta.MotionDirection.UP;
+        else if (this._dx < MOTION_THRESHOLD)
+            dir = Meta.MotionDirection.RIGHT;
+        else if (this._dx > MOTION_THRESHOLD)
+            dir = Meta.MotionDirection.LEFT;
+        else
+            return;
+
+        this.emit('activated', dir);
+    },
+
+    _handleEvent: function(actor, event) {
+        if (event.type() != Clutter.EventType.TOUCHPAD_SWIPE_BEGIN &&
+            event.type() != Clutter.EventType.TOUCHPAD_SWIPE_UPDATE &&
+            event.type() != Clutter.EventType.TOUCHPAD_SWIPE_END)
+            return Clutter.EVENT_PROPAGATE;
+
+        if (event.get_gesture_swipe_finger_count() != 4)
+            return Clutter.EVENT_PROPAGATE;
+
+        if (event.type() == Clutter.EventType.TOUCHPAD_SWIPE_UPDATE) {
+            let [dx, dy] = event.get_gesture_motion_delta(event);
+
+            this._dx += dx;
+            this._dy += dy;
+        } else {
+            if (event.type() == Clutter.EventType.TOUCHPAD_SWIPE_END)
+                this._checkActivated();
+
+            this._dx = 0;
+            this._dy = 0;
+        }
+
+        return Clutter.EVENT_STOP;
+    },
+
+    _init: function(actor) {
+        this._dx = 0;
+        this._dy = 0;
+        actor.connect('captured-event', Lang.bind(this, this._handleEvent));
+    },
+});
+Signals.addSignalMethods(TouchpadWorkspaceSwitchAction.prototype);
+
 const WorkspaceSwitchAction = new Lang.Class({
     Name: 'WorkspaceSwitchAction',
     Extends: Clutter.SwipeAction,
@@ -875,6 +933,10 @@ const WindowManager = new Lang.Class({
         gesture.connect('activated', Lang.bind(this, this._actionSwitchWorkspace));
         global.stage.add_action(gesture);
 
+        // This is not a normal Clutter.GestureAction, doesn't need add_action()
+        gesture = new TouchpadWorkspaceSwitchAction(global.stage);
+        gesture.connect('activated', Lang.bind(this, this._actionSwitchWorkspace));
+
         gesture = new AppSwitchAction();
         gesture.connect('activated', Lang.bind(this, this._switchApp));
         global.stage.add_action(gesture);


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