xdotool: what are "class" and "classname" for a window?
Solution 1
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.
Solution 2
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.

Tim
Elitists are oppressive, anti-intellectual, ultra-conservative, and cancerous to the society, environment, and humanity. Please help make Stack Exchange a better place. Expose elite supremacy, elitist brutality, and moderation injustice to https://stackoverflow.com/contact (complicit community managers), in comments, to meta, outside Stack Exchange, and by legal actions. Push back and don't let them normalize their behaviors. Changes always happen from the bottom up. Thank you very much! Just a curious self learner. Almost always upvote replies. Thanks for enlightenment! Meanwhile, Corruption and abuses have been rampantly coming from elitists. Supportive comments have been removed and attacks are kept to control the direction of discourse. Outright vicious comments have been removed only to conceal atrocities. Systematic discrimination has been made into policies. Countless users have been harassed, persecuted, and suffocated. Q&A sites are for everyone to learn and grow, not for elitists to indulge abusive oppression, and cover up for each other. https://softwareengineering.stackexchange.com/posts/419086/revisions https://math.meta.stackexchange.com/q/32539/ (https://i.stack.imgur.com/4knYh.png) and https://math.meta.stackexchange.com/q/32548/ (https://i.stack.imgur.com/9gaZ2.png) https://meta.stackexchange.com/posts/353417/timeline (The moderators defended continuous harassment comments showing no reading and understanding of my post) https://cs.stackexchange.com/posts/125651/timeline (a PLT academic had trouble with the books I am reading and disparaged my self learning posts, and a moderator with long abusive history added more insults.) https://stackoverflow.com/posts/61679659/revisions (homework libels) Much more that have happened.
Updated on September 18, 2022Comments
-
Tim 9 months
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.
-
Tim almost 5 yearsThanks. 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.
-
Terrance almost 5 years@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.
-
Tim almost 5 yearsThanks. Are "class name" and "instance name" given by
xprop
correponding to "class", "classname" or "name" inxdotool search
? -
Sergiy Kolodyazhnyy almost 5 years@Tim Yes, they are. I've updated my answer slightly. See the update.
-
Sergiy Kolodyazhnyy almost 4 years@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