I’ve got a very nice Moka+Numix icon theme which works well with my dock and Nautilus, but unfortunately Openbox wasn’t picking up on it (not surprisingly, since the icon theme is a GNOME thing). As a result, the icons in Openbox’s Alt-Tab Switcher were inconsistent with the rest of my desktop.
It turns out that Openbox was using the icon specified in the X properties of the window. This is set by the application itself. Fortunately, there’s a rather useful xseticon
script made by Paul “LeoNerd” Evans that allows for the modification of these icons. Together with Devil’s Pie, a look at the XDG Icon Theme Specifications, and small script, this allowed me to automatically set the icon for all windows, so that now everything is nice and consistent.
This requires xseticon
, python-xdg
, and xprop
, all of which are in the Debian repositories (Wheezy).
The Devil’s Pie configuration file is:
1 |
(spawn_sync "$HOME/.local/bin/set-xdg-icon" (str (window_xid))) |
Replace $HOME
with your home directory.
The ~/.local/bin/set-xdg-icon
looks like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
#!/bin/bash # Requirements: xseticon, pyxdg, xprop # The application files to search through SEARCH_FILES="$HOME/.local/share/applications/*.desktop /usr/share/applications/*.desktop /usr/local/share/applications/*.desktop" # The name of this script ME=`basename $0` # Print help message and exit help() { echo "usage: $ME xid" echo "Assigns an XDG icon (specified by the current theme) to the window given by xid" echo exit 0 } # Check for options while getopts h OPT; do case "${OPT}" in h) help ;; esac done shift $(($OPTIND-1)) # If no id is given, then print usage if [ "$#" == "0" ]; then help; fi # Determine the xid xid=$1 # Determine the WM_CLASS of the window, if possible result=`xprop -id "$xid" WM_CLASS` # If the xprop returned a nonzero exit status, then we need to exit too if [ "$?" != "0" ]; then echo "E: Could not get WM_CLASS for the window with xid $xid. Either it doesn't exist, or it doesn't have WM_CLASS set." exit 1 fi # Extract the first WM_CLASS class=`echo "$result" | sed 's/^WM_CLASS(STRING) = "\([a-zA-Z0-9_-]\+\)".*$/\1/'` # Find a .desktop file with StartupWMClass=$class, if one exists file=`grep --files-with-matches --no-messages "StartupWMClass[[:space:]]*=[[:space:]]*$class" $SEARCH_FILES` # If too many files (ie more than one) were found, then exit if [[ "$file" == *\n*\n ]]; then echo "E: More than one matching .desktop file for the window with xid $xid (WM_CLASS: '$class')" exit 1 fi # If we couldn't find a file, then exit if [ ! -e "$file" ]; then echo "E: Could not find a matching .desktop file for the window with xid $xid (WM_CLASS: '$class')" exit 1 fi # Extract the icon name from the .desktop file icon=`grep '^Icon[[:space:]]*=.*$' "$file" | sed 's@^Icon *= *\([a-zA-Z0-9./_ (),-]\+\)$@\1@'` # If $icon is a PNG that exists then use that, otherwise determine the icon file from the theme if [ -e $icon ] && [ "${icon##*.}" == "png" ]; then iconfile=$icon else # Determine the current icon theme theme=`gsettings get org.gnome.desktop.interface icon-theme` # Has quotes # Determine the icon file using the XDG Icon File Specification (http://standards.freedesktop.org/icon-theme-spec) # Try various sizes, preferring the larger ones for i in 256 128 64 32; do iconfile=`python -c "from xdg import IconTheme; print IconTheme.getIconPath('$icon',$i,$theme,['png'])"` if [ -e "$iconfile" ]; then break; fi done # If this has failed, then $icon probably doesn't have an icon file if [ ! -e $iconfile ]; then echo "E: Could not find icon file for icon name '$icon'. Window xid: $xid, WM_CLASS: '$class'" exit 1 fi fi # Finally, set the the window icon to $iconfile xseticon -id "$xid" "$iconfile" exit 0 |
This can certainly be adapted for use with KDE, by just using whatever analogue of gsettings
KDE has when determining the icon theme.
Note that some .desktop
files don’t have the StartupWMClass
set. In order to get the corresponding applications to work with this, you’ll need to add it with the WM_CLASS found by xprop
‘ing the appropriate window.
Here’s a Gist.