diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-12-10 13:32:02 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-12-10 14:44:01 +0000 |
commit | 2705a55fe1128387a1761cae93b1e41ebaeb750d (patch) | |
tree | 87178c5463e34efb0b3847e0559011ec7d49d8e2 /extensions/44/vertical-workspaces/lib/swipeTracker.js | |
parent | Adding upstream version 20230618. (diff) | |
download | gnome-shell-extensions-extra-upstream/20231012.tar.xz gnome-shell-extensions-extra-upstream/20231012.zip |
Adding upstream version 20231210.upstream/20231012
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'extensions/44/vertical-workspaces/lib/swipeTracker.js')
-rw-r--r-- | extensions/44/vertical-workspaces/lib/swipeTracker.js | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/extensions/44/vertical-workspaces/lib/swipeTracker.js b/extensions/44/vertical-workspaces/lib/swipeTracker.js new file mode 100644 index 0000000..7122ead --- /dev/null +++ b/extensions/44/vertical-workspaces/lib/swipeTracker.js @@ -0,0 +1,116 @@ +/** + * V-Shell (Vertical Workspaces) + * swipeTracker.js + * + * @author GdH <G-dH@github.com> + * @copyright 2022 - 2023 + * @license GPL-3.0 + * + */ + +'use strict'; + +const Clutter = imports.gi.Clutter; +const GObject = imports.gi.GObject; + +const Main = imports.ui.main; +const SwipeTracker = imports.ui.swipeTracker; + +let Me; +let opt; + +var SwipeTrackerModule = class { + constructor(me) { + Me = me; + opt = Me.opt; + + this._firstActivation = true; + this.moduleEnabled = false; + } + + cleanGlobals() { + Me = null; + opt = null; + } + + update(reset) { + this.moduleEnabled = opt.get('swipeTrackerModule'); + const conflict = false; + + reset = reset || !this.moduleEnabled || conflict; + + // don't touch the original code if module disabled + if (reset && !this._firstActivation) { + this._disableModule(); + } else if (!reset) { + this._firstActivation = false; + this._activateModule(); + } + if (reset && this._firstActivation) + console.debug(' SwipeTrackerModule - Keeping untouched'); + } + + _activateModule() { + if (opt.ORIENTATION) { // 1-VERTICAL, 0-HORIZONTAL + this._setVertical(); + } else { + this._setHorizontal(); + } + console.debug(' SwipeTrackerModule - Activated'); + } + + _disableModule() { + this._setHorizontal(); + + console.debug(' SwipeTrackerModule - Disabled'); + } + + _setVertical() { + // 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 (!this._originalGestureUpdateId) { + this._originalGestureUpdateId = GObject.signal_handler_find(Main.overview._swipeTracker._touchpadGesture, { signalId: 'update' }); + Main.overview._swipeTracker._touchpadGesture.block_signal_handler(this._originalGestureUpdateId); + Main.overview._swipeTracker._updateGesture = SwipeTrackerVertical._updateGesture; + this._vwGestureUpdateId = Main.overview._swipeTracker._touchpadGesture.connect('update', SwipeTrackerVertical._updateGesture.bind(Main.overview._swipeTracker)); + } + } + + _setHorizontal() { + // 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 (this._vwGestureUpdateId) { + Main.overview._swipeTracker._touchpadGesture.disconnect(this._vwGestureUpdateId); + this._vwGestureUpdateId = 0; + } + if (this._originalGestureUpdateId) { + Main.overview._swipeTracker._touchpadGesture.unblock_signal_handler(this._originalGestureUpdateId); + this._originalGestureUpdateId = 0; + } + } +}; + +const SwipeTrackerVertical = { + _updateGesture(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); + }, +}; |