1 #ifndef EL__TERMINAL_KBD_H
2 #define EL__TERMINAL_KBD_H
4 #include "intl/charsets.h"
8 /* A character received from a terminal. */
10 typedef unicode_val_T term_event_char_T
; /* in UCS-4 */
12 typedef unsigned char term_event_char_T
; /* in the charset of the terminal */
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 */
36 } term_event_modifier_T
;
38 /* A key received from a terminal, with modifiers. */
39 struct term_event_keyboard
{
41 term_event_modifier_T modifier
;
44 /* Like struct term_event_keyboard but used in the interlink protocol
45 * between ELinks processes. Because the processes may be running
46 * different versions of ELinks, especially if a new version has just
47 * been installed, this structure should be kept binary compatible as
48 * long as possible. See bug 793 for a list of pending changes to the
50 struct interlink_event_keyboard
{
51 /* This is like term_event_key_T but carries individual bytes
52 * rather than entire characters, and uses different values
55 * Values <= -2 are not used, for ELinks 0.11 compatibility.
56 * Value == -1 is KBD_UNDEF; not sent via socket.
57 * Values between 0 and 0xFF are bytes received from the terminal.
58 * Values >= 0x100 are special; absolute values of constants
59 * from enum term_event_special_key, e.g. -KBD_ENTER. */
61 /* The values are from term_event_modifier_T, but the type
62 * must be int so that the representation remains compatible
63 * with ELinks 0.11. */
67 /* Codes of special keys, for use in term_event_key_T.
68 * The enum has a tag mainly to let you cast numbers to it in GDB and see
69 * their names. ELinks doesn't use this enum type as term_event_key_T,
70 * because it might be 16-bit and Unicode characters wouldn't then fit. */
71 enum term_event_special_key
{
87 KBD_PAGE_DOWN
= -0x10d,
105 static inline int is_kbd_fkey(term_event_key_T key
) { return key
<= KBD_F1
&& key
>= KBD_F12
; }
106 #define number_to_kbd_fkey(num) (KBD_F1 - (num) + 1)
107 #define kbd_fkey_to_number(key) (KBD_F1 - (key) + 1)
109 /* int is_kbd_character(term_event_key_T key);
110 * Check whether @key is a character or a special key.
111 * Return true if @key is a character from term_event_char_T.
112 * (The character is not necessarily printable.)
113 * Return false if @key is a special key from enum term_event_special_key. */
114 #define is_kbd_character(key) ((key) >= 0)
117 handle_trm(int std_in
, int std_out
, int sock_in
, int sock_out
, int ctl_in
,
118 void *init_string
, int init_len
, int remote
);
120 void itrm_queue_event(struct itrm
*itrm
, unsigned char *data
, int len
);
121 void block_itrm(int);
122 int unblock_itrm(int);
123 void free_all_itrms(void);
124 void resize_terminal(void);
125 void dispatch_special(unsigned char *);
126 void kbd_ctrl_c(void);
127 int is_blocked(void);
128 void get_terminal_name(unsigned char *);
130 #define kbd_get_key(kbd_) ((kbd_)->key)
131 #define kbd_key_is(kbd_, key) (kbd_get_key(kbd_) == (key))
133 #define kbd_get_modifier(kbd_) ((kbd_)->modifier)
134 #define kbd_modifier_is(kbd_, mod) (kbd_get_modifier(kbd_) == (mod))
136 #define kbd_set(kbd_, key_, modifier_) do { \
137 (kbd_)->key = (key_); \
138 (kbd_)->modifier = (modifier_); \