5

I'm curious how I can get information such as the dimensions of my desktop, which desktop is currently active, and what labels (if any) are set for my desktop enviornment (DE).

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
slm
  • 363,520
  • 117
  • 767
  • 871

1 Answers1

8

Using the tool wmctrl you can get all the above information, specifically the -d switch.

Example

$ wmctrl -d
0  * DG: 5760x900  VP: 0,0  WA: 0,25 1440x826  Workspace 1
1  - DG: 5760x900  VP: 0,0  WA: 0,25 1440x826  
2  - DG: 5760x900  VP: 0,0  WA: 0,25 1440x826  N/A
3  - DG: 5760x900  VP: 0,0  WA: 0,25 1440x826  N/A

Details

One line is output for each desktop, with the line broken up into space separated columns.

  • The first column contains an integer desktop number.
  • The second column contains a '*' character for the current desktop, otherwise it contains a '-' character.
  • The next two columns contain the fixed string DG: and then the desktop geometry as 'x' (e.g. '1280x1024').
  • The following two columns contain the fixed string VP: and then the viewport position in the format ',' (e.g. '0,0').
  • The next three columns after this contains the fixed string WA: and then two columns with the workarea geometry as 'X,Y and WxH' (e.g. '0,0 1280x998').
  • The rest of the line contains the name of the desktop (possibly containing multiple spaces).

Extra Cool things you can do with wmctrl

list info about Window Manager

$ wmctrl -m
Name: compiz
Class: N/A
PID: N/A
Window manager's "showing the desktop" mode: OFF

list active windows

$ wmctrl -l
0x00c00028 -1 grinchy Top Expanded Edge Panel
0x0120001e  0 grinchy x-nautilus-desktop
0x06015fee  0 grinchy saml@grinchy:~
0x06000004  0 grinchy saml@grinchy:~
0x05a000d1  0 grinchy xorg - How can I get information about my virtual desktops via the command line? - Unix & Linux Stack Exchange - Google Chrome

One line is output for each window, with the line broken up into space separated columns.

  • The first column always contains the window identity as a hexadecimal integer.
  • The second column always contains the desktop number (a -1 is used to identify a sticky window).
  • If the -p option is specified the next column will contain the PID for the window as a decimal integer.
  • If the -G option is specified then four integer columns will follow: x-offset, y-offset, width and height.
  • The next column always contains the client machine name.
  • The remainder of the line contains the window title (possibly with multiple spaces in the title).

-p switch example

0x06015fee  0 3278   grinchy saml@grinchy:~
0x06000004  0 3278   grinchy saml@grinchy:~
0x05a000d1  0 4676   grinchy xorg - How can I get information about my virtual desktops via the command line? - Unix & Linux Stack Exchange - Google Chrome

-G switch example

0x06015fee  0 3378 128  941  361  grinchy saml@grinchy:~
0x06000004  0 900  142  947  397  grinchy saml@grinchy:~
0x05a000d1  0 0    50   1440 826  grinchy xorg - How can I get information about my virtual desktops via the command line? - Unix & Linux Stack Exchange - Google Chrome

*NOTE: The -p and -G switches can also be combined!

switching to a different desktop

$ wmctrl -s 2

NOTE: Desktops are numbered starting at 0, so 1 would be the 2nd.

reduce the number of desktops

$ wmctrl -n 3

We now have 3 instead of 4.

$ wmctrl -d | wc -l
3

Now put it back to 4.

$ wmctrl -n 4
$ wmctrl -d | wc -l
4

Closing a window

$ wmctrl -l | grep GVIM
0x02a00003  0 grinchy [No Name] - GVIM

$ wmctrl -c GVIM

$ wmctrl -l | grep GVIM
$ 
slm
  • 363,520
  • 117
  • 767
  • 871