From 22b7ac02b4b1cefde6c8bc544c9012c520a233de Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Tue, 2 Nov 2021 22:51:53 +0200 Subject: [PATCH] scripts/minimizeall: Try to preserve last active window Windows in workspace.clientList() are sorted in the map order. This means that the minimize all script will try to activate the last mapped window when unminimizing windows, which is a bit annoying. This change ensures that the minimize all script doesn't activate wrong window by minimizing and unminimizing windows in the stacking order. It's not a bullet-proof solution though, but it should produce good enough results. --- src/scripts/minimizeall/contents/code/main.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/scripts/minimizeall/contents/code/main.js b/src/scripts/minimizeall/contents/code/main.js index 8add235676..fd4aa11588 100644 --- a/src/scripts/minimizeall/contents/code/main.js +++ b/src/scripts/minimizeall/contents/code/main.js @@ -30,6 +30,16 @@ function minimizeAllWindows() { relevantClients.push(allClients[i]); } + // Try to preserve last active window by sorting windows. + relevantClients.sort((a, b) => { + if (a.active) { + return 1; + } else if (b.active) { + return -1; + } + return a.stackingOrder - b.stackingOrder; + }); + for (var i = 0; i < relevantClients.length; ++i) { var wasMinimizedByScript = relevantClients[i].minimizedByScript; delete relevantClients[i].minimizedByScript;