6

Gnome workspaces are very convenient to use, but I find them very difficult to manage. For example:

  • Shutting the last window in a workspace causes that workspace to close (if not immediately, then soon)
  • New windows can only be inserted at the always present empty workspace at the bottom.
  • Moving workspaces around would require moving each window individually, and if a workspace becomes empty during that intended process the workspace will close.

Features I though exist but can't find are:

  • Ability to suppress auto-closing of workspaces, perhaps to replace with a close-(empty)-workspace command.
  • Ability to rotate workspaces (so the empty workspace could be placed anywhere)
  • Ability to swap any workspace with its lower neighbor

Maybe I am just ignorant about commonly known facts. Or, maybe Gnome offers an API for programming in this behavior. Or maybe it's impossible.

Please inform.


Addendum: A few days after selecting the answer for this question, I found a relatively easy API to achieve stated goals. That information is provided below as a new answer.

  • Too broad, please break it into three different questions. Anyway, workspaces by default work exactly the way you described, you're not missing anything. I think the first requirement is somewhat achievable with static instead of dynamic workspaces. – pomsky Jun 21 '19 at 22:14
  • @pomsky - I should have been clearer about the question. This would have been better: Is there a workspace API or configuration file that would enable any of these functionalities: <second list as above>. Your answer might be an answer to that question. Where can I find out more about static vs dynamic workspaces within Gnome? – Craig Hicks Jun 22 '19 at 7:25
  • 1
    See this: askubuntu.com/a/1081253/480481 – pomsky Jun 22 '19 at 9:26
  • @pomsky - Fortunately I found a way to achieve the desired results, leveraging xdotool, as shown in the edited question. Your advice about static vs. dynamic workspaces was helpful, as it can only be done with setting as static. – Craig Hicks Jun 26 '19 at 1:35
3

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).

  • Your answer was partially helpful. Fortunately I was able to achieve a complete answer, e.g. rotation, and have described it in my edited question. – Craig Hicks Jun 26 '19 at 1:33
  • 1
    I think my answer correctly reflected the current state in response to your request: there is no API, but there is the "extensions" opening. You achieved what you wanted using another approach: bash scripting with window manipulation. This is the power of linux. – vanadium Jun 26 '19 at 7:04
  • 1
    Neat bash scripting, I have to say, and nice this only relies on xdotool :-) – vanadium Jun 26 '19 at 7:07
  • The xdotool project is very powerful. I moved the scripting solution out of the question and into another answer, while leaving your solution as the selected answer for the reasons you stated. – Craig Hicks Jun 26 '19 at 19:12
  • Thank you, it probably is a more generic answer fitting more users. Not everybody is prepared to go into scripting. Indeed, it is good also to have moved your approach into an answer for future reference. Again, neat piece of scripting! – vanadium Jun 27 '19 at 6:52
6

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).

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.