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.
1 |
$ 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.
1 2 |
$ xprop | grep WM_CLASS | awk '{print $4}' "jetbrains-studio" |
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.
1 2 3 4 5 6 7 8 9 10 11 12 |
[Desktop Entry] Version=1.0 Type=Application Name=Android Studio Exec="/home/ibrahim/opt/android-studio/bin/studio.sh" %f Icon=/home/ibrahim/opt/android-studio/bin/studio.png Comment=Android Studio Categories=Development;IDE; Terminal=false StartupNotify=true StartupWMClass=jetbrains-studio X-Desktop-File-Install-Version=0.22 |
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.