Bash's meta key originally was defined like this (
Mon Jul 13 11:34:07 1992 Brian Fox (bfox@cubit)
* readline.c: (rl_variable_bind) New variable "meta-flag" if "on"
means force the use of the 8th bit as Meta bit. Internal variable
is called meta_flag.
That happens to be the way it is interpreted with ncurses and xterm. A few terminals provided for making this feature optional (that aspect was not widespread. Most of the terminals you will encounter use hardcoded behavior (and not very interesting). The terminfo manual page documents these terminal capabilities:
has_meta_key km km Has a meta key
(i.e., sets 8th-bit)
meta_off rmm mo turn off meta mode
meta_on smm mm turn on meta mode
and explains the feature:
If the terminal has a "meta key" which acts as a shift
key, setting the 8th bit of any character transmitted,
this fact can be indicated with
km. Otherwise, software
will assume that the 8th bit is parity and it will usually
be cleared. If strings exist to turn this "meta mode" on
and off, they can be given as
A different feature, prefixing an escape character in response to the
Alt key was incorporated into some terminal emulators. Bash (actually the
readline library) documents that usage in its changelog from 2004:
- use _rl_dispatch_callback and a chain of _rl_keyseq_contexts to
simulate the recursion used to decode multicharacter key sequences
(even things like ESC- as meta-prefix
Meta is a special case of a modifier key. Like control and shift, you press it at the same time as another key and expect to see something different from pressing the key by itself. X provides for modifier keys by assigning a bit in the modifier value passed along in the X event for the key. Key presses can be multiple X events; X provides functions for combining these events while retaining the modifiers.
X also defines symbols for each of the keys that might appear on your keyboard. It provides for other values (such as Unicode) by special handling in the functions which combine events.
But "meta" is a special case.
X applications have no meta key, except by convention. X does not have a definition for the meta key, or the meta modifier. Conventionally, terminals look for the Alt-key and/or one of the modifiers known to
mod2. The later xkb feature complicates things (but provides no improvement relative to this discussion) by providing another layer of information to find the Alt key.
Convention of course can take you only so far, given that neither
xkb know anything in particular about meta. xterm, for instance, is configurable, and not all users want to configure meta in the same way. For instance, Alt may not be the intended meta-key, e.g., if it is used in the
translation resource. Another key may be the meta key, but users (particularly those using escape sequences in bash) may want an escape character sent when they press Alt. But keep in mind that unless it is configured as a modifier none of that happens: xterm does not combine events by itself.
xterm has several resource settings (documented in the manual page):
altSendsEscape (added in 2007).
eightBitInput since 2006 corresponds to the original sense of meta mode, and there is an escape sequence defined for this which provides the
rmm (set/remove meta-mode) terminal capabilities.
eightBitInput was modified in 2003 to take UTF-8 into account by shifting the decoded Unicode values by 128 rather than the raw input bytes.
metaSendsEscape dates from 1999
eightBitInput is much older than
metaSendsEscape. That has implemented a choice between meta mode (adding the eighth bit) or prefixing a key with escape since X11R4 (1989). But the feature was determined at startup: it was checked during initialization to determine whether the input was set to permit 8 bits or only 7. After that, it did not change.
Some people equate the two (8th-bit and escape-prefix), referring to the latter as meta mode. Depending on your point of view on the matter, the
eightBitInput resource setting of xterm is part of the solution to getting a workable meta-key.