steam-for-linux icon indicating copy to clipboard operation
steam-for-linux copied to clipboard

StartupWMClass in .desktop file

Open 8Kuula opened this issue 5 years ago • 9 comments

Your system information

  • Steam client version (build number or date): Apr 4 2020, at 00:37:27
  • Distribution (e.g. Ubuntu): Ubuntu 18.04
  • Opted into Steam client beta?: No
  • Have you checked for system updates?: Yes

Please describe your issue in as much detail as possible:

Add StartupWMClass variable in .desktop file when shortcut to desktop is created.

I move .desktop file to '~/.local/share/applications' so I can have it on launcher. Now, when launching a game, launcher creates extra icon. Instead of using already one in there.

Attempted this with Stellaris game. I Added manually it to Stellaris.desktop file; StartupWMClass=stellaris

8Kuula avatar Apr 16 '20 05:04 8Kuula

Actually, Steam appears to write some extra properties onto windows. I've noticed a STEAM_GAME property on the window of Steam games, matching the Game ID in the library, for instance, calling xprop on a Counter-Strike: Source window gives me:

STEAM_GAME(CARDINAL) = 240

This luckily isn't unique to Valve games, I've noticed it does that for third party games, too.

I think StartupWMClass won't be sufficient as for instance all games based on Half-Life 2 games, such as Counter-Strike: Source have a WM_CLASS of hl2_linux. What I think Steam should be doing instead, is write the actual desktop file name of the game onto its window.

I thought there was a cross-desktop property for this nowadays but that might have only been for Wayland. I only find a KDE-specific _KDE_NET_WM_DESKTOP_FILE or _GTK_APPLICATION_ID. In any case, when I manually write the corresponding desktop file onto the window, it is properly identified and can be pinned to the task bar:

xprop -id 0x5e00014 -f _KDE_NET_WM_DESKTOP_FILE 8u -set "_KDE_NET_WM_DESKTOP_FILE" "Counter-Strike Source.desktop"

(With 0x5e00014 being the window id of the window, as determined by e.g. xwininfo)

The given desktop file must exist for it to work, obviously.

I made a proof of concept helper application that automatically reads the STEAM_GAME property and finds the corresponding desktop file: https://github.com/kbroulik/steam-x-proper

kbroulik avatar May 30 '20 15:05 kbroulik

I ran xprop WM_CLASS on Path of Exile WM_CLASS(STRING) = "steam_app_238960", "steam_app_238960" Then adding StartupWMClass=steam_app_238960 to my ".local/share/applications/Path of Exile.desktop" correctly groups the game window with the launcher icon i Ubuntu Wayland session.

So this would be perfect to add to Proton games!

ernstp avatar Feb 16 '22 17:02 ernstp

I believe this to still be an issue in 2024.

I've been trying to work out for months why I wasn't able to see the icon of the currently running game in the dock that I'm using (GNOME 46).

Turns out it's due to the fact that Steam doesn't include this required property in the Desktop files. Like others have said, manually adding it myself sorted the issue (although I'll have to go through and do this for all applications manually).

If this could be automatically included, that would be great.

scallaway avatar May 14 '24 07:05 scallaway

I created a simple bash script that adds "StartupWMClass=steam_app_{steam_id}" to .desktop files of steam apps in the current directory:

#!/bin/bash
changed_files=()
for filename in ./*.desktop; do
    printf "\n\n$filename\n"
    steam_icon_line=$(cat "$filename" | grep "Icon=steam_icon")
    
    if [[ -z "$steam_icon_line" ]]
    then
        printf "not a steam shortcut, skipping..."
        continue
    fi
    
    IFS='_'
    read -ra steam_icon_array <<< "$steam_icon_line"
    steam_id=${steam_icon_array[2]}
    
    new_wmclass_line=$(printf "StartupWMClass=steam_app_${steam_id}")
    
    if [[ ! -z $(cat "$filename" | grep "$new_wmclass_line") ]]
    then
        printf "already has StartupWMClass, no changes needed..."
        continue
    fi
    
    printf "adding \"$new_wmclass_line\" to end of file..."
    printf "\n$new_wmclass_line" >> $filename
    changed_files+=("$filename")
done

printf "\n\n\nAdded StartupWMClass to files:\n"
printf "%s\n" "${changed_files[@]}"

I have very little experience in bash so it might be a little sloppy but it seems to work fine (you might want to make a backup to test)

This won't solve the issue for all games unfortunately, as I have noticed that some steam games use the name of the binary file as the wmclass rather than the app id. Valheim uses "valheim.x86_64" and Vampire Survivors uses "VampireSurvivors.exe"

0011FF avatar Jul 19 '24 02:07 0011FF

Valve still haven't fixed it Good that i found this answer

AlofBronco avatar Dec 16 '24 15:12 AlofBronco

It will be nice to have, I guess

x5f3759df avatar Jan 22 '25 21:01 x5f3759df

Any chance you can just consistently put "steam_app_123456", where 123456 is the unique game number on Steam as one of the active WM_Class strings? Or just be smart enough to set StartupWMCLass to a valid value when creating the .desktop file?

This would give everyone on Linux nice icons when they launch their games, and resolve this 5 year old issue.

zquestz avatar Jun 14 '25 02:06 zquestz

KDE doesn't have this problem. I think they don't really fix it because it is more like GNOME problem.

x5f3759df avatar Jun 14 '25 20:06 x5f3759df

It affects at least GNOME, Cinnamon, Xfce and MATE if not others.

zquestz avatar Jun 15 '25 20:06 zquestz

Guys I made a script for this to fix it on gnome app menu automatically. I dont have much knowledge about others DEs, but it could be extended to other use cases. Also, if someone have a idea to cover non proton games would be great (it changes a lot depending on the game)

Check this out

PeppoDev avatar Jul 16 '25 01:07 PeppoDev

I was thinking on the worst case, map all StartupWMClass for native games and hardcode it, maybe

PeppoDev avatar Jul 16 '25 01:07 PeppoDev

I maped some that I have, but its harder if you consider that someone could have this games running natively or with proton (in some cases are just better run on proton)

Dead cells - deadcells Counter strike 2 - cs2 Hollow Knight - hollow_knight.x86_64 Broforce - Broforce.x86_64 Left 4 Dead - hl2_linux

PeppoDev avatar Jul 16 '25 02:07 PeppoDev

It affects at least GNOME, Cinnamon, Xfce and MATE if not others.

I don't know how it really works, but it is not issue on KDE - everything shows using they icons (even when I launch something with wine or proton)

I can relate this with GTK maybe?

x5f3759df avatar Jul 20 '25 07:07 x5f3759df

It's not just about the icon. It also breaks pinning the game to task bar among other things.

kbroulik avatar Jul 20 '25 07:07 kbroulik