[gnome-shell/wip/gestures: 5/8] Add showOverViewAction Clutter.GestureAction



commit 975e73b0a4d4e9caa2aef5d793bd759cfa96e9f0
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Jun 25 18:10:12 2014 +0200

    Add showOverViewAction Clutter.GestureAction
    
    This gesture implements 3-finger pinch, that will be used to show
    the overview.

 js/js-resources.gresource.xml |    1 +
 js/ui/showOverviewAction.js   |   70 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+), 0 deletions(-)
---
diff --git a/js/js-resources.gresource.xml b/js/js-resources.gresource.xml
index 92950af..d959ce1 100644
--- a/js/js-resources.gresource.xml
+++ b/js/js-resources.gresource.xml
@@ -78,6 +78,7 @@
     <file>ui/shellDBus.js</file>
     <file>ui/shellEntry.js</file>
     <file>ui/shellMountOperation.js</file>
+    <file>ui/showOverviewAction.js</file>
     <file>ui/slider.js</file>
     <file>ui/switcherPopup.js</file>
     <file>ui/tweener.js</file>
diff --git a/js/ui/showOverviewAction.js b/js/ui/showOverviewAction.js
new file mode 100644
index 0000000..c1a8b37
--- /dev/null
+++ b/js/ui/showOverviewAction.js
@@ -0,0 +1,70 @@
+// -*- 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 ShowOverviewAction = new Lang.Class({
+    Name: 'ShowOverviewAction',
+    Extends: Clutter.GestureAction,
+
+    _init : function() {
+        this.parent();
+       this.set_n_touch_points (3);
+       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();
+    },
+
+    _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 });
+    },
+
+    _gestureBegin : function(action, actor) {
+       this._initialRect = this._getBoundingRect(false);
+       this._areaDiff = null;
+       return true;
+    },
+
+    _gestureEnd : function(action, actor) {
+       let rect = this._getBoundingRect(true);
+       let oldArea = this._initialRect.width * this._initialRect.height;
+       let newArea = rect.width * rect.height;
+
+       this._areaDiff = newArea / oldArea;
+    },
+
+    getAreaDiff : function() {
+       return this._areaDiff;
+    }
+});


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