From c5c36eba88b1fdeb8154973924fa974d7bbda07c Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Sun, 13 Aug 2006 17:16:10 +0300 Subject: [PATCH 1/3] terminal: Define term_event_key_T as int32_t, not int. int might be 16-bit and that is not enough. --- src/terminal/kbd.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/terminal/kbd.h b/src/terminal/kbd.h index a4aeb1539..4bea29925 100644 --- a/src/terminal/kbd.h +++ b/src/terminal/kbd.h @@ -7,8 +7,12 @@ struct itrm; * Values between -0xFF and -2 are not used yet; treat as special. * Value == -1 is KBD_UNDEF; not sent via socket. * Values >= 0 are characters received from the terminal; - * in UCS-4 #ifdef CONFIG_UTF_8. */ -typedef int term_event_key_T; + * in UCS-4 #ifdef CONFIG_UTF_8. + * + * Any at least 32-bit signed integer type would work here; using an + * exact-width type hurts portability in principle, but some other + * parts of ELinks already require the existence of uint32_t. */ +typedef int32_t term_event_key_T; struct term_event_keyboard { term_event_key_T key; From f290ff560840de430b2c3536bca43aafec4b49b2 Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Sun, 13 Aug 2006 19:03:09 +0300 Subject: [PATCH 2/3] terminal: New enum term_event_special_key. This makes constants like KBD_ENTER visible to the debugger, at least when compiled with GCC. --- src/terminal/event.h | 6 ++-- src/terminal/kbd.c | 8 +++++ src/terminal/kbd.h | 72 ++++++++++++++++++++++++-------------------- 3 files changed, 51 insertions(+), 35 deletions(-) diff --git a/src/terminal/event.h b/src/terminal/event.h index 8125b1b02..a3bfab4f4 100644 --- a/src/terminal/event.h +++ b/src/terminal/event.h @@ -78,8 +78,10 @@ set_kbd_term_event(struct term_event *ev, int key, int modifier) kbd_set(&ev->info.keyboard, key, modifier); } -/* @key can be e.g. KBD_ENTER as in term_event_keyboard.key. - * This function then sets ev->info.keyboard.key = -KBD_ENTER. */ +/* @key can be either a 8-bit byte or a value from enum term_event_special_key. + * In the latter case, this function negates the value, unless it is KBD_UNDEF. + * For example, key == KBD_ENTER results in ev->info.keyboard.key = -KBD_ENTER. + * This mapping keeps the interlink protocol compatible with ELinks 0.11. */ static inline void set_kbd_interlink_event(struct interlink_event *ev, int key, int modifier) { diff --git a/src/terminal/kbd.c b/src/terminal/kbd.c index 07fd30564..87c892456 100644 --- a/src/terminal/kbd.c +++ b/src/terminal/kbd.c @@ -48,6 +48,14 @@ static int process_queue(struct itrm *); static void handle_itrm_stdin(struct itrm *); static void unhandle_itrm_stdin(struct itrm *); +#ifdef CONFIG_DEBUG +/* This hack makes GCC put enum term_event_special_key in the debug + * information even though it is not otherwise used. The const + * prevents an unused-variable warning. */ +static const enum term_event_special_key dummy_term_event_special_key; +#endif + + int is_blocked(void) { diff --git a/src/terminal/kbd.h b/src/terminal/kbd.h index 4bea29925..fbda0eb03 100644 --- a/src/terminal/kbd.h +++ b/src/terminal/kbd.h @@ -3,11 +3,11 @@ struct itrm; -/* Values <= -0x100 are special; e.g. KBD_ENTER. +/* Values <= -0x100 are special; from enum term_event_special_key. * Values between -0xFF and -2 are not used yet; treat as special. * Value == -1 is KBD_UNDEF; not sent via socket. * Values >= 0 are characters received from the terminal; - * in UCS-4 #ifdef CONFIG_UTF_8. + * in UCS-4 #ifdef CONFIG_UTF_8. Test with is_kbd_character(). * * Any at least 32-bit signed integer type would work here; using an * exact-width type hurts portability in principle, but some other @@ -23,48 +23,54 @@ struct interlink_event_keyboard { /* Values <= -2 are not used, for ELinks 0.11 compatibility. * Value == -1 is KBD_UNDEF; not sent via socket. * Values between 0 and 0xFF are bytes received from the terminal. - * Values >= 0x100 are special; e.g. -KBD_ENTER. */ + * Values >= 0x100 are special; absolute values of constants + * from enum term_event_special_key, e.g. -KBD_ENTER. */ int key; int modifier; }; -/* Values for term_event_key_T */ +/* Codes of special keys, for use in term_event_key_T. + * The enum has a tag mainly to let you cast numbers to it in GDB and see + * their names. ELinks doesn't use this enum type as term_event_key_T, + * because it might be 16-bit and Unicode characters wouldn't then fit. */ +enum term_event_special_key { + KBD_UNDEF = -1, -#define KBD_UNDEF -1 + KBD_ENTER = -0x100, + KBD_BS = -0x101, + KBD_TAB = -0x102, + KBD_ESC = -0x103, + KBD_LEFT = -0x104, + KBD_RIGHT = -0x105, + KBD_UP = -0x106, + KBD_DOWN = -0x107, + KBD_INS = -0x108, + KBD_DEL = -0x109, + KBD_HOME = -0x10a, + KBD_END = -0x10b, + KBD_PAGE_UP = -0x10c, + KBD_PAGE_DOWN = -0x10d, -#define KBD_ENTER (-0x100) -#define KBD_BS (-0x101) -#define KBD_TAB (-0x102) -#define KBD_ESC (-0x103) -#define KBD_LEFT (-0x104) -#define KBD_RIGHT (-0x105) -#define KBD_UP (-0x106) -#define KBD_DOWN (-0x107) -#define KBD_INS (-0x108) -#define KBD_DEL (-0x109) -#define KBD_HOME (-0x10a) -#define KBD_END (-0x10b) -#define KBD_PAGE_UP (-0x10c) -#define KBD_PAGE_DOWN (-0x10d) + KBD_F1 = -0x120, + KBD_F2 = -0x121, + KBD_F3 = -0x122, + KBD_F4 = -0x123, + KBD_F5 = -0x124, + KBD_F6 = -0x125, + KBD_F7 = -0x126, + KBD_F8 = -0x127, + KBD_F9 = -0x128, + KBD_F10 = -0x129, + KBD_F11 = -0x12a, + KBD_F12 = -0x12b, + + KBD_CTRL_C = -0x200 +}; -#define KBD_F1 (-0x120) -#define KBD_F2 (-0x121) -#define KBD_F3 (-0x122) -#define KBD_F4 (-0x123) -#define KBD_F5 (-0x124) -#define KBD_F6 (-0x125) -#define KBD_F7 (-0x126) -#define KBD_F8 (-0x127) -#define KBD_F9 (-0x128) -#define KBD_F10 (-0x129) -#define KBD_F11 (-0x12a) -#define KBD_F12 (-0x12b) static inline int is_kbd_fkey(term_event_key_T key) { return key <= KBD_F1 && key >= KBD_F12; } #define number_to_kbd_fkey(num) (KBD_F1 - (num) + 1) #define kbd_fkey_to_number(key) (KBD_F1 - (key) + 1) -#define KBD_CTRL_C (-0x200) - /* int is_kbd_character(term_event_key_T key); * Return true if @key is a character in some charset, rather than a * special key. The character is not necessarily printable. As for From c8584a1c7e05cd43459b792247ceb5c1e53a6487 Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Sun, 13 Aug 2006 19:41:46 +0300 Subject: [PATCH 3/3] terminal: New type term_event_modifier_T. KBD_MOD_NONE and related constants are now also visible in GDB. --- src/terminal/event.c | 7 ++++--- src/terminal/event.h | 8 +++++--- src/terminal/kbd.c | 8 +++++++- src/terminal/kbd.h | 21 +++++++++++++-------- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/terminal/event.c b/src/terminal/event.c index ac7794b74..d7da3d778 100644 --- a/src/terminal/event.c +++ b/src/terminal/event.c @@ -49,7 +49,7 @@ struct terminal_interlink { * ELinks sees e.g. ESC U+00F6 as 0x1B 0xC3 0xB6 and * converts it to Alt-0xC3 0xB6, attaching the * modifier to the first byte only. */ - int modifier; + term_event_modifier_T modifier; } utf_8; /* This is the queue of events as coming from the other ELinks instance @@ -133,7 +133,8 @@ term_send_event(struct terminal *term, struct term_event *ev) } static void -term_send_ucs(struct terminal *term, unicode_val_T u, int modifier) +term_send_ucs(struct terminal *term, unicode_val_T u, + term_event_modifier_T modifier) { #ifdef CONFIG_UTF_8 struct term_event ev; @@ -277,7 +278,7 @@ handle_interlink_event(struct terminal *term, struct interlink_event *ilev) { int utf8_io = -1; int key = ilev->info.keyboard.key; - int modifier = ilev->info.keyboard.modifier; + term_event_modifier_T modifier = ilev->info.keyboard.modifier; if (key >= 0x100) key = -key; diff --git a/src/terminal/event.h b/src/terminal/event.h index a3bfab4f4..152b4567a 100644 --- a/src/terminal/event.h +++ b/src/terminal/event.h @@ -71,19 +71,21 @@ set_mouse_interlink_event(struct interlink_event *ev, int x, int y, unsigned int } static inline void -set_kbd_term_event(struct term_event *ev, int key, int modifier) +set_kbd_term_event(struct term_event *ev, int key, + term_event_modifier_T modifier) { memset(ev, 0, sizeof(*ev)); ev->ev = EVENT_KBD; kbd_set(&ev->info.keyboard, key, modifier); } -/* @key can be either a 8-bit byte or a value from enum term_event_special_key. +/* @key can be either an 8-bit byte or a value from enum term_event_special_key. * In the latter case, this function negates the value, unless it is KBD_UNDEF. * For example, key == KBD_ENTER results in ev->info.keyboard.key = -KBD_ENTER. * This mapping keeps the interlink protocol compatible with ELinks 0.11. */ static inline void -set_kbd_interlink_event(struct interlink_event *ev, int key, int modifier) +set_kbd_interlink_event(struct interlink_event *ev, int key, + term_event_modifier_T modifier) { memset(ev, 0, sizeof(*ev)); ev->ev = EVENT_KBD; diff --git a/src/terminal/kbd.c b/src/terminal/kbd.c index 87c892456..5e593d86f 100644 --- a/src/terminal/kbd.c +++ b/src/terminal/kbd.c @@ -841,8 +841,14 @@ decode_terminal_application_key(struct itrm *itrm, struct interlink_event *ev) } +/* Initialize *@ev to match the byte @key received from the terminal. + * Actually, @key could also be a value from enum term_event_special_key; + * but callers that use those values generally don't need the mapping + * provided by this function, so they call set_kbd_interlink_event() + * directly. */ static void -set_kbd_event(struct interlink_event *ev, int key, int modifier) +set_kbd_event(struct interlink_event *ev, + int key, term_event_modifier_T modifier) { switch (key) { case ASCII_TAB: diff --git a/src/terminal/kbd.h b/src/terminal/kbd.h index fbda0eb03..c43a250de 100644 --- a/src/terminal/kbd.h +++ b/src/terminal/kbd.h @@ -14,9 +14,18 @@ struct itrm; * parts of ELinks already require the existence of uint32_t. */ typedef int32_t term_event_key_T; +/* Values for term_event_keyboard.modifier and + * interlink_event_keyboard.modifier */ +typedef enum { + KBD_MOD_NONE = 0, + KBD_MOD_SHIFT = 1, + KBD_MOD_CTRL = 2, + KBD_MOD_ALT = 4 +} term_event_modifier_T; + struct term_event_keyboard { term_event_key_T key; - int modifier; + term_event_modifier_T modifier; }; struct interlink_event_keyboard { @@ -26,6 +35,9 @@ struct interlink_event_keyboard { * Values >= 0x100 are special; absolute values of constants * from enum term_event_special_key, e.g. -KBD_ENTER. */ int key; + /* The values are from term_event_modifier_T, but the type + * must be int so that the representation remains compatible + * with ELinks 0.11. */ int modifier; }; @@ -77,13 +89,6 @@ static inline int is_kbd_fkey(term_event_key_T key) { return key <= KBD_F1 && ke * which charset it is in, see the definition of term_event_key_T. */ #define is_kbd_character(key) ((key) >= 0) -/* Values for term_event_keyboard.modifier and - * interlink_event_keyboard.modifier */ -#define KBD_MOD_NONE 0 -#define KBD_MOD_SHIFT 1 -#define KBD_MOD_CTRL 2 -#define KBD_MOD_ALT 4 - void handle_trm(int std_in, int std_out, int sock_in, int sock_out, int ctl_in, void *init_string, int init_len, int remote);