Wrong Icon shown in Dock
I faced an interesting problem where the application icon shows correctly in the application's menu but not for the launched application itself in Ubuntu.
This suggests the .desktop
file’s Icon=
entry is valid and correctly pointing to an image file, but something else is interfering with the running application’s icon display. Here are the most common reasons and troubleshooting steps, in order of likelihood:
Application Not Using the .desktop
File’s StartupWMClass
or WM_CLASS
:
-
Explanation: When an application launches, Ubuntu (specifically GNOME Shell, which is the default desktop environment) tries to associate the running window with a
.desktop
file to display the correct icon and group windows. It primarily does this by matching theWM_CLASS
property of the application’s window to theStartupWMClass
entry in the.desktop
file. If there’s noStartupWMClass
or it doesn’t match the application’sWM_CLASS
, the system might fall back to a generic icon or an icon derived from the application’s executable name, even if the.desktop
file’sIcon=
entry is otherwise correct. -
How to check
WM_CLASS
:-
Open a terminal.
-
Run the command
xprop WM_CLASS
. -
Your cursor will change to a crosshair. Click on the window of the running application that isn’t showing the correct icon.
-
The terminal will output something like:
WM_CLASS(STRING) = "firefox", "Firefox"
. The second string (e.g., “Firefox”) is often the one you want forStartupWMClass
, but sometimes it’s the first.
-
-
How to fix:
-
Edit your
.desktop
file. -
Add or modify the
StartupWMClass=
line to match theWM_CLASS
you found. For example:StartupWMClass=Firefox
-
Save the
.desktop
file. -
Log out and log back in, or run
gtk-update-icon-cache /usr/share/icons/gnome/ -f
(or the appropriate icon theme path) and then restart the application
-
Troubleshooting Steps (Recommended Order):
-
Most Likely Fix: Check and set
StartupWMClass
in your.desktop
file. This resolves the majority of these issues.-
xprop WM_CLASS
on the running window. -
Add/modify
StartupWMClass=
in your.desktop
file. -
Save, then log out/in or restart the application.
-
-
Clear Icon Caches:
-
sudo gtk-update-icon-cache /usr/share/icons/hicolor/ -f
-
rm ~/.cache/icon-cache.kcache
-
Log out and log back in, or restart GNOME Shell (
Alt + F2
, typer
, pressEnter
- this only works on Xorg sessions, not Wayland).
-
-
Verify Icon Path and Permissions: Double-check the
Icon=
path and ensure the icon file is readable.
My fixed .desktop
file
[Desktop Entry]
Name=LMStudio
StartupWMClass=LM Studio
Exec=/home/tipu/Applications/LM-Studio.appimage
Icon=/home/tipu/icons/lm-studio.png
Terminal=False
Type=Application
Categories=Development;Utility;