5

from man wmctrl:

wmctrl is a command that can be used to interact with an X Window manager that is compatible with the EWMH/NetWM specification. wmctrl can query the window manager for information, and it can request that certain window management actions be taken.

The question specifically

The wmctrl -d command can be used to get information about desktops (viewports/workspaces), The wmctrl -lG command lists all windows, including their geometry information.

How can I (in Unity versus other window managers):

  • get an overview of the workspaces and how they are arranged?
  • find out which is the current workspace?
  • find out where a window is located in an absolute sense?
  • list windows that are on the current workspace?

from the command line, using these two commands?

Background information


The wmctrl -d command
lists desktops. On (e.g.) Xubuntu, when I run wmctrl -d, I can clearly see in the output which is the current workspace, and the screen's resolution (DG) on the workspace(s).

0  - DG: 1024x600  VP: N/A  WA: 0,31 1024x569  1
1  - DG: 1024x600  VP: N/A  WA: 0,31 1024x569  2
2  - DG: 1024x600  VP: N/A  WA: 0,31 1024x569  3
3  * DG: 1024x600  VP: 0,0  WA: 0,31 1024x569  4

The current workspace is marked with a *.

On Unity however, the output of wmctrl -d shows only one (very large) workspace, marked with a *, no matter which is the current "workspace", e.g.:

0  * DG: 3360x2100  VP: 1680,0  WA: 65,24 1615x1026  N/A

The wmctrl -lG command
from man wmctrl:
-l: List the windows being managed by the window manager.
-G-: Include geometry information in the output of the -l action

When I run wmctrl -lG on (e.g.) Xubuntu, with a mousepad window on each workspace:

0x03400003  0 241  197  533  244  jacob-1001PX Untitled 1 - Mousepad
0x03400197  1 299  222  533  244  jacob-1001PX Untitled 2 - Mousepad
0x034001be  2 236  201  533  244  jacob-1001PX Untitled 3 - Mousepad
0x034001e3  3 283  228  533  244  jacob-1001PX Untitled 4 - Mousepad

The information is quite understandable; from the second column, we know the workspace the window is on, its position (x,y, column 3/4) and the size (x,y, column 5/6). The position is given in relation to the worspace it is located on.

On Unity however, it is quite a different story. When I have four workspaces and I open a gedit window on every one of them:

0x03c03b81  0 468  -884 875  741  jacob-System-Product-Name Niet-opgeslagen document 1 - gedit
0x03c03e74  0 369  164  1111 741  jacob-System-Product-Name Niet-opgeslagen document 2 - gedit
0x03c03f8e  0 -1269 214  1111 741  jacob-System-Product-Name Niet-opgeslagen document 3 - gedit
0x03c00085  0 -1376 -917 1111 741  jacob-System-Product-Name Niet-opgeslagen document 4 - gedit

Some windows have negative coordinates, some (may) have coordintates that exceed my screen's resolution.

1 Answer 1

4

Viewports versus workspaces

As pointed out in this answer, there is an essential difference between Compiz/Unity and other window managers.

If we look at Xubuntu (XFCE), all workspaces are stand alone spaces. All we need to know is the workspace a window is on, and the x and y coordinates. Basically, there is no matrix in which the workspaces are ordered, apart from the "lineair" order 1, 2, 3 etc.

This is different in Unity, where there is actually only one workspace. The (spanning) workspace is divided in a number of sections, called viewports. These viewports are arranged in rows and columns.

That way it is possible that one window is partially visible on all viewports:

enter image description here

unlike workspaces:

enter image description here

Differences in the output of wmctrl -d and how to interpret

To understand the output of wmctrl -lG, we should understand its "anatomy":

enter image description here

  1. desktop number (first = 0)
  2. current desktop mark ("*" if it is the current desktop (workspace), "-" if not)
  3. desktop geometry (the size of the desktop x-y)
  4. viewport position (position on the desktop; see Unity)
  5. workarea geometry as ("usable" size of the desktop, minus panels etc.; first column is px from left/top)
  6. name of the desktop (possibly containing multiple spaces)

Since Unity only has one workspace, the output always shows a * on [2]. How do we know how the viewports are arranged and what is the current viewport?

The information is in VP: 1680,0 ([4]). Not simply as a viewport number, but as an x and y coordinate. These coordinates can be zero or x*the screen's resolution. To know how the viewports are set up, we will need to know the screen's reolution as well (with the help of xrandr).

How to find out:

  • how many viewports are there currently and how are they arranged:

    Looking at the DG: 3360x2100 in the "Unity" example, and knowing that our screen's resolution is 1680x1050, we can conclude there are two columns of viewports (3360/1680) and two rows (2100/1050).

  • which is the current workspace:

    An example
    The screen has a resolution of 1680x1050. The viewport information sais VP: 1680,0. Cordinates are displayed as the left upper corner, So we are on the second column, first row.

  • where a window is located in an absolute sense:

    Once we know which viewport is the current one, we can localize the windows, looking at their coordinates in the output of wmctrl -lG [3]:

enter image description here

  1. window - id
  2. desktop number (on Unity: always 0 as pointed out)
  3. window coordinates, from the perspective of the current viewport (x-y)
  4. window size, from the perspective of the (w-h)
  5. computer name
  6. window name

    We can simply locate the window, with the origin at the left top of the current viewport.

    Below an example of a screen resolution of 1680x1050, viewports 2x2:

    window coordinates from the perspective of viewport 1

    enter image description here

    window coordinates from the perspective of viewport 4

    enter image description here

    • which are the windows on the current workspace:

    With the information above and the help of wmctrl -lG (the window coordinates, section [3]), quite simple:

    if

    1. a window's x-coordinate is between 0 and the screen's (horizontal) resolution, and
    2. a window's y-coordinate is between 0 and the screen's (vertical) resolution

    then a window is located on the current viewport.

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.