Keyboard shortcut to minimize all windows but the active (focused) one (so called "shake it" action)

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.

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).

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);

O that’s right, it has a shortcut.

Found yet another one.


Where do these entries come from (I don’t have them)?
Have you installed some scripts/plugins?

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

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 :sweat_smile:

Just for your information, the work to include this feature in KDE is underway at plugins/minimizeall: add AllOthers, ActiveScreen & activate last active (!7538) · Merge requests · Plasma / KWin · GitLab

1 Like

The feature was merged and will be available starting from Plasma 6.6.0!

Plasma 6.6 is out, but it appears the version of MinimizeAll KWin script included does not play nicely with Krohnkite – see The new „Minimize all other windows…” feature from Plasma 6.6 does not work well with Krohnkite

I see. But um, on a sidenote and just my personal thoughts. I don’t really see the point of the “shake effect” when in tiled mode. You’d still have to maximize the active window to make it of any use. Unless the shake includes “maximize window” or “set to initial unmaximized size” as well. Also, there’s a difference between minimize all, a standard kwin script and minimize all but. Names seem to be a bit confusing. Anyhow, just my thoughts.

The standard “minimize all”, I have bound to the right bottom corner.

The toggle for shake is still the same and on the top panel.

You don’t have to maximize the window yourself as this is done automatically by Krohnkite when only one window is visible (non-minimized).
Being able to minimize all windows but the active one and thus having the active one automatically occupy the whole screen (but not being maximized in KWin sense) and being able to return to the previous layout by pressing the same keyboard shortcut again is probably the single biggest improvement to using Krohnkite I can envision. It became an essential part of my workflow.

Both actions happen indeed and can be thought of as being “part of shake”, although technically they are performed by Krohnkite in response to minimizing or unminimizing windows.

By the way, maximizing a window in KWin sense goes against the tiling manager spirit, so I even have a Window Rule blocking all windows from being maximized.

I get your point. Here’s the thing. On 5-ish ( very very reluctant for 6-ish myself :rofl: ) I use this thing called “active window”). It has a couple of options, one being the mouse scroll up to maximize the active window, down to restore tiling state. Damn, I wish this widget could be ported to 6-ish. Still, my point being that maximizing a window when in tiled state makes sense when in, say, a kvantum or lightly style layout, visually speaking ( due to transparency and all that). Anyway, I’m sure this shake vs krohnkite issue will get sorted out and like I said, I’d need to actually use 6-ish to actually make sense I guess.

You can try to bring Luis Bocanegra’s attention to this. On his github’s page there’s a link to his matrix.org room where you can reach him.

I am not following, sorry. What does transparency have to do with this? When I started to use Krohnkite, I was looking for the optimum way to temporarily maximize a window (see Monocle or float – which one is better to peek a window? · anametologin/krohnkite · Discussion #88 · GitHub) and after trying a few approaches, I discovered that the best way was to just minimize all windows but the active one and let Krohnkite do its work i.e., maximize the only window left. The much needed ingridient was to have the minimizing script be able to unminimize all windows it had previously minimized when pressing the same shortcut again. Thanks to Luis this behavior was added to MinimizeAll KWin script included in Plasma and the rest is history :smiley: