[gnome-shell/wip/gestures-2: 3/5] viewSelector: Show the overview on 3-finger pinch gestures



commit 932b8951279dd134f759b6be1c2a2dc80f761663
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Jun 25 18:12:04 2014 +0200

    viewSelector: Show the overview on 3-finger pinch gestures

 js/ui/viewSelector.js |   73 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 72 insertions(+), 1 deletions(-)
---
diff --git a/js/ui/viewSelector.js b/js/ui/viewSelector.js
index f80ee31..918cd87 100644
--- a/js/ui/viewSelector.js
+++ b/js/ui/viewSelector.js
@@ -120,6 +120,68 @@ const EdgeDragAction = new Lang.Class({
 });
 Signals.addSignalMethods(EdgeDragAction.prototype);
 
+const ShowOverviewAction = new Lang.Class({
+    Name: 'ShowOverviewAction',
+    Extends: Clutter.GestureAction,
+
+    _init : function() {
+        this.parent();
+        this.set_n_touch_points(3);
+
+        global.display.connect('grab-op-begin', Lang.bind(this, function() {
+            this.cancel();
+        }));
+    },
+
+    vfunc_gesture_prepare : function(action, actor) {
+        return this.get_n_current_points() == this.get_n_touch_points();
+    },
+
+    _getBoundingRect : function(motion) {
+        let minX, minY, maxX, maxY;
+
+        for (let i = 0; i < this.get_n_current_points(); i++) {
+            let x, y;
+
+            if (motion == true) {
+                [x, y] = this.get_motion_coords(i);
+            } else {
+                [x, y] = this.get_press_coords(i);
+            }
+
+            if (i == 0) {
+                minX = maxX = x;
+                minY = maxY = y;
+            } else {
+                minX = Math.min(minX, x);
+                minY = Math.min(minY, y);
+                maxX = Math.max(maxX, x);
+                maxY = Math.max(maxY, y);
+            }
+        }
+
+        return new Meta.Rectangle({ x: minX,
+                                    y: minY,
+                                    width: maxX - minX,
+                                    height: maxY - minY });
+    },
+
+    vfunc_gesture_begin : function(action, actor) {
+        this._initialRect = this._getBoundingRect(false);
+        return true;
+    },
+
+    vfunc_gesture_end : function(action, actor) {
+        let rect = this._getBoundingRect(true);
+        let oldArea = this._initialRect.width * this._initialRect.height;
+        let newArea = rect.width * rect.height;
+        let areaDiff = newArea / oldArea;
+
+        this.emit('activated', areaDiff);
+    }
+});
+Signals.addSignalMethods(ShowOverviewAction.prototype);
+
 const ViewSelector = new Lang.Class({
     Name: 'ViewSelector',
 
@@ -216,7 +278,9 @@ const ViewSelector = new Lang.Class({
                               Shell.KeyBindingMode.OVERVIEW,
                               Lang.bind(Main.overview, Main.overview.toggle));
 
-        let gesture = new EdgeDragAction(St.Side.RIGHT);
+        let gesture;
+
+        gesture = new EdgeDragAction(St.Side.RIGHT);
         gesture.connect('activated', Lang.bind(this, function() {
             if (Main.overview.visible)
                 Main.overview.hide();
@@ -224,6 +288,13 @@ const ViewSelector = new Lang.Class({
                 this.showApps();
         }));
         global.stage.add_action(gesture);
+
+        gesture = new ShowOverviewAction();
+        gesture.connect('activated', Lang.bind(this, function(action, areaDiff) {
+            if (areaDiff < 0.7)
+                Main.overview.show();
+        }));
+        global.stage.add_action(gesture);
     },
 
     _toggleAppsPage: function() {


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