10

I generally see the syntax for setting the terminal title as (something like):

echo -e '\e]0;Some Title\a'

But I noticed this answer used 2 instead of 0, which prompted me to do a little more digging. According to this document you can actually set both the "icon name" and the "window title" with this syntax:

·  ESC]0;stringBEL -- Set icon name and window title to string

·  ESC]1;stringBEL -- Set icon name to string

·  ESC]2;stringBEL -- Set window title to string

   where ESC is the escape character (\033), and BEL is the bell
   character (\007).

Printing one of these sequences within the xterm will cause the window
or icon title to be changed.

But it doesn't go on to explain what exactly it means by "icon title" or "icon name". When I try it out I don't see any difference between 0 and 2, and 1 doesn't appear to do anything.

So what is the "icon title", and what is supposed to happen when 0 or 1 is called?

1
  • If nothing is happening, it might be that your local PS1 variable is causing things to revert back. You can test this by adding ; sleep 10s to the end of whichever command you're using to change a title/name. If you do that, you'll see the new title/name for 10 seconds, then it will revert back to the old. (I can't remember where I picked that up.) If that's the problem, try something like the solution at https://unix.stackexchange.com/a/566383/291375. Commented Feb 3, 2022 at 5:53

3 Answers 3

6

This is X11 code perhaps ignored or unimplemented by modern Window Managers. Luckily, I don't run a modern Window Manger, so with FVWM on OpenBSD, I can set the icon name to blah, then minimize that xterm:

lo a screenshot

Which produces an icon with that name.

1
  • Hi @thrig, I also use fvwm, and would like to assign an icon to a class of xterm's, that's visible in the RightPanel, could you please in more detail explain how you generated the icon you're dipslaying?
    – Leo Simon
    Commented May 6, 2021 at 23:33
3

The Xterm Title HOW-TO is simplified. From XTerm Control Sequences

OSC Ps ; Pt ST
OSC Ps ; Pt BEL

        Ps = 0  -> Change Icon Name and Window Title to Pt.
        Ps = 1  -> Change Icon Name to Pt.
        Ps = 2  -> Change Window Title to Pt.

(OSC could be escape], or 0x9d).

Some applications (such as screen) know about the three possibilities (0=both, 1=icon, 2=title), though it took a while to get to that point (see fix).

According to the XStoreName manual page

The XStoreName() function assigns the name passed to window_name to the specified window. A window manager can display the window name in some prominent place, such as the title bar, to allow users to identify windows easily. Some window managers may display a window's name in the window's icon, although they are encouraged to use the window's icon name if one is provided by the application. If the string is not in the Host Portable Character Encoding, the result is implementation dependent.

The call sets a window manager property. Many window manager properties are optional, allowing for different implementations. The ICCM documents WM_ICON_NAME as

The WM_ICON_NAME property is an uninterpreted string that the client wants to be displayed in association with the window when it is iconified (for example, in an icon label). In other respects, including the type, it is similar to WM_NAME. For obvious geometric reasons, fewer characters will normally be visible in WM_ICON_NAME than WM_NAME.

Clients should not attempt to display this string in their icon pixmaps or windows; rather, they should rely on the window manager to do so.

The encoding mentioned for XStoreName is a clue. It is not UTF-8. After several years (around the early 2000s), of introducing Unicode strings into applications designed for ISO-8859-1 (Latin-1), e.g., this gem, some window manager developers came up with Extended Window Manager Hints to rectify the situation and provide for extensions. It uses different window properties, e.g., _NET_WM_ICON_NAME

The Client SHOULD set this to the title of the icon for this window in UTF-8 encoding. If set, the Window Manager should use this in preference to WM_ICON_NAME.

Again, this is optional. Desktop developers may have different ideas about how to show icons, and graphic images seem to have gotten more attention, usually at the expense of accessibility. However, it is still part of the standard, used by a few window managers such as fvwm, twm, ctwm. If someone were to make an accessible version of KDE or GNOME, they might use this property.

4
  • Note that I often see them escaped with the either the octal escape sequences or (what I'll call) the one-letter escape sequences. For the octal escape sequences, this means (for the three): \033]0;string\007 , \033]1;string\007 , and \033]2;string\007. For the one-letter escapes this means: \e]0;string\a , \e]1;string\a, and \e]2;string\a. Heck, you might be able to use hex escapes, as in \x1d]0;string\x07 , \x1d]1;string\x07 , \x1d]2;string\x07 source, though I haven't tried it.. Commented Feb 3, 2022 at 17:16
  • 1
    @bballdave025 The one-letter escape sequence might not be supported everywhere. For example, the POSIX echo and printf support \a, but not \e; Zsh echo and printf support both. Commented May 17, 2022 at 7:52
  • 1
    I guess POSIX standard inherits \a from C standard. C doesn’t support \e natively. Commented May 17, 2022 at 7:59
  • Thanks, @Franklin_Yu. Scratch the one-letter escapes for portability. Thanks for the explanation with the C standard. That makes it very clear. Commented May 28, 2022 at 17:03
2

Some terminal emulators (iterm2, tmux) may use the "icon title" variant for the tab title so that the tab and window title can be different.

Unfortunately this is not the case for gnome-terminal, xfce4-terminal, lxterminal etc.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .