Looking in the KWin’s keyboard shortcuts in System Settings I don’t see a keyboard shortcut to minimize all windows but the active (focused) one.
Is there a way to add one?
I’m using Krohnkite tiling window manager (KWin’s script) and such a shortcut would enable comfortable workflow.
At Shortcut to minimize all windows but the focused (current) one · Issue #151 · anametologin/krohnkite · GitHub is my suggestion to add it directly to Krohnkite which has been declined as out of scope of Krohnkite and in the scope of KWin.
KWin’s issue a hotkey to minimize everything except active window raised in 2009 (16 years ago…).
Searching for minimize all but current I found this thread – Minimize all but current • KDE Community Forums – where someone was looking for this feature in KDE and this thread – Is there a keyboard shortcut for minimizing all windows except the active one? - Ask Ubuntu – where someone was looking for this feature in Gnome.
dzon
March 26, 2025, 8:48am
2
Should be doable with a little script. On 5-ish and x I use xdotool.
So I guess something similar with kdotool ( if wayland) could do the job.
Something like:
Servicemenu, desktop app or shortcut…
1 Like
Thanks!
Based on your code I came up with this:
#!/bin/bash
# Minimize all but focused window (so called "shake it" action)
active_window_id=$(kdotool getactivewindow)
for window_id in $(kdotool search ".*")
do
if [ $window_id != $active_window_id ]; then
kdotool windowminimize $window_id
fi
done
I also suggested adding a feature to add/remove window to/from windows stack at Multiple commands / stack manipulation · Issue #19 · jinliu/kdotool · GitHub and asked How to assign a keyboard shortcut to kdotool script in a file? · Issue #22 · jinliu/kdotool · GitHub
@luisbocanegra pointed me to minimizeall KWin script in KWin’s source code (ksrc/plugins/minimizeall/package/contents/code/main.js ) which after slight modification should work as a native solution (avoiding the need for kdotool
).
dzon
April 10, 2025, 3:26pm
6
Yep, would do the trick. Not sure how you’d assign a shortcut, but yeah. A corner binding would also work.
There’s this line at the end:
registerShortcut("MinimizeAll", "MinimizeAll", "Meta+Shift+D", minimizeAllWindows);
dzon
April 10, 2025, 10:01pm
8
O that’s right, it has a shortcut.
Where do these entries come from (I don’t have them)?
Have you installed some scripts/plugins?
dzon
April 11, 2025, 4:09pm
11
I stumbled upon https://github.com/ArneBab/kwin-minimize-others , edited the file a bit and there you go. No kdotool, xdotool..whatever. And, no altering the minimize all file. Of course, no corner binding option.
1 Like
The script after changes from @luisbocanegra and me:
var lastActiveClient;
function isRelevant(client) {
return client.minimizable &&
client !== workspace.activeWindow &&
(!client.desktops || client.desktops.indexOf(workspace.currentDesktop) != -1) &&
(!client.activities || client.activities.indexOf(workspace.currentActivity.toString()) > -1);
}
function minimizeAllWindowsButActive() {
var allClients = workspace.windowList();
var relevantClients = [];
var minimize = false;
for (var client in allClients) {
if (!isRelevant(clien)) {
continue;
}
if (!client.minimized) {
minimize = true;
}
relevantClients.push(client);
}
if (minimize) {
lastActiveClient = workspace.activeWindow
}
for (var client in relevantClients) {
var wasMinimizedByScript = client.minimizedByScript;
delete client.minimizedByScript;
if (minimize) {
if (client.minimized) {
continue;
}
client.minimized = true;
client.minimizedByScript = true;
} else {
if (!wasMinimizedByScript) {
continue;
}
client.minimized = false;
}
}
workspace.activeWindow = lastActiveClient
}
registerShortcut("MinimizeAllButActive", "MinimizeAllButActive", "Meta+R", minimizeAllWindowsButActive);
Simple metadata.json
needed to install it:
{
"KPackageStructure": "KWin/Script",
"KPlugin": {
"Authors": [ ],
"Description": "Adds a shortcut to minimize and restore all windows",
"Icon": "preferences-system-windows-script-test",
"Id": "minimizeallbutactive",
"License": "GPL",
"Name": "MinimizeAllButActive"
},
"X-KDE-ConfigModule": "kcm_kwin4_genericscripted",
"X-KWin-Border-Activate": "false",
"X-Plasma-API": "javascript"
}
The layout of directories and files:
.
├── contents
│ └── code
│ └── main.js
└── metadata.json
and the command to install (when being in the root of above tree):
kpackagetool6 -t KWin/Script -i .
Replace -i
with -u
when upgrading after making changes.
1 Like
dzon
April 13, 2025, 8:44pm
13
Well, if it works, it works.
Gave that github script a swing and it works fine without loosing the default minimize all feature. On 5-ish that is. But like I said, a corner binding option could actually be nice.
And since I’m not exactly a keyboard fan, I made a desktop app using…xdotool