4

I currently have four workspaces ('Main', 'Game', 'Work', 'Overflow'). In a perfect setup, the 'Game' workspace would have shortcuts (either on the Desktop or in a Panel) for Steam and individual games.

Switching to 'Work' should NOT have anything game related, but instead have things like Google Docs links and shortcuts to all of my work-related files.

Are uniquely customized workspaces possible in xfce4?

9
  • Regarding the '14.04' tag that was appended: "Only use this tag if your question is version-specific." Is my question specific to 14.04? @sylvain
    – muad-dweeb
    Feb 5 '15 at 9:09
  • No, that is not in any workspace concept I know about. But what do I know... Maybe you should get in touch with the xfce community and put it on the wishlist: wiki.xfce.org/wish_list
    – mondjunge
    Feb 5 '15 at 9:10
  • @SCK: Since you have this problem on 14.04, having the tag can help diagnosing the issue. It's probably affecting other releases but it's good to have this information to reproduce the problem. Feb 5 '15 at 9:14
  • That is a huge list. @mondjunge It is very strange to me that there are so many requests simply for unique wallpapers on each workspace, but I can't seem to find anyone talking about unique sets of launchers and shortcuts.
    – muad-dweeb
    Feb 5 '15 at 9:21
  • @SCK: yeah, it is strange to me also, but most people tend to do only one thing (beside surfing fakebuzz and tweeter) on their machines, so there is no need to.
    – mondjunge
    Feb 5 '15 at 9:33
4

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 >

enter image description here enter image description here enter image description here enter image description here

  • 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

  1. The script uses wmctrl:

    sudo apt-get install wmctrl
    
  2. 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
    

    <image5>

  3. Create launchers for all applications (for all workspaces) on your desktop and copy them to the corresponding folders.

  4. 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:

enter image description here

On another workspace we have a link to the Pictures folder, combined with launchers of Image editors:

enter image description here

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:

enter image description here

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)
8
  • Hey @jacob, I'm sorry for the delayed response. I've been using the script (Option 1) for over 24 hours now with much success. It is added to my Application Autostart as "Workplace-Respawn". On my system the spawn only takes 1-2 seconds to complete. One important detail though is that the folders within the 'desktop_data' directory should be named desktop_x, where 'x' is whatever name is currently given for each workspace. In my case, this means that my folders are ('desktop_Main', 'desktop_Game', 'desktop_Work', 'desktop_Overflow'). Without that minor tweak it didn't work for me :)
    – muad-dweeb
    Feb 9 '15 at 2:48
  • !["Main"][1] !["Game"][2] !["Work"][3] !["Overflow"][4] <br/> I love this! Great work @jacob. [1]: googledrive.com/host/…) [2]: googledrive.com/host/… [3]: googledrive.com/host/… [4]: googledrive.com/host/…
    – muad-dweeb
    Feb 9 '15 at 3:03
  • Perfect! just curious how you did the tweaking, since the script recognizes the folder (-name) by the current number of the workspace (last character of the output of wmctrl -l). Did you add a line to "convert" the name to the ones you use? Feb 9 '15 at 12:57
  • No, I haven't modified the script itself at all. I only had to change the directory names to get the script to work. My programming proficiency is extremely limited, so I don't have any ideas for why that was required on my end. Sorry :/
    – muad-dweeb
    Feb 9 '15 at 19:00
  • 1
    Wow, thanks! I might polish it a bit further and make it available via Launchpad (ppa). Feb 10 '15 at 6:20
1

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:

  1. 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).
  2. Configure and run the script below to distribute each local panel to their own workspace.
  3. Configure XFCE to run the script at each start.
  4. 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
  1. Save this script, for instance as local-panels.sh in your home directory, and make it executable (chmod u+x ~/local-panels.sh)

  2. 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.
  3. 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.

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.