terminal: New enum term_event_special_key.
[elinks.git] / src / terminal / kbd.h
blobfbda0eb03c6c308ff64e0f4809a7731bfa51b8cd
1 #ifndef EL__TERMINAL_KBD_H
2 #define EL__TERMINAL_KBD_H
4 struct itrm;
6 /* Values <= -0x100 are special; from enum term_event_special_key.
7 * Values between -0xFF and -2 are not used yet; treat as special.
8 * Value == -1 is KBD_UNDEF; not sent via socket.
9 * Values >= 0 are characters received from the terminal;
10 * in UCS-4 #ifdef CONFIG_UTF_8. Test with is_kbd_character().
12 * Any at least 32-bit signed integer type would work here; using an
13 * exact-width type hurts portability in principle, but some other
14 * parts of ELinks already require the existence of uint32_t. */
15 typedef int32_t term_event_key_T;
17 struct term_event_keyboard {
18 term_event_key_T key;
19 int modifier;
22 struct interlink_event_keyboard {
23 /* Values <= -2 are not used, for ELinks 0.11 compatibility.
24 * Value == -1 is KBD_UNDEF; not sent via socket.
25 * Values between 0 and 0xFF are bytes received from the terminal.
26 * Values >= 0x100 are special; absolute values of constants
27 * from enum term_event_special_key, e.g. -KBD_ENTER. */
28 int key;
29 int modifier;
32 /* Codes of special keys, for use in term_event_key_T.
33 * The enum has a tag mainly to let you cast numbers to it in GDB and see
34 * their names. ELinks doesn't use this enum type as term_event_key_T,
35 * because it might be 16-bit and Unicode characters wouldn't then fit. */
36 enum term_event_special_key {
37 KBD_UNDEF = -1,
39 KBD_ENTER = -0x100,
40 KBD_BS = -0x101,
41 KBD_TAB = -0x102,
42 KBD_ESC = -0x103,
43 KBD_LEFT = -0x104,
44 KBD_RIGHT = -0x105,
45 KBD_UP = -0x106,
46 KBD_DOWN = -0x107,
47 KBD_INS = -0x108,
48 KBD_DEL = -0x109,
49 KBD_HOME = -0x10a,
50 KBD_END = -0x10b,
51 KBD_PAGE_UP = -0x10c,
52 KBD_PAGE_DOWN = -0x10d,
54 KBD_F1 = -0x120,
55 KBD_F2 = -0x121,
56 KBD_F3 = -0x122,
57 KBD_F4 = -0x123,
58 KBD_F5 = -0x124,
59 KBD_F6 = -0x125,
60 KBD_F7 = -0x126,
61 KBD_F8 = -0x127,
62 KBD_F9 = -0x128,
63 KBD_F10 = -0x129,
64 KBD_F11 = -0x12a,
65 KBD_F12 = -0x12b,
67 KBD_CTRL_C = -0x200
70 static inline int is_kbd_fkey(term_event_key_T key) { return key <= KBD_F1 && key >= KBD_F12; }
71 #define number_to_kbd_fkey(num) (KBD_F1 - (num) + 1)
72 #define kbd_fkey_to_number(key) (KBD_F1 - (key) + 1)
74 /* int is_kbd_character(term_event_key_T key);
75 * Return true if @key is a character in some charset, rather than a
76 * special key. The character is not necessarily printable. As for
77 * which charset it is in, see the definition of term_event_key_T. */
78 #define is_kbd_character(key) ((key) >= 0)
80 /* Values for term_event_keyboard.modifier and
81 * interlink_event_keyboard.modifier */
82 #define KBD_MOD_NONE 0
83 #define KBD_MOD_SHIFT 1
84 #define KBD_MOD_CTRL 2
85 #define KBD_MOD_ALT 4
87 void
88 handle_trm(int std_in, int std_out, int sock_in, int sock_out, int ctl_in,
89 void *init_string, int init_len, int remote);
91 void itrm_queue_event(struct itrm *itrm, unsigned char *data, int len);
92 void block_itrm(int);
93 int unblock_itrm(int);
94 void free_all_itrms(void);
95 void resize_terminal(void);
96 void dispatch_special(unsigned char *);
97 void kbd_ctrl_c(void);
98 int is_blocked(void);
100 #define kbd_get_key(kbd_) ((kbd_)->key)
101 #define kbd_key_is(kbd_, key) (kbd_get_key(kbd_) == (key))
103 #define kbd_get_modifier(kbd_) ((kbd_)->modifier)
104 #define kbd_modifier_is(kbd_, mod) (kbd_get_modifier(kbd_) == (mod))
106 #define kbd_set(kbd_, key_, modifier_) do { \
107 (kbd_)->key = (key_); \
108 (kbd_)->modifier = (modifier_); \
109 } while (0)
112 #endif