Skip to main content

Nico's blog

The importance of window to desktop file mapping

In my last post I talked about what application developers can do to fix their applications not showing up correctly in Plasma’s task manager. I motivated this by the fact that we need this on Wayland to display the app’s icon. However icons are not the only reason why correctly mapping windows to desktop files is important. It brings substantial benefits even on X11:

  • Application titles: In addition to showing the window title Plasma’s task manager also shows the application name (the Name key in the desktop file). If the desktop file can’t be determined it falls back to the executable name, which isn’t particularly nice.
  • Jumplist actions: Desktop files allow apps to specify additional application actions. For example Firefox allows you to open a new window or a new private browsing window by right-clicking on the entry in the task manager.
  • Media player controls: Plasma’s task manager allows to control application’s media playback. You can e.g. pause a music player by right-clicking on its task manager entry. For this to work the window has to be matched to the MPRIS player instance, which happens based on the desktop file name.
  • Recent files: Plasma’s task manager shows you recently used files for an application in the context menu for an application and allows to open that file in the app. This also relies on the desktop file mapping.

Now that we established why it is important to map a window to a desktop file, how is it done?

On Wayland the xdg-shell protocol, which is responsible for application windows, has builtin support for passing a desktop file name in form of set_app_id.

On X11, it’s more complicated.

For Qt applications the plasma-integration Qt Platform Theme sets a KDE-specific window property that contains the desktop file name. The task manager reads this property and handles it accordingly.

GTK apps have a very similar window property, named _GTK_APPLICATION_ID. However, until now Plasma did not use this information at all! Beginning with Plasma 5.25 the task manager will take _GTK_APPLICATION_ID into account, which fixes matching Gedit and other apps.

When neither _KDE_NET_WM_DESKTOP_FILE nor _GTK_APPLICATION_ID are set the task manager will use a wild guessing game heuristic to try and match the window to a desktop file. It takes into account things like the X11 window class, executable name, and Name and Exec from the desktop file. Sometimes this works well, sometimes it doesn’t.

These are just some examples why this mapping is so important. In a future post I will talk about an improvement to Plasma’s task manager in Plasma 5.24 that also requires this mapping to work.

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