1 #ifndef EL__TERMINAL_KBD_H
2 #define EL__TERMINAL_KBD_H
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
{
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. */
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
{
52 KBD_PAGE_DOWN
= -0x10d,
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
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
);
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);
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_); \