Can I set up my xfce workspaces differently?
If we limit the setup to have a different set of launchers per desktop it is not very complicated. What we need is a script, running in the background to keep track of the current workspace and automatically alter the set of launchers accordingly.
1. A set of launchers per workspace
Let's say I have four workspaces, I want the following launchers to be available on the different workspaces:
workspace 1 > workspace 2 > workspace 3 > workspace 4 >
- Workspace 1: Firefox / Idle
- Workspace 2: Gcolor2 / Gimp Image Editor / Inkskape
- Workspace 3: Abiword / Gnumeric / Mail Reader
- Workspace 4: Mines / Sudoku
How to set up
-
The script uses
wmctrl
:sudo apt-get install wmctrl
-
In your home directory (not in a subdirectory, but on the "first" level), create a directory (exactly) named:
desktop_data
inside this directory, create for each of your desktops, a folder named (exactly):
desktop_1 desktop_2 desktop_3 desktop_4
Create launchers for all applications (for all workspaces) on your desktop and copy them to the corresponding folders.
-
Copy the script below into an empty file, save it as
change_launchers.py
. Test-run it by running in a terminal window the command:python3 /path/to/change_launchers.py
If all works fine, add it to your startup applications
The script
#!/usr/bin/env python3 import subprocess import os import time import shutil home = os.environ["HOME"] desktop_dir = home+"/"+"Desktop" data_dirstr = home+"/desktop_data/desktop_" get = lambda cmd: subprocess.check_output(["/bin/bash", "-c", cmd]).decode("utf-8") def get_desktop(): return [l for l in get("wmctrl -d").splitlines() if "*" in l][0].split()[-1] while True: curr_dt1 = get_desktop() time.sleep(1) curr_dt2 = get_desktop() # alter the set of launchers when workspace changes if not curr_dt1 == curr_dt2: datafolder = data_dirstr+curr_dt2 for f in [f for f in os.listdir(desktop_dir)if f.endswith(".desktop")]: subject = desktop_dir+"/"+f os.remove(subject) for f in os.listdir(datafolder): subject = datafolder+"/"+f; target = desktop_dir+"/"+f shutil.copyfile(subject, target) subprocess.call(["/bin/bash", "-c", "chmod +x "+target])
Note
In different localized versions of Ubuntu, the name of the "Desktop" folder may differ (In Dutch: "Bureaublad"). If in your Ubuntu version the name of the desktop folder is not "Desktop", change it in the line:
desktop_dir = home+"/"+"Desktop"
2. Extending possibilities, launchers and links
If we add a few lines to the script, the setting-per-workspace options can be extended with a altering set of links to directories:
On one workspace we have a e.g. a link to the Documents folder, combined with launchers of office applications:
On another workspace we have a link to the Pictures folder, combined with launchers of Image editors:
How to setup
The setup is pretty much the same as in option 1, but additionally, in the data folders (see option 1), create links to folders (using ln -s <source> <destination>
) you'd like to be available on the corresponding workspace:
The script
#!/usr/bin/env python3
import subprocess
import os
import time
import shutil
home = os.environ["HOME"]
desktop_dir = home+"/"+"Desktop"
data_dirstr = home+"/desktop_data/desktop_"
get = lambda cmd: subprocess.check_output(["/bin/bash", "-c", cmd]).decode("utf-8")
def get_desktop():
return [l for l in get("wmctrl -d").splitlines() if "*" in l][0].split()[-1]
while True:
curr_dt1 = get_desktop()
time.sleep(1)
curr_dt2 = get_desktop()
# alter the set of launchers & links when workspace changes
if not curr_dt1 == curr_dt2:
datafolder = data_dirstr+curr_dt2
for f in os.listdir(desktop_dir):
subject = desktop_dir+"/"+f
if os.path.islink(subject) or subject.endswith(".desktop") :
os.remove(subject)
for f in os.listdir(datafolder):
subject = datafolder+"/"+f; target = desktop_dir+"/"+f
if os.path.islink(subject):
os.symlink(os.readlink(subject), target)
else:
shutil.copy(subject,target)
Some other desktop environments (like KDE) offer this natively, but this is only partially supported in XFCE.
What works natively in XFCE:
- You can set a different wallpaper on each workspace, this is fully supported and can be easily configured through the workspace settings GUI.
- You can affect a panel to a specific workspace, but AFAIK there is no GUI option allowing to configure this but the script below will take everything in charge.
The solution I adopted:
- Create a new panel for each workspace. You can also create supplementary global panels which will be displayed on all workspaces (some elements like the notification bar can be added only once, so the only way to have it visible on every workspace is to add it to a global panel).
- Configure and run the script below to distribute each local panel to their own workspace.
- Configure XFCE to run the script at each start.
- Configure the panels as you will.
Contrary to the other answer, this script will not run as an endless loop fetching the status each and every second. It runs only once during the session opening in order to associate each local panels to their own workspace, afterwards all the rest is handled natively by the window manager.
#! /bin/sh
# First panel to move
start=2
# Number of panels to move
count=$( wmctrl -d | wc -l )
desk=0
for winid in $( wmctrl -l | grep 'dom0 xfce4-panel$' \
| awk "NR==$start,NR==$(( start + count - 1 )) { print \$1; }" )
do
wmctrl -i -r $winid -b remove,sticky
wmctrl -i -r $winid -t $desk
desk=$(( desk + 1 ))
done
Save this script, for instance as
local-panels.sh
in your home directory, and make it executable (chmod u+x ~/local-panels.sh
)-
Configure the script to suit your needs:
-
$start
: XFCE numbers your panels, this is the number of the fist panel you want to make local. Here the first panel is kept global, and the panel 2 and onward are made local to their own workspaces. -
$count
: The number of panels to make local. By default this is equal to the number of workspaces, ie. one different local panel per workspace. -
$desk
: The first workspace to have a local panel. By default every workspace will have a local panel, but setting this variable to a higher value allows you to have no local panel on the first few workspaces if you would like to.
-
Configure XFCE to automatically start this script upon session opening: go in XFCE Settings Manager > Session and Startup, click on the Application Autostart tab, and then on the Add button to schedule the execution of the script upon each session opening.