Linux: Get WM_CLASS of Window

Objective: Get the WM_CLASS property of a X Window application on Linux.

The WM_CLASS property and various other properties are used by X window managers to track applications and to retrieve the application’s resources from the resource database.

To retrieve the WM_CLASS property of an application, for example, Google Chrome, run the following command on the terminal.

$ xprop | grep WM_CLASS | awk '{print $4}'

The mouse pointer would have changed after running xprop to indicate that it’s waiting for input. Use the mouse to select the target window. Below is the output that I got after selecting Android Studio IDE window.

$ xprop | grep WM_CLASS | awk '{print $4}'

If you are having issues with application icons not displaying correctly on Linux, most probably it has something to do with window matching using WM_CLASS property. Most Java applications running on Linux are affected by this issue.

You can manually define the WM_CLASS property of an application by modifying the appropriate desktop entry file. Desktop entries for applications, or .desktop files, are generally a combination of meta information resources and a shortcut of an application. These files usually reside in /usr/share/applications or /usr/local/share/applications for applications installed system-wide, or ~/.local/share/applications for user-specific applications. User entries take precedence over system entries.

Below is the config of my android-studio.desktop file that is used to launch Android Studio. The WM_CLASS property is set to jetbrains-studio using the StartupWMClass property.

Without the StartupWMClass line, Docky (application shortcut bar that I am using) was not matching the window properly – both the name and icon were incorrect.

ibrahim = { interested_in(unix, linux, android, open_source, reverse_engineering); coding(c, shell, perl, php, python, java, javascript, nodejs, angular, react); plays_on(xbox, ps4); linux_desktop_user(true); }