7

In light of https://unix.stackexchange.com/a/254854/674 and https://unix.stackexchange.com/questions/458895/how-can-i-bring-a-background-gui-job-to-the-front-of-my-desktop, there is an example from manpage of xdotool

# Activate google-chrome when you move the mouse to the bottom-left corner: 
xdotool behave_screen_edge bottom-left search --class google-chrome windowactivate

The manpage says

--class Match against the window class.

--classname Match against the window classname.

What are "class" and "classname"?

What possible values do they have?

How can I find out the class and classname of a window?

Thanks.

7

Under X11 windows have XWindowdAttributes structure and XClassHint structures properties from which applications get information about windows. Specifically the last one is responsible for the WM_CLASS property, two comma-separated strings, which can be seen easily via xprop command. For instance, Chrome has

WM_CLASS(STRING) = "google-chrome", "Google-chrome"

These two are documented as:

  • A string that names the particular instance of the application to which the client that owns this window belongs. ...
  • A string that names the general class of applications to which the client that owns this window belongs. Resources that are specified by class apply to all applications that have the same class name....

Thus, for example Hangouts extension for Chrome, has same class name, but different instance name:

$ xprop | grep 'CLASS'
WM_CLASS(STRING) = "crx_nckgahadagoaajjgafhacjanaoiihapd", "Google-chrome"

This allows tools such as xdotool search all windows of particular application type, or specific window instance. For instance, this also can be useful property for something like docks that group windows under the same icon of an application.

In particular for xdotool, classname corresponds with the first string, and class corresponds the second string. In my example with Chrome and Hangouts apps:

$ xdotool search -classname crx_nckgahadagoaajjgafhacjanaoiihapd
96469129

$ xdotool search -class Google-chrome
96469069
109051905
109051907
96468993
96469129
109051912
109051924

This also can be apparent from looking at the source code. Let's focus on classname for example. In the cmd_search.c we have a search struct built up, which has a search mask property(lines 171 to 173).

This gets passed to xdo_search_windows function defined in xdo_search.c , which in turn calls check_window_match, that in turn goes to _xdo_match_window_classname, which finally ends up retrieving both structures mentioned in the beginning of this answer with the standard Xlib functions XGetWindowAttributes and XGetClassHint.


Side note: Gtk apps apparently always create a small parent window with a child window, which means you may get confusing results when searching for a specific window.

  • Thanks. Are "class name" and "instance name" given by xprop correponding to "class", "classname" or "name" in xdotool search? – Tim Jul 28 '18 at 19:23
  • @Tim Yes, they are. I've updated my answer slightly. See the update. – Sergiy Kolodyazhnyy Jul 29 '18 at 3:40
  • @Michael It may to do with Ubuntu using Wayland instead of X11 in more recent versions. Ideally, it should wait for you to select a window with the mouse - then the output appears. If you do that, but there's still no output - likely because your system uses Wayland – Sergiy Kolodyazhnyy Jun 25 at 3:14
4

A class would be that like urxvt which actually contains both urxvt and rxvt which is the unicode rxvt terminal. The classname breaks those up into the actual names. I will show an example below.

I have 4 rxvt terminal windows open.

terrance-Linux:~$ xdotool search -class rxvt
130023435
127926283
125829131
132120587

terrance-Linux:~$ xdotool search -class urxvt
130023435
127926283
125829131
132120587

terrance-Linux:~$ xdotool search -classname urxvt

terrance-Linux:~$ xdotool search -classname rxvt
130023435
127926283
125829131
132120587

Then when I launched a urxvt terminal this is what I got.

terrance-Linux:~$ xdotool search -classname urxvt
140509193

Using the xprop application we can click on the windows and it will tell us the WM_CLASS(STRING). The first is the classname and the second is the class.

Example:

Running the command and clicking on a RXVT terminal window:

terrance-Linux:~$ xprop | grep WM_CLASS
WM_CLASS(STRING) = "rxvt", "URxvt"

Same command clicking on a URXVT window:

terrance-Linux:~$ xprop | grep WM_CLASS
WM_CLASS(STRING) = "urxvt", "URxvt"

Same command again clicking on a Google Chrome browser:

terrance-Linux:~$ xprop | grep WM_CLASS
WM_CLASS(STRING) = "google-chrome", "Google-chrome"

Clicking on a xfce4-terminal window:

terrance-Linux:~$ xprop | grep WM_CLASS
WM_CLASS(STRING) = "xfce4-terminal", "Xfce4-terminal"

Clicking on a gnome-terminal window:

terrance-Linux:~$ xprop | grep WM_CLASS
WM_CLASS(STRING) = "gnome-terminal-server", "Gnome-terminal"

Clicking on a Firefox window (which is different):

terrance-Linux:~$ xprop | grep WM_CLASS
WM_CLASS(STRING) = "Navigator", "Firefox"

Hope this helps spread some light on the differences.

  • Thanks. I would like to see some general definition of the concepts of "class" and "classname". I can't generalize from your example to other examples. – Tim Jul 27 '18 at 23:20
  • @Tim Updated the answer to show how to get the classname and class of a window. Not too much different between the two, but it should show some differences at least. – Terrance Jul 27 '18 at 23:54

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.