XFCE Workspace Desktop Rotation

Linux offers a wonderful feature called workspaces: I can have an arbitrary number of desktops, and arrange windows however I want. One could have a music player running fullscreen, another can run GIMP, and a third could have a tutorial. Keyboard shortcuts let me jump between workspaces. In effect, multiple workspaces give me four screens for the price of one.

One problem: it's hard to tell the workspaces apart. Setting different backgrounds per workspace would help (and be pretty nifty), but XFCE doesn't support that by default.

I've been looking to solve this conundrum for a while. The first time I tried, I wrote a script to grab NASA's image of the day, but got stuck at switching desktops with workspaces: XFCE doesn't allow the shortcut for switching workspaces to be assigned to another script. For a while, I was content with the rotation of amazing NASA images. But I have time again, and wanted to finish.

Looking around online, I found a program called wmctrl. It offers control over workspaces for all major Linux window managers. The command

wmctrl -s 1
switches to workspace one. Now I just need to write some code to change the background, and I can move control over switching workspaces from XFCE to wmctrl. (I'll politely ask XFCE to stop listening for a keyboard shortcut to switch workspaces, and call my script on that newly freed shortcut.)

Switching backgrounds is a piece of cake: I just need to call:

xfdesktop --reload

The only thing left is to change the backgrounds. The easiest way to do this is with lists. XFCE supports background lists, which are nothing more than text lists of images.

Switching out background lists is trivial, so I told xfce to watch a file that I'd edit on the fly. The complete code is below.

#Ben Nitkin, Winter 2013

#Set desktop
wmctrl -s $1
#Set new background list
ln -f ${DIR}/${1}/imagelist ${DIR}/imagelist
#Refresh the lists.
xfdesktop --reload

DIR is a directory. It contains numbered directories, one for each workspace (1, 2, 3, and 4). Within each of those directories are images and an imagelist (called imagelist). When I call this script, it switches to the new workspace, links the appriate image list into the main directory, then reloads XFCE. XFCE is using ${DIR}/imagelist as its list of images, so when it refreshes, it draws from a different list of images.

With the directory structure set up, go into XFCE config > Window Manager > Keyboard, and remove the shortcuts for switching workspaces. Then go into config > keyboard and add a shortcut for each desktop. On my machine, the shortcut <Primary><F1> calls:

switch.sh 1

Refactoring this script for single images should be trivial; if you're interested in more details, email me!