Skip to main content

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 the WM_CLASS property of the application’s window to the StartupWMClass entry in the .desktop file. If there’s no StartupWMClass or it doesn’t match the application’s WM_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’s Icon= 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 for StartupWMClass, but sometimes it’s the first.

  • How to fix:

    • Edit your .desktop file.

    • Add or modify the StartupWMClass= line to match the WM_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

  1. 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.

  2. 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, type r, press Enter - this only works on Xorg sessions, not Wayland).

  3. 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;