I'm running Linux Mint 17.1 (KDE). I know that I'm able to move windows from one desktop space to another by right-clicking in the title bar. I also know I'm able to do so from the command line with wmctrl, which first requires me to know the window ID. In my case, I can do this:

wmctrl -l

This lists open windows with their respective IDs:

0x04c00012 0 laptop2 Downloads – Dolphin

0x00800015 -1 laptop2 Yakuake

0x03800012 1 laptop2 sh-format.sh – Kate

(along with several others).

If I then type:

wmctrl -i -r 0x03800012 -t 1

then I can move the Kate window to desktop 2.

My question is this: I would like to either (1) set up a keyboard shortcut to move the active window to a different desktop (I'm willing to set up separate shortcuts per desktop), or (2) identify the window ID for the active window, so that I can script a shortcut.

Is there a way to do this?

  • You can just do this with the builtin KWin scripts? In Plasma 5, you can set the key at System Settings > (Workspace) Shortcuts > Global Keyboard Shortcuts > KWin > Window to Desktop 2.
    – Sparhawk
    Feb 10 '16 at 22:26
  • @Sparhawk: I thought I should be able to, but don't have this option in KWin. I'm confused by this, but so it is.
    – Fire
    Feb 18 '16 at 21:49
  • It might be different in KDE 4 (is that what Mint ships with?), but this is how it looks in Plasma 5. I definitely used that option in KDE 4, at least in Arch Linux and Ubuntu.
    – Sparhawk
    Feb 18 '16 at 22:27

I found a solution. Rather than delete the question, I thought I'd post what I have. I'm sure someone or other has the same question somewhere, and if not, I'm sure there's still a cleaner way of doing this. Here goes.

(This, by the way, is to make a keyboard shortcut to move the active window to workspace 4.)

First, I wrote a script (~/.move4.sh):

a=`xprop -root _NET_ACTIVE_WINDOW | rev | cut -d ' ' -f1 | rev`;wmctrl -i -r $a -t 3

(the "-t 3" is because the workspace numbering starts at zero, so "-t 3" moves the window to workspace 4)

I made the script executable:

chmod u+x ~/.move4.sh

Finally, I went into system settings and made a custom global keyboard shortcut (I used Meta+4), and assigned it to run this script. Worked like a charm.

I feel silly for not having come up with it sooner, but I think I had to post a question to come up with an answer. Sorry.

  • You could just use: wmctrl -r :ACTIVE: -t 3 (assuming you want to send to the 4th desktop) Instead of xprop -root _NET_ACTIVE_WINDOW | rev | cut -d ' ' -f1 | rev I would recommend xdotool getactivewindow
    – erwin
    Aug 27 '21 at 7:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.