Sunday 9 June 2013

Customize workspace, change wallpaper, execute script on workspace switching

I mostly switch to dfferent workspace and i really like if i could have different settings on different workspace like different wallpaper.
A few solutions like using compiz along with few plugins already exist (i don't know if they work or not because i have never tried them), but they are limited only to wallpaper change. I was looking for something where i can run my own commands on changing workspace.
After googling a lot i found a small C program here. It was really cool (thanks to Isaac) and showing a notification on workspace switching. I had taken C (wsn.c) code from there, modified and added support to call scripts on each workspace change.
You can download modified C code along with the compiled binary here. Binary is compiled on Debian Wheezy Stable x64, it may or may not work on your configuration. If it doesn't work then compile it from C code, don't worry compiling it is quite easy.
Using the wsnd program
USAGE:  wsnd [-s] [-1:script -2:script -3:script -4:script]

OPTIONS
-s           Silent mode. Turn off displaying notification,
             but passed scripts will be executed.
-1:script    Path to script to be executed when workspace 1 activated.
-2:script    Path to script to be executed when workspace 2 activated.
-3:script    Path to script to be executed when workspace 3 activated.
-4:script    Path to script to be executed when workspace 4 activated.

Example
    wsdn -1:~/w1.sh -2:~/w2.sh
Ok, so what we have to do is, just pass path to a script that we want to execute when a particular workspace activated.
In above example i set wsdn to execute w1.sh when i switch to wroskspace 1 and execute w2.sh when i switch to workspace 2. I use only two workspaces so i skipped passing arguments for workspace 3 and 4.
We can also pass -s argument, to stop showing notification on workspace switching but passed scripts will still execute.
What the scripts wh1.sh and wh2.sh doing?
Both scripts are doing three things-
First changing the wallpaper, second mute/unmute sound and third toggling touchpad.
In Workspace-1 i usually do my work, lot of typing etc. so i simply turnoff touchpad and also mute sound.
In workspace-2, i do browsing, listening songs etc., so again i turned touchpad on and unmute sound.
Here is how my wh1.sh looks like
#!/bin/sh

# change wallpaper
xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor0/image-path -s /home/samtech/Pictures/evolution.jpg

# turn off touchpad
synclient touchpadoff=1

# mute sound
/usr/bin/amixer --quiet set Master toggle
You are free to use different commands as per your needs.
Set wsnd to run on startup
Set wsnd to auto start by adding it to 'Application Menu' > Settings > 'Session and Startup'. Do not forget to pass scripts to execute.

Compiling from the code
If attached binary doesn't work for you then you can compile the application with following command
gcc -O2 -o wsnd pkg-config  --cflags --libs libnotify --libs libwnck-1.0 wsn.c
It it doesn's work then try this
gcc -O2 -DWNCK_I_KNOW_THIS_IS_UNSTABLE -o wsnd pkg-config  --cflags --libs libnotify --libs libwnck-1.0 wsn.c
It it complain for libnotify and libwnck not found then run following to install missing libraries
sudo apt-get install libnotify-dev libwnck-dev
Then again try to compile.
Hope it will help you customize your different workspace as you want it to be.
It is working well on my XFCE 4.8, i have not  tested but it should work on other desktops too. On other desktops you may need to use different commands, like for changing wallpaper in GNOME use gconftool-2.

No comments:

Post a Comment