Skip to main content

Nico's blog

Fixing Wayland taskbar icons

A common papercut in a Wayland session is entries in the task manager showing a generic Wayland icon instead of the proper application icon. Here’s a KWallet window having a generic icon in the task manager (on the right):

Task manager with generic Wayland icon on the right

This is due to the shell not being able to properly map a window to an application. This breaks more things than just icons, but those are often the first thing that is noticed. Fortunately this is usually very easy to fix, particularly for Qt/KDE apps. I fixed a couple of those over the holidays and now I am writing down what needs to be done so you know what to do the next time you encounter such a case.

Window to application mapping is based on the desktop entry name. That is the filename of the application’s .desktop file in /usr/share/applications/ (without the .desktop extension). For KWallet that would be org.kde.kwalletd5. Make sure your application actually has such a .desktop file installed to /usr/share/applications/. Most graphical apps have one, otherwise you wouldn’t be able to lauch it from the application launcher. However things that are not traditional applications, like services (e.g. KWallet) or helper applications (e.g. the Gwenview importer) don’t always have one yet. To avoid those showing up in the application laucher include NoDisplay=true in the .desktop file.

Now all we need to do is make sure that the window correctly reports the name of the .desktop file to the compositor. For Qt applications that boils down to making sure that QGuiApplication::desktopFileName() is correct. This can be as easy as calling QGuiApplication::setDesktopFileName("org.kde.kwalletd5"). For applications using KAboutData it can even be easier. If you have a KAboutData data("kwalletd5", ...) then QGuiApplication::desktopFileName() will automatically be set to org.kde.kwalletd5. The underlying heuristic can go wrong at times, in which case you need to override it using QGuiApplication::setDesktopFileName(). With those two things fixed KWallet shows a proper taskbar icon now:

Task manager with proper icon on the right

See my next post for more detail on why mapping windows to desktop files is important.

Happy fixing!

© Nicolas Fella, 2024 MastodonNicolas Fella
Powered by Hugo, theme Anubis.