ValveSoftware / steam-for-linux

Issue tracking for the Steam for Linux beta client
4.25k stars 175 forks source link

StartupWMClass in .desktop file #7034

Open 8Kuula opened 4 years ago

8Kuula commented 4 years ago

Your system information

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

kbroulik commented 4 years ago

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

ernstp commented 2 years ago

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!

scallaway commented 6 months ago

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.

0011FF commented 3 months ago

I created a simple bash script that adds "StartupWMClass=steamapp{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"