How to move windows to another workspace without switching workspace?

XFCE supports a hotkey to move a window to another workspace.

In fact this does two things:

  • It moves the window to the new workspace.

  • switches to this workspace.

I'm trying to disable this behaviour and make the hotkey only move the window without switching the workspace. Is this somehow possible, perhaps using hidden options?


Solution 1:

wmctrl lets you manipulate windows. You can bind keyboard shortcuts to the following commands:

wmctrl -r :ACTIVE: -t 0  // Move active window to workspace 1
wmctrl -r :ACTIVE: -t 1  // Move active window to workspace 2
wmctrl -r :ACTIVE: -t 2  // Etc...
  • wmctrl - man page

Solution 2:

It is also worth recording here that it is possible to do this with xdotool, which can be installed with

sudo apt-get install xdotool

You can bind the command below to perhaps a spare button on the side of your mouse, and then you can click that button to flick the active window to another workspace. The number of the workspace is specified at the end of the command.

xdotool getactivewindow set_desktop_for_window 1

This will move the currently active window (the one that has focus) to the desired workspace, while keeping you on the workspace where the command was issued, which was just what you specifically required. (To actually move to that other workspace yourself, you would use xdotool set_desktop 1.)

You could also select a particular window to move instead of just the active window, but probably shifting the active window (whatever it is) would be most useful to bind to a key.

Note: If you use a different window manager than that of the default on Xfce, or you use compiz, you may need to look at the viewport options in the xdotool manpage or try wmctrl instead.

For more detailed information on using xdotool for manipulating windows and workspaces, please see my answers here to related, but different questions:

  • how to shift applications from workspace 1 to 2 using command

  • Is there a command to go a specific workspace?

There are so many things you can do with xdotool; please see the Ubuntu manpage or man xdotool.