Showing posts with label Gnome. Show all posts
Showing posts with label Gnome. Show all posts

January 26, 2008

Wrapping workspaces in Gnome

One source of frustration sometimes with gnome is that there is no way to wrap workspaces like in KDE, compiz or even the other window managers like XFCE. This means that, if like me you use 'move to workspace right' and 'move to workspace left' frequently while working, it can frustrating not to be able to get back to workspace 1 from the last one in one simple step.

Searching for some way to do this, I came upon this post describing the use of wmctrl to do this. I had never heard of wmctrl before, but it turns out to be pretty cool. So go ahead, install it (sudo aptitude install wmctrl) and now -


raja@eee:~$ wmctrl -d
0 - DG: 800x480 VP: N/A WA: 0,2 800x476 Desk 1
1 - DG: 800x480 VP: N/A WA: 0,2 800x476 Desk 2
2 - DG: 800x480 VP: N/A WA: 0,2 800x476 Desk 3
3 * DG: 800x480 VP: 0,0 WA: 0,2 800x476 Desk 4

raja@eee:~$ wmctrl -s 1 && wmctrl -d
0 - DG: 800x480 VP: N/A WA: 0,2 800x476 Desk 1
1 * DG: 800x480 VP: 0,0 WA: 0,2 800x476 Desk 2
2 - DG: 800x480 VP: N/A WA: 0,2 800x476 Desk 3
3 - DG: 800x480 VP: N/A WA: 0,2 800x476 Desk 4



As we can see, 'wmctrl -d' lists the desktops and places an asterisk to indicate the current desktop. And 'wmctrl -s n' allows us to switch to the desktop n, with the desktops being numbered from 0 onwards.

With this knowledge, it is easy to write a couple of scripts to switch to the desktop on the left and the one on the right, with wrapping enabled.


#!/bin/bash

#ws_wrap_lt.sh

#get number of workspaces
ws=$(wmctrl -d | wc -l)

#current workspace index
cws=$(wmctrl -d | awk '/\*/ {print $1}')

#work space on left
lws=$(($cws-1))

#wrap if required
if [ $lws = -1 ]; then
lws=$(($ws-1))
fi
echo $lws

#change to next workspace
wmctrl -s $lws


and ..


#!/bin/bash

#ws_wrap_rt.sh

#get number of workspaces
ws=$(wmctrl -d | wc -l)

#current workspace index
cws=$(wmctrl -d | awk '/\*/ {print $1}')

#work space on right
rws=$(($cws+1))

#wrap if required
if [ $rws = $ws ]; then
rws=0
fi

#change to next workspace
wmctrl -s $rws


Save the files somewhere and now you can use gconf-editor to map commands to these scripts. Then you can set up a desired key or key combination to run these commands. An option is also to use only one of the scripts and rotate through the workspaces with one key. On the eeepc, I have mapped the 'menu' key to ws_wrap_rt.sh and use just that key to get to any workspace I want. If you use only two workspaces,one key works to toggle the workspaces.