adamyg/grief

mok2-input-mode

Closed this issue · 0 comments

Controls modifyOtherKeys:

  enable:    \e[>4;2m  
  disable:    \e[>4;0m 
CSI > Pp m
          Set/reset key modifier options, xterm.  Set or reset resource-
          values used by xterm to decide whether to construct escape
          sequences holding information about the modifiers pressed with
          a given key.

          The first parameter Pp identifies the resource to set/reset.
          The second parameter Pv is the value to assign to the
          resource.

          If the second parameter is omitted, the resource is reset to
          its initial value.  Values 3  and 5  are reserved for keypad-
          keys and string-keys.

            Pp = 0  ⇒  modifyKeyboard.
            Pp = 1  ⇒  modifyCursorKeys.
            Pp = 2  ⇒  modifyFunctionKeys.
            Pp = 4  ⇒  modifyOtherKeys.

          If no parameters are given, all resources are reset to their
          initial values.

Values that can be "assigned" for modiyOtherKeys are:

modifyOtherKeys (class ModifyOtherKeys)
               Like modifyCursorKeys, tells xterm to construct an escape
               sequence for ordinary (i.e., "other") keys (such as "2") when
               modified by Shift-, Control-, Alt- or Meta-modifiers.  This
               feature does not apply to special keys, i.e., cursor-, keypad-,
               function- or control-keys which are labeled on your keyboard.
               Those have key symbols which XKB identifies uniquely.

               For example, this feature does not apply to special control-
               keys (e.g., Escape, Tab, Enter, Backspace) Other control keys
               (e.g., Control-I, Control-M, Control-H) may send escape
               sequences when this feature is enabled.

               The default is "0":

               0    disables this feature.

               1    enables this feature for keys except for those with well-
                    known behavior, e.g., Tab, Backarrow and some special
                    control character cases which are built into the X11
                    library, e.g., Control-Space to make a NUL, or Control-3
                    to make an Escape character.

                    Except for those special cases built into the X11 library,
                    the Shift- and Control- modifiers are treated normally.
                    The Alt- and Meta- modifiers do not cause xterm to send
                    escape sequences.  Those modifier keys are interpreted
                    according to other resources, e.g., the metaSendsEscape
                    resource.

               2    enables this feature for keys including the exceptions
                    listed.  Xterm ignores the special cases built into the
                    X11 library.  Any shifted (modified) ordinary key sends an
                    escape sequence.  The Alt- and Meta- modifiers cause xterm
                    to send escape sequences.

               The Xterm FAQ has an extended discussion of this feature, with
               examples:
               https://invisible-island.net/xterm/modified-keys.html

Reports:

  xterm:      \e[27;<modifier>;<char>~ or
  alt-form:   \e[<char>;<modifier>u
  
  formatOtherKeys=1 in xterm; which is the mintty default.

References:
https://invisible-island.net/xterm/modified-keys-gb-altgr-intl.html#other_modifiable_keycodes

Optional, request keyboard protocol state;

CSI ? Pp m
          Query key modifier options (XTQMODKEYS), xterm.
          The parameter Pp identifies the resource to query.

            Pp = 0  ⇒  modifyKeyboard.
            Pp = 1  ⇒  modifyCursorKeys.
            Pp = 2  ⇒  modifyFunctionKeys.
            Pp = 4  ⇒  modifyOtherKeys.

          XTerm's response can be used to restore this state,
          because it is formatted as an XTMODKEYS control, i.e.,

            CSI > Pp m

          where
            Pp = 0  ⇒  modifyKeyboard
            Pp = 1  ⇒  modifyCursorKeys
            Pp = 2  ⇒  modifyFunctionKeys
            Pp = 4  ⇒  modifyOtherKeys

Example:

Code Symbol Actual Mode 0 Mode 1 Mode 2 Alt-Mode 1 Alt-Mode 2
0x0020 XK_space 32 -(skip)- ---- -*******
---- \s \s \s \s \s
s--- \s \s \E[27;2;32~ \s \E[32;2u
-a-- \s \E[27;3;32~ \E[27;3;32~ \E[32;3u \E[32;3u
sa-- \s \E[27;4;32~ \E[27;4;32~ \E[32;4u \E[32;4u
--c- ^@ ^@ \E[27;5;32~ ^@ \E[32;5u
s-c- ^@ ^@ \E[27;6;32~ ^@ \E[32;6u
-ac- ^@ \E[27;7;32~ \E[27;7;32~ \E[32;7u \E32;7u
sac- ^@ \E[27;8;32~ \E[27;8;32~ \E[32;8u \E32;8u

We can use this to represent the problematic combinations of keys; for example variations on the letter "A" (ASCII decimal value 65) and "a":

unmodified Alt+ Ctrl+ Ctrl+Alt+
without Shift a ESC a 0x01 ESC 0x01
with Shift A ESC A CSI 65;5 u CSI 65;7 u

This same pattern is continued for the other letters, except for the awkward cases of We can now represent the usual problematic keys unambiguously:

Ctrl-I = CSI 105;5 u Ctrl-Shift-I = CSI 73;5 u Tab = 0x09
Ctrl-M = CSI 109;5 u Ctrl-Shift-M = CSI 77;5 u Enter = 0x0d
Ctrl-[ = CSI 91;5 u Ctrl-{ = CSI 123;5 u Escape = 0x1b
Ctrl-@ = CSI 64;5u Ctrl-Space = 0x00

Because other C0 bytes do not have usual alternative names or keypresses, these can continue to be sent using the simple single-byte encoding. This is essential to ensuring that legacy systems continue to interpret them correctly (e.g. termios still sends SIGINT on Ctrl-C). The Space key is unique among the printing Unicode keys in that its behaviour doesn't normally change as a result of the Shift modifier. We can capture this by encoding it using CSIu - uniquely, the only printing Unicode key for which we use this:

Ctrl-Space = 0x00 Ctrl-Shift-Space = CSI 32;6 u

The problematic keys listed above plus Backspace can be represented using the CSI u encoding when any modifiers are present. Because these symbols are almost universally found on their own physical keycap, there is no problem with encoding the Shift modifier as well, with the value 1. We encode these keys using their normal ASCII codepoint values.

Enter = 0x0d Shift-Enter = CSI 13;2 u Ctrl-Enter = CSI 13;5 u ...
Escape = 0x1b Shift-Escape = CSI 27;2 u Ctrl-Escape = CSI 27;5 u
Backspace = 0x7f Shift-Backspace = CSI 127;2 u Ctrl-Backspace = CSI 127;5 u

The Space key is trickier, because it's traditionally used with the Ctrl modifier to obtain the NUL byte encoding.

Space = 0x20 Shift-Space = CSI 32;2 u Ctrl-Space = 0x00 Ctrl-Shift-Space = CSI 32;6 u