I'm trying to create one gvim per workspace using this script as a starting point: http://www.openhex.org/notes/2011/1/27/one-vim-server-per-desktops

I know when I first found this script months ago, wmctrl -d listed four workspaces. But now when I try it, it shows only one:

$ wmctrl -d
0  * DG: 7208x1003  VP: 0,0  WA: 0,0 1802x976  Workspace 1

Listing the windows shows that all are on the same desktop, but spaced screen-widths apart:

$ wmctrl -lGx
0x02200003  0 0    1952 1802 27   gnome-panel.Gnome-panel  ned-vbox Bottom Expanded Edge Panel
0x0260001e  0 0    0    1802 1003 desktop_window.Nautilus  ned-vbox x-nautilus-desktop
0x04600004  0 332  140  1169 722  gnome-terminal.Gnome-terminal  ned-vbox Terminal
0x046000c6  0 116  288  1433 512  gnome-terminal.Gnome-terminal  ned-vbox Terminal
0x0480001e  0 388  48   1604 948  gvim.Gvim             ned-vbox .bashrc (~) - GVIM
0x04604c55  0 784  48   1214 948  gnome-terminal.Gnome-terminal  ned-vbox Terminal

This is Ubuntu 10.10 running compiz in a virtual box (which is why the screen is 1802 pixels wide).

Why are my workspaces not visible in wmctrl? They behave properly in the GUI, all the shortcut keys work as they should, and menu items to move windows among workspaces are fine. How do I get wmctrl to show me what I want? Is there another way I can get workspace info accurately?


Compiz implements viewports instead of desktops. You can calculate the number of viewports based on the width of the desktop:

$ wmctrl -d
0  * DG: 7680x1200  VP: 0,0  WA: 0,0 1920x1175  Workspace 1

This says that I have four viewports (7680 / 1920 = 4) and I'm currently looking at the first one. (Unfortunately I don't see a way in wmctrl to reliably fetch the width of a viewport becuase the working area will shrink if you have a panel taking space on an edge. You can either use hard numbers or use xdpyinfo to find the pixel dimensions of your screen.)

To switch to the second viewport:

$ wmctrl -o 1920,0

If you're wanting to parse this stuff in bash, here's an example:

$ dimensions=$(xdpyinfo | awk '$1=="dimensions:"{print $2}')
$ screen_width=${dimensions%x*}
$ info=( $(wmctrl -d | awk '{print $4, $6}') )
$ desktop_width=${info[0]%x*}
$ viewports=$(( desktop_width / screen_width ))
$ current_vp=$(( ${info[1]%,*} / screen_width ))
  • Please note that this considers the viewports to be arranged horizontally only. In case of a 2x2 layout (Unity's default), the screen height needs to be considered also (screen_height=${dimensions#*x}). – blueyed Nov 1 '13 at 13:34

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.