Change XTerm's Window Icon

Venerable and versatile XTerm.
Carrying cruft from four decades.

I am a big friend of lightweight terminal emulators - I want them to pop up immediately, without having to run a daemon.
Despite all its baggage, xterm is extremely fast.

Change the Window Icon (pixmap)

The default icon is absolutely hideous.
xterm default icon And it's surprisingly difficult to do something about it. There is extra confusion because traditionally in the X Windowing System, "Icon" refers to a minimised representation of the application and a text label, but not necessarily a small picture (you can see this in my TWM gallery); XTerm's man page mentions "Icons" many times but it never seems to refer to what we want here.

Not working (for me)

Today I found this article.
The accepted solution is twofold:

  • use xseticon, which I don't want because it would require a wrapper script, and even then there'd be a short flicker as the icon changes after you start the xterm.
  • use an .xbm file (those are two tone only, i.e. black/white) and add this to your Xresources:
    xterm*iconPixmap: /path/to/xterm.xbm - but it didn't change the default icon for me.

Working (for me)

However, there's another solution with zero votes, and that one did it.
I quote:

I finally managed to do by setting *iconHint on the xterm resource. The value needs to be a path to an .xpm file WITHOUT the extension.

Unlike .xbm files, .xpm files support colours, and on/off transparency. I imported the file
/usr/share/icons/Papirus/16x16/apps/terminal.svg
into GIMP, made a few small adjustments and exported it to
~/.local/share/icons/terminal_16x16.xpm.
I then added this line to my Xresources:
xterm*iconHint: /home/your_username/.local/share/icons/terminal_16x16 (note that you cannot use $HOME or ~).
It needs to be applied with xrdb -merge /path/to/Xresources.

It works!

The XTerm man page explains:

iconHint (class IconHint)
Specifies an icon which will be added to the window manager hints. Xterm provides no default value.
Set this resource to “none” to omit the hint entirely, using whatever the window manager may decide.
If the iconHint resource is given xterm searches for a pixmap file with that name, in the current directory as well as in /usr/share/pixmaps, if the resource does not specify an absolute pathname. In each case, xterm adds “_48x48” and/or “.xpm” to the filename after trying without those suffixes. If it is able to load the file, xterm sets the window manager hint for the icon-pixmap.

I can confirm that it is possible to use e.g. terminal_16x16.xpm in Xresources, instead of terminal_16x16 - but it must be an .xpm file, no other format seems to work.

You can download my xpm files here (16, 18 and 32px).
terminal xpms

Change the icon for a single window only

Just like you can put the iconHint in your Xresources, you can also add it to a single xterm window via xterm's -xrm option, e.g.:

sh
xterm -xrm "xterm*iconHint: $HOME/.local/share/icons/terminal_music_16x16" -e musicplayer