From e2a93ac8c3b64493f2a9d91ec577d6427b5e4701 Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Sat, 5 Aug 2006 12:47:27 +0300 Subject: [PATCH] Renumber special keys to negative values, making room for Unicode. This version should still be interlink compatible with previous ones. --- src/terminal/event.c | 8 ++--- src/terminal/event.h | 4 +++ src/terminal/kbd.h | 69 +++++++++++++++++++++++++------------------- 3 files changed, 47 insertions(+), 34 deletions(-) diff --git a/src/terminal/event.c b/src/terminal/event.c index b69f7e81d..38822a131 100644 --- a/src/terminal/event.c +++ b/src/terminal/event.c @@ -261,11 +261,11 @@ handle_interlink_event(struct terminal *term, struct interlink_event *ilev) case EVENT_KBD: { int utf8_io = -1; - int key; + int key = ilev->info.keyboard.key; - set_kbd_term_event(&tev, ilev->info.keyboard.key, ilev->info.keyboard.modifier); - - key = get_kbd_key(&tev); + if (key >= 0x100) + key = -key; + set_kbd_term_event(&tev, key, ilev->info.keyboard.modifier); reset_timer(); diff --git a/src/terminal/event.h b/src/terminal/event.h index c83b4542d..9a491e377 100644 --- a/src/terminal/event.h +++ b/src/terminal/event.h @@ -78,11 +78,15 @@ 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. */ static inline void set_kbd_interlink_event(struct interlink_event *ev, int key, int modifier) { memset(ev, 0, sizeof(*ev)); ev->ev = EVENT_KBD; + if (key <= -0x100) + key = -key; kbd_set(&ev->info.keyboard, key, modifier); } diff --git a/src/terminal/kbd.h b/src/terminal/kbd.h index 8c88d349b..b9672e46c 100644 --- a/src/terminal/kbd.h +++ b/src/terminal/kbd.h @@ -4,49 +4,58 @@ struct itrm; struct term_event_keyboard { + /* Values <= -0x100 are special; e.g. KBD_ENTER. + * Values between -0xFF and -2 are not used yet; treat as special. + * Value == -1 is KBD_UNDEF; not sent via socket. + * Values between 0 and 0xFF are bytes received from the terminal. + * Values >= 0x100 are not used. */ int key; int modifier; }; 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. */ int key; int modifier; }; #define KBD_UNDEF -1 -#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 +#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) -#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(int key) { return key >= KBD_F1 && key <= KBD_F12; } -#define number_to_kbd_fkey(num) ((num) + KBD_F1 - 1) -#define kbd_fkey_to_number(key) ((key) - KBD_F1 + 1) +#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(int 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 +#define KBD_CTRL_C (-0x200) #define KBD_MOD_NONE 0 #define KBD_MOD_SHIFT 1