From a50a463eb388c186e641ad506f49ab7f8474bee6 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Wed, 25 Jun 2014 18:12:41 +0200 Subject: [PATCH] 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(+) create mode 100644 js/ui/workspaceSwitchAction.js diff --git a/js/js-resources.gresource.xml b/js/js-resources.gresource.xml index 3515ba885..3fed6a4fb 100644 --- a/js/js-resources.gresource.xml +++ b/js/js-resources.gresource.xml @@ -91,6 +91,7 @@ ui/windowMenu.js ui/windowManager.js ui/workspace.js + ui/workspaceSwitchAction.js ui/workspaceSwitcherPopup.js ui/workspaceThumbnail.js ui/workspacesView.js diff --git a/js/ui/workspaceSwitchAction.js b/js/ui/workspaceSwitchAction.js new file mode 100644 index 000000000..3cd509e2c --- /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; + +let MOTION_THRESHOLD = 50; + +const WorkspaceSwitchAction = new Lang.Class({ + Name: 'WorkspaceSwitchAction', + Extends: Clutter.GestureAction, + + _init : function() { + this.parent(); + this.set_n_touch_points (4); + global.display.connect('grab-op-begin', Lang.bind(this, this.cancel)); + global.display.connect('grab-op-end', Lang.bind(this, this.cancel)); + }, + + vfunc_gesture_prepare : function(action, actor) { + return this.get_n_current_points() == this.get_n_touch_points(); + }, + + vfunc_gesture_end : 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; + let direction; + + if (Math.abs(offsetX) < MOTION_THRESHOLD && + Math.abs(offsetY) < MOTION_THRESHOLD) + return; + + if (Math.abs(offsetY) > Math.abs(offsetX)) { + if (offsetY > 0) + direction = Meta.MotionDirection.UP; + else + direction = Meta.MotionDirection.DOWN; + } else { + if (offsetX > 0) + direction = Meta.MotionDirection.LEFT; + else + direction = Meta.MotionDirection.RIGHT; + } + + this.emit('activated', direction); + } +}); +Signals.addSignalMethods(WorkspaceSwitchAction.prototype);