Handle multiple desktop files with different StartupWMClass
Some system installed apps define common/default StartupWMClass in system-installed .desktop file.
Application then create extra .desktop files in user's local applications directory with additional (more specific) StartupWMClass entry.
This patch will match specific window class (WM_CLASS instance name) before matching common window class (WM_CLASS class name).
See: https://www.x.org/releases/X11R7.7/doc/xorg-docs/icccm/icccm.html#WM_CLASS_Property
Specific problem details:
Brave (chromium based) browser has this in /usr/share/applications/brave-browser.desktop
:
[Desktop Entry]
Name=Brave
StartupWMClass=brave-browser
Exec=brave %U
...
App launched with this desktop entry has WM_CLASS(STRING) = "brave-browser", "Brave-browser"
Startup notification in task manager uses icon/title from brave-browser.desktop
When application launches task manager uses icon/title from brave-browser.desktop
Then inside browser you can turn certain web pages into separate applications from menu More Tools > Create Shortcut...
, which in turn can create desktop entries like these:
/home/max/.local/share/applications/brave-efmjfjelnicpmdcmfikempdhlmainjcb-Default.desktop:
[Desktop Entry]
Name=Chrome Remote Desktop
Exec=/usr/lib/brave-bin/brave --profile-directory=Default --app-id=efmjfjelnicpmdcmfikempdhlmainjcb
StartupWMClass=crx_efmjfjelnicpmdcmfikempdhlmainjcb
App launched with this desktop entry has WM_CLASS(STRING) = "crx_efmjfjelnicpmdcmfikempdhlmainjcb", "Brave-browser"
Startup notification in task manager uses icon/title from brave-efmjfjelnicpmdcmfikempdhlmainjcb-Default.desktop
When application launches task manager uses wrong icon/title from brave-browser.desktop
/home/max/.local/share/applications/brave-lacblhgkobmacddcampelknddaiijfge-Default.desktop:
[Desktop Entry]
Name=Microsoft Teams
Exec=/usr/lib/brave-bin/brave --user-data-dir=/home/max/fast/tmp/brave-teams --profile-directory=Default --app-id=lacblhgkobmacddcampelknddaiijfge
StartupWMClass=crx_lacblhgkobmacddcampelknddaiijfge
App launched with this desktop entry has WM_CLASS(STRING) = "crx_lacblhgkobmacddcampelknddaiijfge", "Brave-browser"
Startup notification in task manager uses icon/title from brave-lacblhgkobmacddcampelknddaiijfge-Default.desktop
When application launches task manager uses wrong icon/title from brave-browser.desktop
With this patch when application launches later two entries, task manager matches them to correct .desktop files and accurate icon/title is shown.
NOTE: Alt-Tab window switcher already shows correct icon, if I'm not mistaken that one is handled directly by kwin?