How to fix the Slack icon in Debian - XFCE?

22 April 2021linux

For a while I've been really annoyed that some applications (Slack, React-Native Debugger and some others installed via .deb) appear without an icon in the XFCE task list panel.

Panel de XFCE without the Slack icon

It seems to be a bug in the app itself or maybe Electron apps on Debian, and it even happens when installed with SnapStore. Either way, it annoys me.

I spent a lot of time researching and learned that the Window Buttons item gets its configuration from programs’ .desktop files. Searching for Slack's file gives:

$ sudo find / -iname "*slack*.desktop"
# Output
/home/veuge/.config/autostart/slack.desktop
/usr/share/applications/slack.desktop

The file in $HOME/.config/autostart is a symlink to /usr/share/applications, so fixing that one is enough. Its content is:

$ cat /usr/share/applications/slack.desktop
# Output
[Desktop Entry]
Name=Slack
StartupWMClass=Slack
Comment=Slack Desktop
GenericName=Slack Client for Linux
Exec=/usr/bin/slack %U
Icon=/usr/share/pixmaps/slack.png
Type=Application
StartupNotify=true
Categories=GNOME;GTK;Network;InstantMessaging;
MimeType=x-scheme-handler/slack;

The interesting line is Icon=/usr/share/pixmaps/slack.png; the image exists and has correct permissions.

$ ls -l /usr/share/pixmaps/slack.png
# Output
-rw-rw-r-- 1 root root 38884 Mar 15 20:12 /usr/share/pixmaps/slack.png

Since config looks good, it seems like an ElectronJS bug, so there must be another fix. I found this Reddit discussion; the second comment says the workaround is to reset the icon after Slack opens, with two steps:

  1. Get Slack window ID using xwininfo.
  2. Set the window icon using xseticon.

Manual process:

$ xwininfo -root -tree | sed -e 's/^ *//'| grep -E '0x.*Slack\s{1}\|' | awk '{print $1}'
# Output
0x4400005
$ xseticon -id 0x4400005 /usr/share/pixmaps/slack.png

After running xtseticon the result is:

Panel de XFCE con icono válido de Slack

As Reddit says, doing this manually every Slack launch is suboptimal, so we tweak Exec in /usr/share/applications/slack.desktop to update icon automatically once Slack is known started.

I replicated the approach from this comment in a script, and then call that script from slack.desktop.

Script breakdown:

# Permite sobreescribir el .desktop
env BAMF_DESKTOP_FILE_HINT=$SLACK_DESKTOP
# Comando que abre Slack minimizado y sin output
/usr/bin/slack -u %U & > /dev/null
# Pausa para esperar que Slack inicie
sleep 10
# Obtiene window ID de Slack y lo guarda en la variable app_wid
app_wid=$(xwininfo -root -tree |sed -e 's/^ *//'|grep -E '0x.*Slack\s{1}\|' | awk '{print $1}')
# Actualiza el ícono dado el window ID y el icono en png.
xseticon -id $app_wid $SLACK_ICON

And finally, the modified slack.desktop:

[Desktop Entry]
Name=Slack
StartupWMClass=Slack
Comment=Slack Desktop
GenericName=Slack Client for Linux
Exec=sh -c /home/veuge/slack-init.sh
Icon=/usr/share/pixmaps/slack.png
Type=Application
StartupNotify=true
Categories=GNOME;GTK;Network;InstantMessaging;
MimeType=x-scheme-handler/slack;

Conclusion

  • This is a workaround to restore Slack/other app icons in XFCE; the real cause should be diagnosed.
  • It works when Slack is started manually or via auto-start.
  • The script can be improved to make it configurable and reusable for other applications with this icon bug. (I'll do that someday).
Portrait of Verónica Clavijo

Verónica Clavijo

Notes on React, React Native, JS, and some other things.