18.04 (gnome) workspaces - How to manipulate (e.g. arbitrarily reorder) workspaces?
Note: Answering my own question - while leaving the accepted answer because it accurately reflects Gnome status.
There is a project xdotool which is conveniently provided as Ubuntu 18.04 managed packaged. It offers read and write access to desktops, windows, and their relationships. (Also many other features I didn't use.)
Using this package it was simple to code the desired functions. Direct CLI is not useful but linking them to Ubuntu custom shortcuts meant I was, for example, able to move select and move individual desktops up and down with keys while watching the all desktops with Gnomes standard bird's eye view.
The Gnome standard bird's eye is available through "Super+a, Super+a" and then moving the mouse to the right hand side of the screen whereupon all the desktops will appear in a vertical array.
To avoid interference with Gnome, it was necessary to turn off Gnome's dynamic desktops and use the static desktops setting instead. Using static desktops was suggested in the selected answer.
My complete code is provided as a gist.
As an example, this code excerpt is for swapping desktops:
swaprelative(){
nbr=$1
ndt=$(xdotool get_num_desktops)
if [[ $ndt -lt 2 ]] ; then return 0 ; fi
adt=$(xdotool get_desktop)
bdt=$((( adt + ndt + nbr) % ndt ))
if [[ $bdt == $adt ]] ; then return 0; fi
if [[ $bdt -lt 0 ]] ; then
echo "relative neighbor value $nbr is out of bounds"
return 1;
fi
xdotool search '.*' | while read w ; do
if ! window_has_desktop $w ; then continue; fi
wdt=$(xdotool get_desktop_for_window $w)
if [[ $wdt -eq $adt ]] ; then
xdotool set_desktop_for_window $w $bdt
elif [[ $wdt -eq $bdt ]] ; then
xdotool set_desktop_for_window $w $adt
fi
done
xdotool set_desktop $bdt
}
It must be emphasized that the coding was so simple is due to of the power of the xdotool
project. That project is not dependent on Gnome, but rather operates in parallel with Gnome accessing the same X primitives. Likely it can be used across a number of different window managers, provided care is taken to avoid mutual interference between the WM and xdotool, (e.g. switching off dynamic desktops in Gnome).
In GNOME Shell, one cannot, by default, move around entire workspaces with the applications they contain. While this would be a powerful feature, I do not know Linux desktop environments that feature this.
With respect to an API, GNOME Shell has the mechanism of extensions. This actually is not an API at all. It is essentially a "(potential security) hole" in the system where developers can inject their own javascript code to change the behaviour of the Shell. The many GNOME Shell extensions around exist illustrate what can be done, in many cases with great success.
With respect to the features you expect, the situation is as follows:
Ability to suppress auto-closing of workspaces, perhaps to replace with a close-(empty)-workspace command.
By default, GNOME Shell comes with dynamic work spaces. This, however, can be turned off, and you can set a number of fixed workspaces. To achieve this, install (GNOME) Tweaks, and select "Static workspaces" on the "Workspaces" tab as illustrated here.
Ability to rotate workspaces (so the empty workspace could be placed anywhere)
There is no possibility to change the order of workspaces (and their content), unfortunately. You only can move applications around. Of course, with static workspaces, an empty workspace remains empty.
Ability to swap any workspace with its lower neighbor
It depends what you mean with this. If you mean again changing the order of workspaces, then see the point above. If you mean quickly switching workspaces, then this is easily achieved with the shortcut keys Ctrl+Alt+Up/Down or Super+PgDn/PgUp.
Switching to static workspaces can give you more control on what is where, with the restriction that you cannot move entire workspaces around.
Some tips to enhance a workflow with static workspaces
You can install the Workspace Indicator GNOME Shell extension to provide an indicator of the current workspace you are on. The extension allows you to rename your workspaces if you wish (e.g. "1 - Browsing" rather than "1").
You can configure hotkeys to quickly switch to a specific workspace or move an application, for example:
gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-4 "['<Super>4']" gsettings set org.gnome.desktop.wm.keybindings move-to-workspace-4 "['<Super><Shift>4']"
These commands will set up a hotkey Super+4 that immediately brings you to WS 4, and a hotkey Super+Shift+4 that moves an application to WS 4 (much like it works in the tiling window manager i3).