The union of the color and the node_number in the struct screen_char.
[elinks.git] / src / terminal / kbd.h
blobe277988ffccbbb6fa601164953a03fdb62ab6178
1 #ifndef EL__TERMINAL_KBD_H
2 #define EL__TERMINAL_KBD_H
4 #include "intl/charsets.h"
6 struct itrm;
8 /** A character received from a terminal. */
9 #ifdef CONFIG_UTF8
10 typedef unicode_val_T term_event_char_T; /* in UCS-4 */
11 #else
12 typedef unsigned char term_event_char_T; /* in the charset of the terminal */
13 #endif
15 /** A key received from a terminal, without modifiers. The value is
16 * either from term_event_char_T or from enum term_event_special_key.
17 * To check which one it is, use is_kbd_character().
19 * - Values <= -0x100 are special; from enum term_event_special_key.
20 * - Values between -0xFF and -2 are not used yet; treat as special.
21 * - Value == -1 is KBD_UNDEF; not sent via socket.
22 * - Values >= 0 are characters; from term_event_char_T.
24 * Any at least 32-bit signed integer type would work here; using an
25 * exact-width type hurts portability in principle, but some other
26 * parts of ELinks already require the existence of uint32_t. */
27 typedef int32_t term_event_key_T;
29 /** Values for term_event_keyboard.modifier and
30 * interlink_event_keyboard.modifier */
31 typedef enum {
32 KBD_MOD_NONE = 0,
33 KBD_MOD_SHIFT = 1,
34 KBD_MOD_CTRL = 2,
35 KBD_MOD_ALT = 4,
37 /** The character is part of a string being pasted from the
38 * terminal. parse_keystroke() does not support this flag, so
39 * keystrokes that include it cannot be bound to any actions,
40 * and ELinks will instead insert the characters if possible. */
41 KBD_MOD_PASTE = 8,
42 } term_event_modifier_T;
44 /** A key received from a terminal, with modifiers. */
45 struct term_event_keyboard {
46 term_event_key_T key;
47 term_event_modifier_T modifier;
50 /** Like struct term_event_keyboard but used in the interlink protocol
51 * between ELinks processes. Because the processes may be running
52 * different versions of ELinks, especially if a new version has just
53 * been installed, this structure should be kept binary compatible as
54 * long as possible. See bug 793 for a list of pending changes to the
55 * protocol. */
56 struct interlink_event_keyboard {
57 /** This is like term_event_key_T but carries individual bytes
58 * rather than entire characters, and uses different values
59 * for special keys.
61 * - Values <= -2 are not used, for ELinks 0.11 compatibility.
62 * - Value == -1 is KBD_UNDEF; not sent via socket.
63 * - Values between 0 and 0xFF are bytes received from the terminal.
64 * - Values >= 0x100 are special; absolute values of constants
65 * from enum term_event_special_key, e.g. -KBD_ENTER. */
66 int key;
67 /** The values are from term_event_modifier_T, but the type
68 * must be int so that the representation remains compatible
69 * with ELinks 0.11. */
70 int modifier;
73 /** Codes of special keys, for use in term_event_key_T.
74 * The enum has a tag mainly to let you cast numbers to it in GDB and see
75 * their names. ELinks doesn't use this enum type as term_event_key_T,
76 * because it might be 16-bit and Unicode characters wouldn't then fit. */
77 enum term_event_special_key {
78 KBD_UNDEF = -1,
80 KBD_ENTER = -0x100,
81 KBD_BS = -0x101,
82 KBD_TAB = -0x102,
83 KBD_ESC = -0x103,
84 KBD_LEFT = -0x104,
85 KBD_RIGHT = -0x105,
86 KBD_UP = -0x106,
87 KBD_DOWN = -0x107,
88 KBD_INS = -0x108,
89 KBD_DEL = -0x109,
90 KBD_HOME = -0x10a,
91 KBD_END = -0x10b,
92 KBD_PAGE_UP = -0x10c,
93 KBD_PAGE_DOWN = -0x10d,
95 KBD_F1 = -0x120,
96 KBD_F2 = -0x121,
97 KBD_F3 = -0x122,
98 KBD_F4 = -0x123,
99 KBD_F5 = -0x124,
100 KBD_F6 = -0x125,
101 KBD_F7 = -0x126,
102 KBD_F8 = -0x127,
103 KBD_F9 = -0x128,
104 KBD_F10 = -0x129,
105 KBD_F11 = -0x12a,
106 KBD_F12 = -0x12b,
108 KBD_CTRL_C = -0x200
111 static inline int is_kbd_fkey(term_event_key_T key) { return key <= KBD_F1 && key >= KBD_F12; }
112 #define number_to_kbd_fkey(num) (KBD_F1 - (num) + 1)
113 #define kbd_fkey_to_number(key) (KBD_F1 - (key) + 1)
115 /**Check whether @a key is a character or a special key.
116 * @code int is_kbd_character(term_event_key_T key); @endcode
117 * Return true if @a key is a character from ::term_event_char_T.
118 * (The character is not necessarily printable.)
119 * Return false if @a key is a special key from enum term_event_special_key. */
120 #define is_kbd_character(key) ((key) >= 0)
122 void
123 handle_trm(int std_in, int std_out, int sock_in, int sock_out, int ctl_in,
124 void *init_string, int init_len, int remote);
126 void itrm_queue_event(struct itrm *itrm, unsigned char *data, int len);
127 void block_itrm(void);
128 int unblock_itrm(void);
129 void free_all_itrms(void);
130 void resize_terminal(void);
131 void dispatch_special(unsigned char *);
132 void kbd_ctrl_c(void);
133 int is_blocked(void);
134 void get_terminal_name(unsigned char *);
136 #define kbd_get_key(kbd_) ((kbd_)->key)
137 #define kbd_key_is(kbd_, key) (kbd_get_key(kbd_) == (key))
139 #define kbd_get_modifier(kbd_) ((kbd_)->modifier)
140 #define kbd_modifier_is(kbd_, mod) (kbd_get_modifier(kbd_) == (mod))
142 #define kbd_set(kbd_, key_, modifier_) do { \
143 (kbd_)->key = (key_); \
144 (kbd_)->modifier = (modifier_); \
145 } while (0)
148 #endif