Assume I am using 4 workspaces and I incidentally need more, is there an automated process or, if impossible, an easy way to incidentally add more workspaces (instead of installing Ubuntu tweak
etc. etc.).
Assume I am using 4 workspaces and I incidentally need more, is there an automated process or, if impossible, an easy way to incidentally add more workspaces (instead of installing Ubuntu tweak
etc. etc.).
Automatically set the number of workspaces; add and remove columns and rows, depending on your needs
Below a version of a (the) backround script that will automatically add workspaces if you entered the last column or row of your workspace-matrix.
This is how it works:
If you arrive at the last column or row, additional viewports are added:
If your workspaces are unused for 5-10 seconds and there are no windows on it, the additional workspaces will be removed again. You will however always keep one extra row below, and one extra column right of your current viewport:
The script:
How to use
add_space.py
In the head section of the script, edit the lines if you like other settings (maximum number of workspaces, default matrix e.g. 2x2):
Test- run it by the command:
If all works fine, add it to your startup applications: Dash > Startup Applications > Add the command:
Note
As always, the script is extremely "low on juice", and does not add any noticeable load to your processor.
Explanation
The story below is a bit complicated and mostly an explanation on the concept and the procedure, rather than the coding. Only read if you're interested.
How to calculate the needed workspaces (example columns)
The output of
wmctrl -d
looks like:In the output,
VP: 1680,1050
gives us information on where we are on the spanning workspace (the matrix of all viewports). This information is only useful if we also have the screen's resolution, since e.g.1680
could be the width of two (unlikely, but still) or one time the screen.Luckily, we can parse out the screen's resolution from the command
xrandr
.Then if we know the screen's x-size is
1680
and we currently are onVP: 1680,1050
, we know we are on the second column in the workspace's matrix. Since we also know the size of the total matrix (DG: 3360x2100
, also from the output ofwmctrl -d
), we know the current matrix includes two columns (3360/1680), and we are on the "last" one.The script will then send an instruction to add a column to the matrix by the command:
This is the principle.
How to calculate the workspaces to remove (example columns)
Once per 10 seconds, the script runs the command to list all currently opened windows, with the command:
This gives us information on the window's position also, looking like:
In the output,
3425
is the x-position of the window. This figure is however relative to the current workspace (left side). To know the absolute position of the window (x-wise) in the workspace-matrix, we have to add the first number of the current viewport information (e.g.VP: 1680,1050
, from the output ofwmctrl -d
).Let's however, for simplicity reasons, assume we are on viewport
1,1
(topleft viewport), so the window's relative position equals its absolute position.Since the screen's resolution is
1680
, we know the window is on column3425/1680
, rounded up, since everything between3360 and 5040
is on the same column in the matrix (between 3 and 4 times the resolution). For proper calculation we usemath.ceil()
(python
)Since the script also practices the rule to always have an extra workspace on the right/below, we need to set the number of columns to the highest value of:
And so the script does :)
The rows are managed in exactly the same procedure.
Technically, there is no shortcut for resizing workspaces, but you can use the simple script bellow and bind it to a shortcut.
.local/share/applications
folder , or wherever you prefer.chmod 755 /path/to/script
For example, I have this setup:
The script is bound to ShiftCtrlAltI. But CtrlAltI could work too. I give full path to the script, which is
And here's how it should look like:
Script
Very simple to use, very simple to set up