http://invisible-island.net/xterm/xterm.faq.html
Copyright © 2020,2021 by Thomas E. Dickey


Notes on the Meta-key in XTerm and other Terminal Emulators

XXX

Overview

XXX

Background

The meta key predates X (originally in custom-built terminals, later in commercial terminals). 4.2BSD termcap listed a half-dozen terminals which had a meta key:

Some programs such as E (see 1974 manual) were written to use the meta key if it was available. The technical report Essential E (1980) mentions E's use with DataDisc and DataMedia terminals. Later, other developers copied the feature, e.g., Emacs (see 1978 manual).

The documentation for Emacs 147 (1980) allowed for the possibility that the terminal had no Meta key:

Meta refers to the Meta key. A character's name includes the word Meta if the Meta key must be held down in order to type the character. If there is no Meta key, then the Altmode character is used as a prefix instead. See section 2 [Meta], page 9.

However, the Altmode character was not (as some readers may have assumed) the Alt key on a “PC keyboard” (still in the future when the Emacs manual was written), but the ASCII escape character.

XXX need transition here pointing out that X uses keyboards too

Shift and Control are regular X11 modifiers, but Meta is not:

X10R4
X10 (which had no xmodmap utility) had a meta mask, but X11 did not.
X11R1
X11R1 introduced xmodmap, along with the current set of modifier masks. The meta key was assumed to be mod1 starting with X11R1. The initial xterm logic in X11 was different, but gave the same result.
X11R2
X11R2 modified xterm by eliminating the X10 table which provided part of the meta logic.
X11R3
X11R3 modified Xt (the X Toolkit Intrinsics), making Meta_L and Meta_R assignable via xmodmap, and equating Alt with Meta. Neither Alt or Meta is a modifier, but Alt is more likely to be on the keyboard.

This release also added keymap tables for the server; Meta was used frequently in HP keymaps, which were the most extensive set of keymaps.

X11R4
X11R4 mentions Meta in the ICCCM, stating that if Meta_L or Meta_R is found in the keysyms for a given modifier, that the client should use that modifier.

XXX

patch #362
When making improvements to xterm's Meta feature, one case was overlooked: the escape sequences returned when making mouse-clicks.

This function follows the ICCCM, picking the modifier which contains the Meta_L/Meta_R keysyms (if available), falling back to the Alt_L/Alt_R (as per X11R3), and ultimately to mod1 (per X11R1).

How it is used

XXX

XXX the half-dozen terminals cited with meta-key weren't latching.

XXX none of the BSD termcaps defined mm/mo to "latch" meta mode.

XXX CSRG 4.2BSD termcap from July 1983 lists only the teleray 10 special with "km". CSRG 4.3BSD termcap from June 1986 has also the dmchat and hp2392. A few others (XXX) have MT, which esr said is the same thing.

XXX CSRG 4.3BSD (date?) has source for xterm (version?) from 1986/05/16. Its terminfo (not termcap) lists km, for meta key.

XXX CSRG 1991/09/20 jak removed km from wy60, saying it has no meta key.

XXX CSRG 1989/04/22 jak added km to sun, per rms.

XXX perhaps https://deskthority.net/wiki/Sun_Type_3

Keyboard variations

Current/common xmodmap

XXX

xmodmap:  up to 4 keys per modifier, (keycodes in parentheses):

shift       Shift_L (0x32),  Shift_R (0x3e)
lock        Caps_Lock (0x42)
control     Control_L (0x25),  Control_R (0x69)
mod1        Alt_L (0x40),  Alt_R (0x6c),  Meta_L (0xcd)
mod2        Num_Lock (0x4d)
mod3      
mod4        Super_L (0x85),  Super_R (0x86),  Super_L (0xce),  Hyper_L (0xcf)
mod5        ISO_Level3_Shift (0x5c),  Mode_switch (0xcb)

Solaris10 xmodmap

xmodmap:  up to 2 keys per modifier, (keycodes in parentheses):

shift       Shift_L (0x32),  Shift_R (0x3e)
lock        Caps_Lock (0x42)
control     Control_L (0x25),  Control_R (0x6d)
mod1        Alt_L (0x40)
mod2        Mode_switch (0x71)
mod3        Num_Lock (0x4d)
mod4        Meta_L (0x73),  Meta_R (0x74)
mod5      

Solaris11 xmodmap

xmodmap:  up to 4 keys per modifier, (keycodes in parentheses):

shift       Shift_L (0x32),  Shift_R (0x3e)
lock        Caps_Lock (0x42)
control     Control_L (0x25),  Control_R (0x6d)
mod1        Alt_L (0x40)
mod2        Num_Lock (0x4d)
mod3        Scroll_Lock (0x4e),  Multi_key (0x75)
mod4        Meta_L (0x73),  Meta_R (0x74),  Super_L (0x7f),  Hyper_L (0x80)
mod5        Mode_switch (0x8),  ISO_Level3_Shift (0x71),  ISO_Level3_Shift (0x7c)

macOS default

xmodmap:  up to 2 keys per modifier, (keycodes in parentheses):

shift       Shift_L (0x40),  Shift_R (0x44)
lock        Caps_Lock (0x41)
control     Control_L (0x43),  Control_R (0x46)
mod1        Mode_switch (0x42),  Mode_switch (0x45)
mod2        Meta_L (0x3f),  Meta_R (0x47)
mod3      
mod4      
mod5      

macOS default

xmodmap:  up to 2 keys per modifier, (keycodes in parentheses):

shift       Shift_L (0x40),  Shift_R (0x44)
lock        Caps_Lock (0x41)
control     Control_L (0x43),  Control_R (0x46)
mod1        Alt_L (0x42),  Alt_R (0x45)
mod2        Meta_L (0x3f),  Meta_R (0x47)
mod3      
mod4      
mod5      

Other terminals

dtterm

dtterm(1) mentions kshMode, which uses escape+character rather than meta-mode, saying it was for emacs.

XXX

rxvt-unicode

XXX urxvt uses this resource:

       modifier: modifier
           Set the key to be interpreted as the Meta key to: alt, meta, hyper,
           super, mod1, mod2, mod3, mod4, mod5; option -mod.

It ignores case when comparing those names (unlike Xt). In initialization, it uses XGetModifierMapping, assigns meta to any match on keysyms Meta_L or Meta_R, falling through to any match on Alt_L or Alt_R

XQuartz vs xterm

XQuartz preferences has a setting that makes Alt_L/Alt_R by default send Mode_Switch as mask 0x2000, though xmodmap shows it on mod1:

                mod1        Alt_L (0x42),  Alt_R (0x45)
                mod2        Meta_L (0x3f),  Meta_R (0x47)
                

Xt/TMparse.c has these relevant entries:

            {"Mod1",    0,      ParseModImmed,Mod1Mask},
            {"Mod2",    0,      ParseModImmed,Mod2Mask},
            {"Meta",    0,      ParseModSym,  XK_Meta_L},
            {"Alt",     0,      ParseModSym,  XK_Alt_L},
            {"m",       0,      ParseModSym,  XK_Meta_L},
            {"a",       0,      ParseModSym,  XK_Alt_L},
        

So... unless I rewrote the default-translation resources, xterm won't see the meta key as "Meta": only "Alt". Xt's table doesn't mention Alt_R or Meta_R, by the way.

XXX this is why procura's translation doesn't work for me.

Use in applications