From dc73f5f38421a2ae824ebf98cf2ee50e6bb800a3 Mon Sep 17 00:00:00 2001 From: matt1432 Date: Sat, 28 Oct 2023 21:41:20 -0400 Subject: [PATCH] fix(ags overview): properly get rid of timeouts --- devices/wim/config/ags/config.js | 3 ++ devices/wim/config/ags/js/overview/clients.js | 3 -- .../wim/config/ags/js/overview/workspaces.js | 32 +++++++++++++------ 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/devices/wim/config/ags/config.js b/devices/wim/config/ags/config.js index 628070ed..64d858c1 100644 --- a/devices/wim/config/ags/config.js +++ b/devices/wim/config/ags/config.js @@ -1,3 +1,6 @@ +// Has to be a traditional function for 'this' scope +Array.prototype.remove = function (el) { this.splice(this.indexOf(el), 1); }; + import { App, Utils } from './imports.js'; import closeAll from './js/misc/closer.js'; diff --git a/devices/wim/config/ags/js/overview/clients.js b/devices/wim/config/ags/js/overview/clients.js index af3dd9a2..b0a97cce 100644 --- a/devices/wim/config/ags/js/overview/clients.js +++ b/devices/wim/config/ags/js/overview/clients.js @@ -5,9 +5,6 @@ const { execAsync } = Utils; import { WindowButton } from './dragndrop.js'; import * as VARS from './variables.js'; -// Has to be a traditional function for 'this' scope -Array.prototype.remove = function (el) { this.splice(this.indexOf(el), 1); }; - const scale = size => size * VARS.SCALE - VARS.MARGIN; const getFontSize = client => Math.min(scale(client.size[0]), scale(client.size[1])) * VARS.ICON_SCALE; diff --git a/devices/wim/config/ags/js/overview/workspaces.js b/devices/wim/config/ags/js/overview/workspaces.js index fc920090..37216b49 100644 --- a/devices/wim/config/ags/js/overview/workspaces.js +++ b/devices/wim/config/ags/js/overview/workspaces.js @@ -74,7 +74,10 @@ const Workspace = (id, name, extra = false) => { ['wasActive', false], ], connections: [[Hyprland, box => { - box._timeouts.forEach(timer => GLib.source_remove(timer)); + box._timeouts.forEach(timer => { + GLib.source_remove(timer); + box._timeouts.remove(timer); + }); const activeId = Hyprland.active.workspace.id; const active = activeId === box._id; @@ -84,15 +87,21 @@ const Workspace = (id, name, extra = false) => { if (Hyprland.getWorkspace(box._id)?.windows > 0 || active) { rev.setStyle(DEFAULT_STYLE); - box._timeouts.push(Utils.timeout(100, () => { + + const timer = Utils.timeout(100, () => { box.revealChild = true; - })); + box._timeouts.remove(timer); + }); + box._timeouts.push(timer); } else if (!Hyprland.getWorkspace(box._id)?.windows > 0) { rev.setStyle(DEFAULT_STYLE); - box._timeouts.push(Utils.timeout(100, () => { + + const timer = Utils.timeout(100, () => { box.revealChild = false; - })); + box._timeouts.remove(timer); + }); + box._timeouts.push(timer); return; } @@ -103,18 +112,23 @@ const Workspace = (id, name, extra = false) => { box._wasActive = true; } else if (box._wasActive) { - box._timeouts.push(Utils.timeout(120, () => { + const timer1 = Utils.timeout(120, () => { rev.setStyle(`${DEFAULT_STYLE} transition: margin 0.5s ease-in-out; opacity: 1; margin-left: ${n ? '' : '-'}300px; margin-right: ${n ? '-' : ''}300px;`); box._wasActive = false; - })); - box._timeouts.push(Utils.timeout(500, () => { + box._timeouts.remove(timer1); + }); + box._timeouts.push(timer1); + + const timer2 = Utils.timeout(500, () => { rev.setStyle(`${DEFAULT_STYLE} opacity: 0; margin-left: ${n ? '' : '-'}300px; margin-right: ${n ? '-' : ''}300px;`); - })); + box._timeouts.remove(timer2); + }); + box._timeouts.push(timer2); } else { rev.setStyle(`${DEFAULT_STYLE} opacity: 0;