[gnome-shell/wip/gestures: 1/8] Add edgeDrag Clutter.GestureAction



commit ff3f0cac8ab7bb16040c24940f638cd981de458d
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Jun 25 17:47:36 2014 +0200

    Add edgeDrag Clutter.GestureAction
    
    This action is only triggered if started from the monitor edge specified
    on construction.

 js/js-resources.gresource.xml |    1 +
 js/ui/edgeDrag.js             |   53 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 0 deletions(-)
---
diff --git a/js/js-resources.gresource.xml b/js/js-resources.gresource.xml
index 47bdd00..92950af 100644
--- a/js/js-resources.gresource.xml
+++ b/js/js-resources.gresource.xml
@@ -39,6 +39,7 @@
     <file>ui/dash.js</file>
     <file>ui/dateMenu.js</file>
     <file>ui/dnd.js</file>
+    <file>ui/edgeDrag.js</file>
     <file>ui/endSessionDialog.js</file>
     <file>ui/environment.js</file>
     <file>ui/extensionDownloader.js</file>
diff --git a/js/ui/edgeDrag.js b/js/ui/edgeDrag.js
new file mode 100644
index 0000000..fadf265
--- /dev/null
+++ b/js/ui/edgeDrag.js
@@ -0,0 +1,53 @@
+// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
+
+const Lang = imports.lang;
+const Meta = imports.gi.Meta;
+const Clutter = imports.gi.Clutter;
+const St = imports.gi.St;
+
+let EDGE_THRESHOLD = 20;
+
+const EdgeDragAction = new Lang.Class({
+    Name: 'EdgeDragAction',
+    Extends: Clutter.GestureAction,
+
+    _init : function(side) {
+        this.parent();
+       this._side = side;
+       this.set_n_touch_points (1);
+
+       this.connect('gesture-progress', Lang.bind (this, this._gestureProgress));
+    },
+
+    vfunc_gesture_prepare : function(action, actor) {
+       let [x, y] = this.get_press_coords(0);
+        let rect = new Meta.Rectangle({ x: x - 1, y: y - 1, width: 1, height: 1 });
+        let monitorIndex = global.screen.get_monitor_index_for_rect(rect);
+       let monitorRect = global.screen.get_monitor_geometry(monitorIndex);
+
+       return ((this._side == St.Side.LEFT && x < monitorRect.x + EDGE_THRESHOLD) ||
+               (this._side == St.Side.RIGHT && x > monitorRect.x + monitorRect.width - EDGE_THRESHOLD) ||
+               (this._side == St.Side.TOP && y < monitorRect.y + EDGE_THRESHOLD) ||
+               (this._side == St.Side.BOTTOM && y > monitorRect.y + monitorRect.height - EDGE_THRESHOLD));
+    },
+
+    _gestureProgress : function (action, actor) {
+       let [startX, startY] = this.get_press_coords(0);
+       let [x, y] = this.get_motion_coords(0);
+       let offsetX = Math.abs (x - startX);
+       let offsetY = Math.abs (y - startY);
+
+       if (offsetX < EDGE_THRESHOLD && offsetY < EDGE_THRESHOLD)
+           return true;
+
+       if ((offsetX > offsetY &&
+            (this._side == St.Side.TOP || this._side == St.Side.BOTTOM)) ||
+           (offsetY > offsetX &&
+            (this._side == St.Side.LEFT || this._side == St.Side.RIGHT))) {
+           this.cancel();
+           return false;
+       }
+
+       return true;
+    },
+});


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