Script to swap all opened window between display monitors


I’m using dual display monitor setup using KDE.

Is there a script/shortcut available to easily swap all windows from the first monitor to the second monitor; and vice versa? For example the script would bind to the keyboard combination CTRL+W; and pressing this keyboard combination will swap all window between monitors.



Hey there
While I don’t know of any scripts I do know a bunch of keyboard shortcuts that might help.

There are keyboard shortcuts that you can use thou they only shift one at a time, take some standard KDE tools and it makes them work here very well, this what has evolved on my box.

Shortcuts - Kwin - in search box type in window
scroll down to
Window to screen 0 I use Meta+0
Window to screen 1 I use Meta+1

IF you want to use the mouse without clicking then try this
Window Management - Focus - Focus Follows Mouse
I’ve got checked Raise on Hover
Then simply hover mouse over window and use the appropriate move Window to Screen shortcut.

Then later added now I also use this so I don’t have to move the mouse
go back to
Shortcuts - Kwin - in search box type in window
scroll down to
Switch to Window Above I use Meta+Alt+Up (arrow)
Switch to Window Below I use Meta+Alt+Down (arrow)
Switch to Window Left I use Meta+Alt+Left (arrow)
Switch to Window Right I use Meta+Alt+Right (arrow)

This way there is focus follows mouse , control the window under focus use keys , move window to other screen using keys.

Keyboard shortcuts are better than clicking on and dragging windows around.

Now if I could make the windows behave same as Layers in Gimp (selectively linked) Ahh Bliss.

Hope this helps.

1 Like

One can do this sort of thing with X11, using utilities like wmctrl.

In principle, kwin scripting can, or will one day, do this. But, I’ve found these are hard to get into.

1 Like

This KWin Script seems to do what you want:

Will create a new action called “Switch the screen to all windows”, whose default shortcut is Meta+Shift+P
When activated, all windows will move to the next screen.

1 Like

Thanks for this simple solution Luis! The KWin script works like a charm after rebooting the computer. Thanks everyone!

Installed the script and rebooted x2 it’s just not willing to work here, Thanks anyway.

I have installed the KWin script on my Steam Deck running SteamOS KDE and on a laptop running MX Linux KDE. The script works for me on both machine.

It would be nice if a button “switch to other monitor” could be added to the top bar, along with maximise/minimise/close.

To add it to the panel you can use any of the “run command” widgets and then make it invoke the shortuct by setting the command to:

qdbus org.kde.kglobalaccel /component/kwin org.kde.kglobalaccel.Component.invokeShortcut "switchAllWindowsScreen"

For the maximize/minimize/close actions the Window Buttons widget does that and it works amazingly well

1 Like

Thanks Luis. That looks interesting.

I don’t see the installation instruction available for Debian based system? I’m using MX Linux.

I don’t see them either, but you can always build from source and hunt for the dependencies as they are requested :slight_smile:

1 Like

Lol ok. Thanks again Luis.