From b7a926a0b52eb221a5536d245afe5405f2c0cddc Mon Sep 17 00:00:00 2001 From: Jay Ta'ala Date: Mon, 22 Jan 2024 22:34:53 +1100 Subject: [PATCH] FIX: for case where switchWorkspace by clicking link (which opens window in another space on another monitor) - if space is shown on that monitor don't do gnome workspace switch animation. --- patches.js | 46 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/patches.js b/patches.js index 1c4c9d2d..bfbf635e 100644 --- a/patches.js +++ b/patches.js @@ -140,21 +140,47 @@ export function setupOverrides() { // WorkspaceAnimation.WorkspaceAnimationController.animateSwitch // Disable the workspace switching animation in Gnome 40+ function (_from, _to, _direction, onComplete) { + // ensure swipeTrackers are disabled after this + const reset = () => { + // gnome windows switch animation time = 250, do that plus a little more + pillSwipeTimer = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 300, () => { + swipeTrackers.forEach(t => { + t.enabled = false; + }); + pillSwipeTimer = null; + return false; // on return false destroys timeout + }); + }; + + if (Tiling.inPreview) { + onComplete(); + reset(); + return; + } + // if using PaperWM workspace switch animation, just do complete here - if (Tiling.inPreview || !Tiling.spaces.space_defaultAnimation) { + if (!Tiling.spaces.space_defaultAnimation) { onComplete(); + reset(); + return; } - else { - const saved = getSavedPrototype(WorkspaceAnimation.WorkspaceAnimationController, 'animateSwitch'); - saved.call(this, _from, _to, _direction, onComplete); + + // if switching to a paperwm space that is already shown on a monitor + // from / to are workspace indices + const toSpace = Tiling.spaces.spaceOfIndex(_to); + + const spaces = Array.from(Tiling.spaces.monitors.values()); + const toOnMonitor = spaces.some(space => space === toSpace); + if (toOnMonitor) { + onComplete(); + reset(); + return; } - // ensure swipeTrackers are disabled after this - pillSwipeTimer = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 500, () => { - swipeTrackers.forEach(t => t.enabled = false); - pillSwipeTimer = null; - return false; // on return false destroys timeout - }); + // standard gnome switch animation + const saved = getSavedPrototype(WorkspaceAnimation.WorkspaceAnimationController, 'animateSwitch'); + saved.call(this, _from, _to, _direction, onComplete); + reset(); }); registerOverridePrototype(WorkspaceAnimation.WorkspaceAnimationController, '_prepareWorkspaceSwitch',