summaryrefslogtreecommitdiffstats
path: root/js/ui/edgeDragAction.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 15:07:22 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 15:07:22 +0000
commitf9d480cfe50ca1d7a0f0b5a2b8bb9932962bfbe7 (patch)
treece9e8db2d4e8799780fa72ae8f1953039373e2ee /js/ui/edgeDragAction.js
parentInitial commit. (diff)
downloadgnome-shell-f9d480cfe50ca1d7a0f0b5a2b8bb9932962bfbe7.tar.xz
gnome-shell-f9d480cfe50ca1d7a0f0b5a2b8bb9932962bfbe7.zip
Adding upstream version 3.38.6.upstream/3.38.6upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/ui/edgeDragAction.js')
-rw-r--r--js/ui/edgeDragAction.js77
1 files changed, 77 insertions, 0 deletions
diff --git a/js/ui/edgeDragAction.js b/js/ui/edgeDragAction.js
new file mode 100644
index 0000000..8502170
--- /dev/null
+++ b/js/ui/edgeDragAction.js
@@ -0,0 +1,77 @@
+// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
+/* exported EdgeDragAction */
+
+const { Clutter, GObject, Meta, St } = imports.gi;
+
+const Main = imports.ui.main;
+
+var EDGE_THRESHOLD = 20;
+var DRAG_DISTANCE = 80;
+
+var EdgeDragAction = GObject.registerClass({
+ Signals: { 'activated': {} },
+}, class EdgeDragAction extends Clutter.GestureAction {
+ _init(side, allowedModes) {
+ super._init();
+ this._side = side;
+ this._allowedModes = allowedModes;
+ this.set_n_touch_points(1);
+
+ global.display.connect('grab-op-begin', () => this.cancel());
+ }
+
+ _getMonitorRect(x, y) {
+ let rect = new Meta.Rectangle({ x: x - 1, y: y - 1, width: 1, height: 1 });
+ let monitorIndex = global.display.get_monitor_index_for_rect(rect);
+
+ return global.display.get_monitor_geometry(monitorIndex);
+ }
+
+ vfunc_gesture_prepare(_actor) {
+ if (this.get_n_current_points() == 0)
+ return false;
+
+ if (!(this._allowedModes & Main.actionMode))
+ 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(_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(_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');
+ }
+});