Google

This document covers the technical aspects of Eterm, including escape sequences it supports, "under-the-hood" descriptions of certain Eterm features, etc. Portions of this document were taken from the XTerm documentation.

Table of Contents

  1. Document Conventions
  2. Symbols
  3. Escape Sequences
  4. Key Sequences
  5. Eterm Extensions, Standards, and Implementations

Document Conventions

Convention Meaning
c A literal. It should be typed as shown.
SYM A symbol. Replace with the proper character. See the symbol table below for a listing of the symbols used and their meanings.
text A parameter. Replace the italicized text with a parameter. The text itself generally describes the type of parameter needed.
[ ... ] Items enclosed in brackets are optional.
{ ... | ... } Items inclosed in braces and separated by pipes indicate that exactly one of the items should be chosen.

Symbols

Symbol Meaning
BEL Bell (Ctrl-G)
BS Backspace (Ctrl-H)
CR Carriage Return (Ctrl-M)
ENQ Enquiry (Ctrl-E), Send Device Attributes (DA). Eterm replies with the string defined by ESCZ_ANSWER in src/feature.h, which is ESC[?1;2c by default. This response indicates a VT100 emulator with Advanced Video Option.
ESC Escape (Ctrl-[)
FF or NP Form Feed or New Page(Ctrl-L)
LF or NL Line Feed or New Line (Ctrl-J)
SI Shift In (Ctrl-O), invokes the G0 (default) character set
SO Shift Out (Ctrl-O), invokes the G1 (alternate) character set
SPC Space
TAB or HT Horizontal Tab (Ctrl-I)
VT Vertical Tab (Ctrl-K)

Escape Sequences

Sequence Function
ESC { ( | ) | * | + | $ } { 0 | A | B } Select ISO 2022 character sets.
  • ( sets the G0 character set
  • ) sets the G1 character set
  • * sets the G2 character set
  • + sets the G3 character set
  • $ sets the Kanji character set
  • 0 uses the DEC Special Character and Line Drawing set
  • A uses the United Kingdom (UK) character set
  • B uses the United States (USASCII) character set
ESC 7 Save cursor (SC)
ESC 8 Restore cursor (RC)
ESC = Application Keypad (SMKX)
ESC > Numeric Keypad (RMKX)
ESC D Index (IND)
ESC E Next Line (NEL)
ESC H Tab Set (HTS)
ESC M Reverse Index (RI)
ESC Z Obselete form of Send Device Attributes (DA), which is ESC [ c
ESC [ [ n ] @ Insert n blank Characters (ICH). Default for n is 1.
ESC [ [ n ] A Cursor Up n times (CUU), default 1
ESC [ [ n ] B Cursor Down n times (CUD), default 1
ESC [ [ n ] C Cursor Forward n times (CUF), default 1
ESC [ [ n ] D Cursor Backward n times (CUB), default 1
ESC [ [ n ] E Cursor Down n times and to first column, default 1
ESC [ [ n ] F Cursor Up n times and to first column, default 1
ESC [ [ n ] G Cursor to Column n (HPA)
ESC [ [ r ; c ] H Cursor Position [row;column] (CUP), default 1;1
ESC [ [ n ] I Move forward n tab stops, default 1
ESC [ [ n ] J Erase in Display (ED)
  • n == 0: Clear Below (default)
  • n == 1: Clear Above
  • n == 2: Clear All
ESC [ [ n ] K Erase in Line (EL)
  • n == 0: Clear to Right (default)
  • n == 1: Clear to Left (EL1)
  • n == 2: Clear All
ESC [ [ n ] L Insert n lines (IL), default 1
ESC [ [ n ] M Delete n lines (DL), default 1
ESC [ [ n ] P Delete n characters (DCH), default 1
ESC [ [ n ] W Tabulator functions
  • n == 0: Tab Set (HTS)
  • n == 2: Tab Clear (TBC), clear current column (default)
  • n == 5: Tab Clear (TBC), clear all
ESC [ [ n ] X Erase n characters (ECH), default 1
ESC [ [ n ] Z Move backward n tabstops, default 1
ESC [ [ n ] ` Same as ESC [ n G (HPA)
ESC [ [ n ] a Same as ESC [ n C (CUF)
ESC [ [ n ] c Send Device Attributes (DA), default of 0 returns "ESC[?1;2c" indicating a VT100 with advanced video option
ESC [ [ n ] d Cursor to line n (VPA)
ESC [ [ n ] e Same as ESC [ n A (CUU)
ESC [ [ r ; c ] f Horizontal and Vertical Position (HVP), default 1;1
ESC [ [ n ] g Tab Clear
  • n == 0: Tab Clear (TBC), clear current column (default)
  • n == 3: Tab Clear (TBC), clear all
ESC [ [ n ] i Printing
  • n == 4: Disable transparent print mode (MC4)
  • n == 5: Enable transparent print mode (MC5)
ESC [ n [ ; n ... ] { h | l }
  • h: Set Mode (SM)
  • l: Reset Mode (RM)
  • n == 4: Insert Mode (SMIR)/Replace Mode (RMIR)
  • n == 20: Automatic Newline (LNM)/Normal Linefeed (LNM)
ESC [ n [ ; n ... ] m Character Attributes (SGR)
  • n == 0: Normal (default)
  • n == 1/22: Turn bold (bright fg) on/off
  • n == 4/24: Turn underline on/off
  • n == 5/25: Turn "blink" (bright bg) on/off
  • n == 7/27: Turn inverse on/off
  • n == 30/40: foreground/background black
  • n == 31/41: foreground/background red
  • n == 32/42: foreground/background green
  • n == 33/43: foreground/background yellow
  • n == 34/44: foreground/background blue
  • n == 35/45: foreground/background magenta
  • n == 36/46: foreground/background cyan
  • n == 37/47: foreground/background white
  • n == 39/49: foreground/background default
ESC [ [ n ] n Device Status Report (DSR)
  • n == 5: Status Report, returns "ESC[0n" ("OK")
  • n == 6: Report Cursor Position (CPR) as "ESC[r;cR"
  • n == 7: Request display name (ignored by default for security reasons)
  • n == 8: Request version number in window title
ESC [ [ t ; b ] r Set Scrolling Region (CSR), where t is the top row and b is the bottom row, defaults to the full screen
ESC [ [ n ] x Request Terminal Parameters (DECREQTPARM)
ESC [ ? n [ ; n ... ] { h | l | s | r | t } DEC Private Modes (shown as set/reset)
  • h: Set Private Mode (DECSET)
  • l: Reset Private Mode (DECRST)
  • s: Save all DEC Private Mode values
  • r: Restore previously-saved DEC Private Mode values
  • t: Toggle Private Mode (rxvt/Eterm extension)
  • n == 1: Application/Normal cursor keys (DECCKM)
  • n == 3: 132/80 column mode (DECCOLM)
  • n == 4: Smooth/Jump scrolling (DECSCLM) [not yet implemented]
  • n == 5: Reverse/Normal video (DECSCNM)
  • n == 6: Origin/Normal cursor mode (DECOM)
  • n == 7: Wraparound mode on/off (DECAWM)
  • n == 9: (X10 Xterm mouse reporting) Do/Don't send mouse coords on button press (see below)
  • n == 10: Toggle menubar on/off (rxvt/Eterm extension)
  • n == 25: Visible/invisible cursor
  • n == 30: Toggle scrollbar on/off (rxvt/Eterm extension)
  • n == 35: Allow/Disallow xterm shift+key sequences (rxvt/Eterm extension)
  • n == 40: Allow/Disallow 80 <--> 132 mode
  • n == 47: Use Alternate/Normal screen buffer
  • n == 66: Application/Normal keypad (DECPAM)
  • n == 67: Backspace key sends BS/DEL (DECBKM)
  • n == 1000: (X11 Xterm mouse reporting) Do/Don't send mouse coords on button press and release (see below)
ESC [ n [ ; n [ ... ] ] t Window Operations
  • n == 1: Un-iconify window
  • n == 2: Iconify window
  • n == 3: Move window. Must by followed by ;x;y
  • n == 4: Resize window. Must by followed by ;height;width
  • n == 5: Raise window
  • n == 6: Lower window
  • n == 7: Refresh window
  • n == 8: Resize text area. Must by followed by ;height;width, with height and width given in characters.
  • n == 11: Report icon state. (not implemented)
  • n == 13: Report window position as ESC[3;x;yt
  • n == 14: Report window size in pixels as ESC[4;height;widtht
  • n == 18: Report text area size in characters as ESC[4;height;widtht
  • n == 20: Report icon name as ESC]LnameESC\
  • n == 21: Report window title as ESC]ltitleESC\
ESC ] n ; string BEL Set Text Parameters
  • n == 0: Change icon name and window title to string
  • n == 1: Change icon name to string
  • n == 2: Change window title to string
  • n == 10: Menubar commands (see below)
  • n == 20: Pixmap commands (see below)
  • n == 39: Set the default foreground color to string
  • n == 49: Set the default background color to string
  • n == 50: Set font to string. rxvt/Eterm extensions:
    • string == "#+n": Change font up by n, default 1
    • string == "#-n": Change font down by n, default 1
    • string empty: Change to font 0
    • string == "#n": Change to font n
ESC ] { l | L | I } string ESC \
  • l: Change window title to string
  • L: Change icon name to string
  • I: Read new icon image from file whose path is string
ESC c Full Reset (RIS)
ESC n Invoke the G2 character set (LS2)
ESC o Invoke the G3 character set (LS3)

Menubar Escape Sequences

The menubar system in Eterm is probably the most complex, convoluted, complicated, and poorly-implemented feature of Eterm. The code, though modified somewhat, is still almost entirely derived from rxvt. It will be rewritten from scratch as part of Project Resurrection, but for now, here are the basics. You'll probably want to look at the menubar files that come with Eterm; they're pretty good samples.

First, let's discuss the paradigm used by the menubar system. Like so many things these days, the menubar uses a filesystem analogy, with the menubar itself comprising the top level (root) and each menu and submenu is a "directory" or "subdirectory" thereof. You manipulate the contents of the menubar by adding and removing menus, menu items, and submenus via their respective "paths." You even have a "working directory" and can add/remove several items at a time by changing to the directory you want.

The following table shows the commands which are recognized by the menubar system. These commands can be supplied as string in the menubar escape sequence, or they can be lines in a menubar file.

Command Action
= title Set the menubar title to title. Note that the menubar title is entirely separate from Eterm's titlebar text. Any occurance of %v in title is replaced by the Eterm version. %n is replaced by the resource name (as specified by the -n option. %% inserts a literal '%'.
[ + ] path Change directories to path. If path doesn't exist, it is created. / represents the menubar itself. /some_menu/ represents a primary menu in the menubar. /some_menu/submenu/ represents a submenu underneath that menu. And so on.... You can also use "." and ".." just like you would on a UNIX filesystem.
-path Removes the menu at path. All submenus and menu items are automatically removed.
[ + ] [ path ] { menuitem } [ { rtext } ] [ { action } ] Add a menu item at path. The label (menuitem) is required but can be hidden by using a dot ('.') as the first character of menuitem, or by using the same text for rtext. The optional string rtext will be right-justified; this is generally used to note the key sequence bound to a particular menu item. If action is not specified, the contents of rtext are used.

action is the string which is bound to the menuitem. It is parsed for escape sequences, control characters, etc. See the table below for a list of valid encodings. If action begins with a NUL character (^@), the string is sent to Eterm instead of to the application. (To send a string beginning with a NUL to the application, simply prefix the string with two NUL's. The first one will be stripped and the remainder send to the application.) So any escape sequences you want Eterm to parse should begin with ^@.

As mentioned in the table below, M- can be used as a substitute for ESC in an action string, with one difference: a carriage return (\r) is appending automatically to any string that begins with M- and does not already have the trailing CR.

To add a separator bar, specify - as menuitem.

- [ path ] { menuitem } Removes menuitem.
[apptitle: title ] Sets Eterm's titlebar title to title. Not to be confused with the [title:] command, which sets the menubar title.
[clear] Clears the menubar of all menus. Equivalent to rm -rf / on a UNIX filesystem.
[done [ : tag ] ] Sets the current menubar to read-only. No modification attempts will be accepted (unless they are enclosed in [::]; see below).
[dump] Dumps the current menubars out to a file. The path of this file is placed in the Eterm titlebar. The menubars are dumped so that the resulting file is a valid Eterm menubar file which can be parsed by Eterm in the future to restore the current menubar settings.
[echo: text ] Sends text to the application running in the Eterm window.
[hide] Hides (toggles off) the menubar and sets it to read-only.
[menu [ : name ] ] Begin addition/modification of the name menubar. If name is not given, "default" is used. This command sets the menubar to read-write.
[pixmap: string ] A convenience command. string should follow the syntax shown in the Pixmap Escape Sequences section below.
[read: file ] Reads the menubar file file and parses the commands it contains. A menubar file consists of commands shown in this table. Lines beginning with '#' and blank lines are ignored.
[rm [ : ] [ spec ] ] Removes part or all of the contents of a menubar. spec can be a path, a menu item, or '*', or empty. The latter two remove all menus in the menubar.
[show] Shows (toggles on) the menubar and sets it to read-only.
[title: title ] Sets the menubar title to title
[:command:] Specifies that the current menu's read-only status should be ignored in order to parse command. command should be one of the above commands.
Escaped String Meaning
Backslash-Escaped Characters (case is ignored)
\a BEL (Alert)
\b BS
\cX Interpreted as Ctrl-X. Analogous to ^X.
\e ESC
\f FF
\n LF
\r CR
\t TAB
\v VT
\nnn nnn is interpreted as an octal number, and the corresponding character is inserted.
Convenience Shortcuts
^X Interpreted as Ctrl-X. X can be any character between @ and _. Case is ignored.
C-X Interpreted as Ctrl-X. Analogous to ^X.
M-X Interpreted as ESC followed by X. Analogous to \eX. If the string begins with M-, a CR is automatically appended to the end of the string if not already present.

Pixmap Escape Sequences

The string supplied to the pixmap escape sequence (above) consists of a filename (which can be empty) followed by a semicolon, then one or more geometry strings. The following table shows the valid geometry strings and their affects on the background pixmap:

String Function
? Query scale and position (generally disabled)
Adjusting scaling and position
WxH+X+Y Set scaling to W% by H%, and position to X% by Y%. W and H are percentages of the original image size. The position is a percentage, where +50+50 centers the pixmap in the window.
WxH+X Assumes Y == X
WxH Assumes Y == X == 50 (centers the pixmap)
W+X+Y Assumes H == W
W+X Assumes H == W and Y == X
W Assumes H == W and Y == X == 50
Adjusting position only
=+X+Y Set position to X% by Y% (absolute).
=+X Set position to X% by X%.
+X+Y Adjust position horizontally X% and vertically Y% from current position (relative).
+X+X Adjust position horizontally X% and vertically X% from current position.
Adjusting scale only
Wx0 Multiply horizontal scaling factor by W%
0xH Multiply vertical scaling factor by H%

Examples:

  • "\e]20;Dragon.jpg\007" -- Set background image to "Dragon.jpg"
  • "\e]20;Canyon.jpg;200\007" -- Set background image to "Canyon.jpg", scaling to 200% by 200%, and center it.
  • "\e]20;;100\007" -- Set scaling back to 100%
  • "\e]20;blackstone.png;0x0\007" -- Set background image to "blackstone.png" and tile it
  • "\e]20;;0x0\007" -- Tile current image instead of scaling

Mouse Reporting

When Eterm receives a mouse reporting request (and if mouse reporting is currently enabled), it replies with the sequence "ESC[Mbxy". The values for b, x, and y are as follows (subtract the value of space ' ' first):

  • Button status: The lower 2 bits of b indicate the button status, with 00 indicating Button1 down, 01 indicating Button2 down, 10 indicating Button3 down, and 11 indicating the button was released. (button = b & 0x3 - ' ')
  • Modifier status: The upper bits of b are used to flag which modifiers were active when the button was pressed. The low bit is the Shift flag, the middle is Meta, and the high bit is Control. (mod = b & 0x1c - ' ')
  • Coordinates: x and y are the column and row, respectively. (c = x - ' '; r = y - ' ')

Key Sequences

Cursor Keys
Key Pressed What Eterm Sends
Normal Shift Control Application
Up ESC [ A ESC [ a ESC O a ESC O A
Down ESC [ B ESC [ b ESC O b ESC O B
Right ESC [ C ESC [ c ESC O c ESC O C
Left ESC [ D ESC [ d ESC O d ESC O D
Special Keys
Key Pressed Normal Shift Control Control+Shift
Tab ^I ESC [ Z ^I  
Backspace ^H ^? ^?  
Home (Find) ESC [ 1 ~ ESC [ 1 $ ESC [ 1 ^ ESC [ 1 @
End (Select) ESC [ 4 ~ ESC [ 4 $ ESC [ 4 ^ ESC [ 4 @
Insert ESC [ 2 ~ Paste mouse selection ESC [ 2 ^ ESC [ 2 @
Delete (Execute) ESC [ 3 ~ ESC [ 3 $ ESC [ 3 ^ ESC [ 3 @
PageUp (Prior) ESC [ 5 ~ Scroll up one page ESC [ 5 ^ ESC [ 5 @
PageDown (Next) ESC [ 6 ~ Scroll down one page ESC [ 6 ^ ESC [ 6 @
Function Keys (Note: Shift-F1 through F10 sends F11-F20)
Key Pressed Normal Shift Control Control+Shift
F1 ESC [ 11 ~ ESC [ 23 ~ ESC [ 11 ^ ESC [ 23 ^
F2 ESC [ 12 ~ ESC [ 24 ~ ESC [ 12 ^ ESC [ 24 ^
F3 ESC [ 13 ~ ESC [ 25 ~ ESC [ 13 ^ ESC [ 25 ^
F4 ESC [ 14 ~ ESC [ 26 ~ ESC [ 14 ^ ESC [ 26 ^
F5 ESC [ 15 ~ ESC [ 28 ~ ESC [ 15 ^ ESC [ 28 ^
F6 ESC [ 17 ~ ESC [ 29 ~ ESC [ 17 ^ ESC [ 29 ^
F7 ESC [ 18 ~ ESC [ 31 ~ ESC [ 18 ^ ESC [ 31 ^
F8 ESC [ 19 ~ ESC [ 32 ~ ESC [ 19 ^ ESC [ 32 ^
F9 ESC [ 20 ~ ESC [ 33 ~ ESC [ 20 ^ ESC [ 33 ^
F10 ESC [ 21 ~ ESC [ 34 ~ ESC [ 21 ^ ESC [ 34 ^
F11 ESC [ 23 ~ ESC [ 23 $ ESC [ 23 ^ ESC [ 23 @
F12 ESC [ 24 ~ ESC [ 24 $ ESC [ 24 ^ ESC [ 24 @
F13 ESC [ 25 ~ ESC [ 25 $ ESC [ 25 ^ ESC [ 25 @
F14 ESC [ 26 ~ ESC [ 26 $ ESC [ 26 ^ ESC [ 26 @
F15 (Help) ESC [ 28 ~ ESC [ 28 $ ESC [ 28 ^ ESC [ 28 @
F16 (Menu) ESC [ 29 ~ ESC [ 29 $ ESC [ 29 ^ ESC [ 29 @
F17 ESC [ 31 ~ ESC [ 31 $ ESC [ 31 ^ ESC [ 31 @
F18 ESC [ 32 ~ ESC [ 32 $ ESC [ 32 ^ ESC [ 32 @
F19 ESC [ 33 ~ ESC [ 33 $ ESC [ 33 ^ ESC [ 33 @
F20 ESC [ 34 ~ ESC [ 34 $ ESC [ 34 ^ ESC [ 34 @
Keypad
Key Pressed Normal Application
KP_Enter ^M ESC O M
KP_F1 ESC O P ESC O P
KP_F2 ESC O Q ESC O Q
KP_F3 ESC O R ESC O R
KP_F4 ESC O S ESC O S
XK_KP_Multiply * ESC O j
XK_KP_Add + ESC O k
XK_KP_Separator , ESC O l
XK_KP_Subtract - ESC O m
XK_KP_Decimal . ESC O n
XK_KP_Divide / ESC O o
XK_KP_0 0 ESC O p
XK_KP_1 1 ESC O q
XK_KP_2 2 ESC O r
XK_KP_3 3 ESC O s
XK_KP_4 4 ESC O t
XK_KP_5 5 ESC O u
XK_KP_6 6 ESC O v
XK_KP_7 7 ESC O w
XK_KP_8 8 ESC O x
XK_KP_9 9 ESC O y

Eterm Extensions, Standards, and Implementations

Eterm Proprietary Escape Sequences

The table below contains a listing of all the Eterm-specific escape sequences that Eterm supports. These sequences were created by the Eterm authors. Please note the following conventions used in this table:

When an escape sequence is said to "set/toggle" an option, this means that the boolean parameter of the sequence is optional. If given, it will either set or unset the option. If omitted, the current state of that option will be reversed (i.e., turned off if on, or on if off). Acceptable values for "true" are: 1, on, yes, or (of course) true. Likewise, acceptable values for "false" are: 0, off, no, or false.

Sequence Function
ESC [ 9 n Titlebar Status. This places Eterm's current status in the titlebar. The status information includes the application name and version number, as well as the shading/tinting state if transparent, the pixmap path if their is a background pixmap, or "No Pixmap" if neither of these is true.
ESC ] 5 ; BEL Steal Focus. Eterm will raise itself to the top and steal keyboard/mouse focus. This is useful in case your window manager dies or has trouble starting up. By default, this is activated by holding the Ctrl key and clicking on the Eterm window with the left mouse button (Button1).
ESC ] 6 ; 0 [ ; boolean ] BEL Set/toggle transparency state.
ESC ] 6 ; 1 ; pct BEL Set shading percentage to pct.
ESC ] 6 ; 2 ; mask BEL Set tint mask to mask. As a favor to keebler, I left support for the old text aliases in the escape sequence parser. Thus, the following are supported as alternative values for mask:
  • none: 0xffffff
  • red: 0xff8080
  • green: 0x80ff80
  • blue: 0x8080ff
  • cyan: 0x80ffff
  • magenta: 0xff80ff
  • yellow: 0xffff80
ESC ] 6 ; 3 ; BEL Force an update the of transparency background.
ESC ] 6 ; 4 [ ; boolean ] BEL Set/toggle desktop watching.
ESC ] 6 ; 10 ; [ type ] [ ; width ] BEL Set scrollbar style to type and scrollbar width to width. If specified, type must be one of motif, xterm, or next. If you omit the type parameter and only wish to set the width, take care not to omit the extra semicolon. width is an integer. Its value is fairly wide-open, but should be something reasonable.
ESC ] 6 ; 11 [ ; boolean ] BEL Set/toggle right-side scrollbar.
ESC ] 6 ; 12 [ ; boolean ] BEL Set/toggle floating scrollbar (i.e., one with no trough).
ESC ] 6 ; 13 [ ; boolean ] BEL Set/toggle popup scrollbar (i.e., one that appears when the window has focus and disappears when it does not).
ESC ] 6 ; 15 [ ; boolean ] BEL Set/toggle menubar move.
ESC ] 6 ; 20 [ ; boolean ] BEL Set/toggle visual bell.
ESC ] 6 ; 21 [ ; boolean ] BEL Set/toggle map alert.
ESC ] 6 ; 22 [ ; boolean ] BEL Set/toggle xterm's cutchar selection behavior.
ESC ] 6 ; 23 [ ; boolean ] BEL Set/toggle selection of the whole line by triple-click.
ESC ] 6 ; 24 [ ; boolean ] BEL Set/toggle viewport mode.
ESC ] 6 ; 25 [ ; boolean ] BEL Set/toggle selection trailing spaces.
ESC ] 6 ; 50 ; desktop BEL Move Eterm to desktop desktop and make it the current desktop. This requires a GNOME-compliant Window Manager, such as Enlightenment.
ESC ] 6 ; 70 BEL Exit Eterm (most useful from a menubar).
ESC ] 6 ; 71 [ ; path ] BEL Saves the current configuration to the current theme directory, or to path if specified. If a file of the same name already exists, it is renamed to path.YYYYMMDD.HHMMSS (where YYYYMMDD.HHMMSS is the current system time).

Transparency

The standard for implementing transparency was a mutual effort between myself, Carsten Haitzler , Gerald Britton , and Nat Friedman , based off of an original idea by Nat. First I'll define the standard, then I'll discuss its justification.

There are two separate procedures for setting the transparency property (the _XROOTPMAP_ID atom in X). The first is for persistent X clients such as window managers. These clients should proceed through their normal mechanism for setting the desktop image. Once the finalized pixmap has been created, the _XROOTPMAP_ID property should be set on the desktop window (the same window which will receive the pixmap...note that this is not necessarily the root window), and its value should be set to the Pixmap ID. The following sample code (taken from Enlightenment) demonstrates this:

/* disp is the Display, win is the desktop Window, pmap is the pixmap */
static Atom prop = 0;

if (!prop) {
  prop = XInternAtom(disp, "_XROOTPMAP_ID", False);
}
XChangeProperty(disp, win, prop, XA_PIXMAP, 32, PropModeReplace,
                (unsigned char *)&pmap, 1);
XSetWindowBackgroundPixmap(disp, win, pmap);
XClearWindow(disp, win);

The second procedure is for temporary clients; i.e., clients who set the desktop pixmap and then exit. An example of this type of client would be Esetroot, the transparency utility provided with Eterm. These clients should set the _XROOTPMAP_ID property just like the persistent client does. They should also set a companion property as well, ESETROOT_PMAP_ID. Both are set to the same pixmap ID. When a temporary client runs, it checks to see if _XROOTPMAP_ID and ESETROOT_PMAP_ID have the same value. If so, the client knows that it can safely do an XKillClient() on the pixmap ID. This will save memory, as the old pixmap can be removed. If they are not equal, however, calling XKillClient() would kill the persistent client which did set it, most likely the user's window manager. This would be a Bad Ideatm. The following code fragment (taken from Esetroot) illustrates this process:

/* disp is the Display, win is the desktop Window, pmap is the pixmap */
Atom prop_root, prop_esetroot, type;
int format;
unsigned long length, after;
unsigned char *data_root, *data_esetroot;

/* First check to see if the properties already exist, and if they are equal */
prop_root = XInternAtom(disp, "_XROOTPMAP_ID", True);
prop_esetroot = XInternAtom(disp, "ESETROOT_PMAP_ID", True);

if (prop_root != None && prop_esetroot != None) {
  XGetWindowProperty(disp, win, prop_root, 0L, 1L, False, AnyPropertyType,
                     &type, &format, &length, &after, &data_root);
  if (type == XA_PIXMAP) {
    XGetWindowProperty(disp, win, prop_esetroot, 0L, 1L, False, AnyPropertyType,
                       &type, &format, &length, &after, &data_esetroot);
    if (data_root && data_esetroot && type == XA_PIXMAP && *((Pixmap *) data_root) == *((Pixmap *) data_esetroot)) {
      /* It's safe.  Kill the pixmap. */
      XKillClient(disp, *((Pixmap *) data_root));
    }
  }
}

/* This will locate the property, creating it if it doesn't exist */
prop_root = XInternAtom(disp, "_XROOTPMAP_ID", False);
prop_esetroot = XInternAtom(disp, "ESETROOT_PMAP_ID", False);

/* The call above should have created it.  If that failed, we can't continue. */
if (prop_root == None || prop_esetroot == None) {
  fprintf(stderr, "Error:  Creation of pixmap property failed.\n");
  exit(1);
}
XChangeProperty(disp, win, prop_root, XA_PIXMAP, 32, PropModeReplace,
                (unsigned char *) &pmap, 1);
XChangeProperty(disp, win, prop_esetroot, XA_PIXMAP, 32, PropModeReplace,
                (unsigned char *) &pmap, 1);
XSetCloseDownMode(disp, RetainPermanent);

When the client runs, it looks for the _XROOTPMAP_ID property on the desktop window. (The client searches through all its parent windows until it either finds one with this property set, or hits the root window without finding it.) If the client finds this property, it can then use the pixmap directly, or make a copy of the pixmap in order to perform additional operations on it (such as brightening, shading, tinting, etc.).

So why use this technique? Why require such support from the window manager and other external applications? Why not simply set the background to ParentRelative and be done with it? let X handle everything? This seems to be a point of great confusion lately. Those who have taken the time to put the other terminal emulators who have chosen the latter route through their paces already know the answer: Power. Very simply, you have *much* greater power and flexibility with this technique than any other. X only permits a limited amount of flexibility when copying the background directly (basically just bitwise logical operations). The above technique allows programs to tint, shade, brighten, or otherwise manipulate the image in *any* way they see fit. Want a 10% shade? A 30% shade? Maybe a light cyan tint? Or perhaps you prefer a midnight blue tint.... With this technique, you can have it *your* way, not their way.