From 3713a4d3bf8ae2df7d02e63b5b827353e5121d19 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 5 Feb 2023 09:57:47 +0100 Subject: Merging upstream version 20230205. Signed-off-by: Daniel Baumann --- extensions/vertical-workspaces/swipeTracker.js | 79 ++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 extensions/vertical-workspaces/swipeTracker.js (limited to 'extensions/vertical-workspaces/swipeTracker.js') diff --git a/extensions/vertical-workspaces/swipeTracker.js b/extensions/vertical-workspaces/swipeTracker.js new file mode 100644 index 0000000..d5c52da --- /dev/null +++ b/extensions/vertical-workspaces/swipeTracker.js @@ -0,0 +1,79 @@ +/** + * Vertical Workspaces + * swipeTracker.js + * + * @author GdH + * @copyright 2022 - 2023 + * @license GPL-3.0 + * + */ + +'use strict'; + +const { Clutter, GObject } = imports.gi; +const Main = imports.ui.main; +const SwipeTracker = imports.ui.swipeTracker; + +const Me = imports.misc.extensionUtils.getCurrentExtension(); +let opt; + +let _vwGestureUpdateId; +let _originalGestureUpdateId; + +function update(reset = false) { + opt = Me.imports.settings.opt; + + if (reset || !opt.ORIENTATION) { // 1-VERTICAL, 0-HORIZONTAL + // original swipeTrackers' orientation and updateGesture function + Main.overview._swipeTracker.orientation = Clutter.Orientation.VERTICAL; + Main.wm._workspaceAnimation._swipeTracker.orientation = Clutter.Orientation.HORIZONTAL; + Main.overview._swipeTracker._updateGesture = SwipeTracker.SwipeTracker.prototype._updateGesture; + if (_vwGestureUpdateId) { + Main.overview._swipeTracker._touchpadGesture.disconnect(_vwGestureUpdateId); + _vwGestureUpdateId = 0; + } + if (_originalGestureUpdateId) { + Main.overview._swipeTracker._touchpadGesture.unblock_signal_handler(_originalGestureUpdateId); + _originalGestureUpdateId = 0; + } + + opt = null; + return; + } + + if (opt.ORIENTATION) { // 1-VERTICAL, 0-HORIZONTAL + // reverse swipe gestures for enter/leave overview and ws switching + Main.overview._swipeTracker.orientation = Clutter.Orientation.HORIZONTAL; + Main.wm._workspaceAnimation._swipeTracker.orientation = Clutter.Orientation.VERTICAL; + // overview's updateGesture() function should reflect ws tmb position to match appGrid/ws animation direction + // function in connection cannot be overridden in prototype of its class because connected is actually another copy of the original function + if (!_originalGestureUpdateId) { + _originalGestureUpdateId = GObject.signal_handler_find(Main.overview._swipeTracker._touchpadGesture, { signalId: 'update' }); + Main.overview._swipeTracker._touchpadGesture.block_signal_handler(_originalGestureUpdateId); + Main.overview._swipeTracker._updateGesture = SwipeTrackerVertical._updateGesture; + _vwGestureUpdateId = Main.overview._swipeTracker._touchpadGesture.connect('update', SwipeTrackerVertical._updateGesture.bind(Main.overview._swipeTracker)); + } + } +} + +//---- SwipeTracker ----------------------------------------------------------------------------------- +// switch overview's state gesture direction +var SwipeTrackerVertical = { + _updateGesture: function(gesture, time, delta, distance) { + if (this._state !== 1) //State.SCROLLING) + return; + + if ((this._allowedModes & Main.actionMode) === 0 || !this.enabled) { + this._interrupt(); + return; + } + + if (opt.WS_TMB_RIGHT) + delta = -delta; + this._progress += delta / distance; + this._history.append(time, delta); + + this._progress = Math.clamp(this._progress, ...this._getBounds(this._initialProgress)); + this.emit('update', this._progress); + } +} -- cgit v1.2.3