[gnome-shell/wip/gestures: 7/8] Add workspaceSwitchAction Clutter.GestureAction



commit 998443faaead52c77be8e47b03116d9a254588da
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Jun 25 18:12:41 2014 +0200

    Add workspaceSwitchAction Clutter.GestureAction
    
    This gesture implements 4-finger drag, that will be used for workspace
    switching.

 js/js-resources.gresource.xml  |    1 +
 js/ui/workspaceSwitchAction.js |   52 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+), 0 deletions(-)
---
diff --git a/js/js-resources.gresource.xml b/js/js-resources.gresource.xml
index d959ce1..5e93924 100644
--- a/js/js-resources.gresource.xml
+++ b/js/js-resources.gresource.xml
@@ -89,6 +89,7 @@
     <file>ui/windowMenu.js</file>
     <file>ui/windowManager.js</file>
     <file>ui/workspace.js</file>
+    <file>ui/workspaceSwitchAction.js</file>
     <file>ui/workspaceSwitcherPopup.js</file>
     <file>ui/workspaceThumbnail.js</file>
     <file>ui/workspacesView.js</file>
diff --git a/js/ui/workspaceSwitchAction.js b/js/ui/workspaceSwitchAction.js
new file mode 100644
index 0000000..1fe1535
--- /dev/null
+++ b/js/ui/workspaceSwitchAction.js
@@ -0,0 +1,52 @@
+// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
+
+const Signals = imports.signals;
+const Lang = imports.lang;
+const Meta = imports.gi.Meta;
+const Clutter = imports.gi.Clutter;
+const St = imports.gi.St;
+
+const WorkspaceSwitchAction = new Lang.Class({
+    Name: 'WorkspaceSwitchAction',
+    Extends: Clutter.GestureAction,
+
+    _init : function() {
+        this.parent();
+       this.set_n_touch_points (4);
+       this.connect('gesture-begin', Lang.bind (this, this._gestureBegin));
+       this.connect('gesture-end', Lang.bind (this, this._gestureEnd));
+    },
+
+    vfunc_gesture_prepare : function(action, actor) {
+        return this.get_n_current_points() == this.get_n_touch_points();
+    },
+
+    _gestureBegin : function(action, actor) {
+       this._direction = null;
+       return true;
+    },
+
+    _gestureEnd : function(action, actor) {
+       // Just check one touchpoint here
+       let [startX, startY] = this.get_press_coords(0);
+       let [x, y] = this.get_motion_coords(0);
+       let offsetX = x - startX;
+       let offsetY = y - startY;
+
+       if (Math.abs(offsetY) > Math.abs(offsetX)) {
+           if (offsetY > 0)
+               this._direction = Meta.MotionDirection.UP;
+           else
+               this._direction = Meta.MotionDirection.DOWN;
+       } else {
+           if (offsetX > 0)
+               this._direction = Meta.MotionDirection.LEFT;
+           else
+               this._direction = Meta.MotionDirection.RIGHT;
+       }
+    },
+
+    getDirection : function() {
+       return this._direction;
+    }
+});


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