Cycle through your viewports
With a small script, it is very well possible to browse through the workspaces (actually viewports):
forward:

(If the last viewport is reached, the script moves to the first one)
...or backward:

(If the first viewport is reached, the script moves to the last one)
The script
#!/usr/bin/env python3
import subprocess
import sys
move = sys.argv[1]
# get the needed info from wmctrl -d
wsdata = subprocess.check_output(["wmctrl", "-d"]).decode("utf-8").split()
# retrieve total size of workspace
ws = [int(n) for n in wsdata[3].split("x")]
# panel/launcher height/width
pans = [int(n) for n in wsdata[7].split(",")]
# work area
wa = [int(n) for n in wsdata[8].split("x")]
# x/y resolution
res_h = pans[0]+wa[0]; res_v = pans[1]+wa[1]
# current position in the spanning workspace
VP = [int(n) for n in wsdata[5].split(",")]
def last_h():
# test if we are on the last viewport horizontally
return VP[0]+res_h == ws[0]
def first_h():
# test if we are on the first viewport horizontally
return VP[0] == 0
def last_v():
# test if we are on the last viewport vertically
return VP[1]+res_v == ws[1]
def first_v():
# test if we are on the first viewport vertically
return VP[1] == 0
if move == "next":
if last_h() == False:
command = str(VP[0]+res_h)+","+str(VP[1])
elif last_v() == True:
command = "0,0"
else:
command = "0,"+str(VP[1]+res_v)
if move == "prev":
if first_h() == False:
command = str(VP[0]-res_h)+","+str(VP[1])
elif first_v() == True:
command = str(ws[0]-res_h)+","+str(ws[1]-res_v)
else:
command = str(ws[0]-res_h)+","+str(VP[1]-res_v)
subprocess.Popen(["wmctrl", "-o", command])
How to use
The script needs wmctrl:
sudo apt-get install wmctrl
Copy the script into an empty file, save it as through_viewports.py
Add two commands to two different shortcut keys:
python3 /path/to/through_viewports.py next
to go to the next viewport, and:
python3 /path/to/through_viewports.py prev
to go to the previous viewport
Open System Settings > Keyboard > Shortcuts > Custom Shortcuts. Click the +
and add both commands to shortcuts you like.
That's it The script detects how your viewports are set up and cycles through them.
How it works, the concept
In Unity, viewports are arranged in one big matrix, which all together makes the single workspace, the Unity desktop exists of.
Using the command:
wmctrl -d
in the output, we can read all information we need to find out where we currently are in the matrix.
0 * DG: 5120x2400 VP: 0,0 WA: 65,24 1215x776 N/A
5120x2400
is the total size of all viewports (matrix)
0,0
is the x/y position of the current viewport in the matrix (top left, pixels)
- from
WA: 65,24 1215x776
we can derive the screen's resolution (65,24
are the width/height of the Launcher/panel, 1215x776
is the remaining area)
Once we have the correct information, the script calculates the target position in the matrix and sets it with the command:
wmctrl -o x,y