[gnome-shell/wip/gestures-2: 2/5] viewSelector: Add left edge drag gesture to show the app picker
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/gestures-2: 2/5] viewSelector: Add left edge drag gesture to show the app picker
- Date: Tue, 8 Jul 2014 16:13:33 +0000 (UTC)
commit 9c4ffc4bf353fe9c64368f3e194e38b0e8f61311
Author: Carlos Garnacho <carlosg gnome org>
Date: Wed Jun 25 17:52:19 2014 +0200
viewSelector: Add left edge drag gesture to show the app picker
js/ui/viewSelector.js | 79 +++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 79 insertions(+), 0 deletions(-)
---
diff --git a/js/ui/viewSelector.js b/js/ui/viewSelector.js
index e7d9b1d..f80ee31 100644
--- a/js/ui/viewSelector.js
+++ b/js/ui/viewSelector.js
@@ -49,6 +49,77 @@ function getTermsForSearchString(searchString) {
return terms;
}
+const EDGE_THRESHOLD = 20;
+const DRAG_DISTANCE = 80;
+
+const EdgeDragAction = new Lang.Class({
+ Name: 'EdgeDragAction',
+ Extends: Clutter.GestureAction,
+
+ _init : function(side) {
+ this.parent();
+ this._side = side;
+ this.set_n_touch_points(1);
+
+ global.display.connect('grab-op-begin', Lang.bind(this, function() {
+ this.cancel();
+ }));
+ },
+
+ _getMonitorRect : function (x, y) {
+ 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);
+
+ return global.screen.get_monitor_geometry(monitorIndex);
+ },
+
+ vfunc_gesture_prepare : function(action, actor) {
+ if (this.get_n_current_points() == 0)
+ return false;
+
+ let [x, y] = this.get_press_coords(0);
+ let monitorRect = this._getMonitorRect(x, y);
+
+ 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));
+ },
+
+ vfunc_gesture_progress : 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;
+ },
+
+ vfunc_gesture_end : function (action, actor) {
+ let [startX, startY] = this.get_press_coords(0);
+ let [x, y] = this.get_motion_coords(0);
+ let monitorRect = this._getMonitorRect(startX, startY);
+
+ if ((this._side == St.Side.TOP && y > monitorRect.y + DRAG_DISTANCE) ||
+ (this._side == St.Side.BOTTOM && y < monitorRect.y + monitorRect.height - DRAG_DISTANCE) ||
+ (this._side == St.Side.LEFT && x > monitorRect.x + DRAG_DISTANCE) ||
+ (this._side == St.Side.RIGHT && x < monitorRect.x + monitorRect.width - DRAG_DISTANCE))
+ this.emit('activated');
+ }
+});
+Signals.addSignalMethods(EdgeDragAction.prototype);
+
const ViewSelector = new Lang.Class({
Name: 'ViewSelector',
@@ -145,6 +216,14 @@ const ViewSelector = new Lang.Class({
Shell.KeyBindingMode.OVERVIEW,
Lang.bind(Main.overview, Main.overview.toggle));
+ let gesture = new EdgeDragAction(St.Side.RIGHT);
+ gesture.connect('activated', Lang.bind(this, function() {
+ if (Main.overview.visible)
+ Main.overview.hide();
+ else
+ this.showApps();
+ }));
+ global.stage.add_action(gesture);
},
_toggleAppsPage: function() {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]