Is is possible to move all windows (or all not minimized windows) form one workspace to another?
I know I can move one window to other workspace with Shift+Ctrl+Alt+arrow, but it will move only that one focused window.
compizunityviewportsworkspaces
Is is possible to move all windows (or all not minimized windows) form one workspace to another?
I know I can move one window to other workspace with Shift+Ctrl+Alt+arrow, but it will move only that one focused window.
Best Answer
Unity : What are Viewports?
Ubuntu Unity uses viewports - basically a coordinate system (with coordinate 0,0 being top left corner) , where one giant desktop subdivided into chunks that fit your screen resolution. Coordinates grow in value as you move to the right and downwards.
The coordinate system is relative. If my current viewport is top left , everything relative to that viewport will be positive values in increments of width and height. For instance, if my current viewport is top leftmost, the firefox window in top middle workspace you see above is positioned in at x value 1366 and y value 0 relative to the top leftmost viewport. If my active viewport is top middle one, the terminal window in top leftmost viewport is positioned at x value -1327 60. This is the key issue for
xdotool
, becausexdotool
does not deal with negative numbers.Note also that, the top left corner of your current viewport will always be assumed by xdotool as coordinates 0 0 . That means we can only move stuff right and down.
Making xdotool work for Unity
Now we know that
xdotool
can move windows only relative to our top-left corner ( i.e., you can always move window down and right , but never up and left ). How do we make that work for unity. Well, the basic idea would be toScripting Solution
The script below performs exactly the procedure described above. It can be called with either
-v
flag to manually specify coordinates or you can use-g
flag to bring up GUI dialog.-f
flag will tell the script to switch viewport too ; if that flag is not used - you'll remain on the current viewport and only windows will be moved aroundObtaining the script
One can copy the source code from this post directly or through github using the following steps:
sudo apt-get install git
cd /opt ; sudo git clone https://github.com/SergKolo/sergrep.git
sudo chmod -R +x sergrep
The script file will be
/opt/sergrep/move_viewport_windows.sh
To bind script to shortcut , refer to How do I bind .sh files to keyboard combination?
Note that
wmctrl
andxdotool
are required for this script to work properly. You can install them via sudo apt-get install xdotool and wmctrlSource Code
Demo
Webm recording of the script in action:
https://www.youtube.com/watch?v=cJMlC41CWWo
Issues
Due to Unity's
grid
plugin that is responsible for window snapping, the script cannot move the maximized , or right/left snapped windows. It will be attempted to add the momentary unset and reset of that plugin to make the script work with all windows, but because unsetting and resetting has a time delay, it might be abandoned as an idea. If you want the script to make working with all windows, installunity-tweak-tool
and unset window snapping under Window Manager options.