From 974a8595ed3c09ccef62df7e3748baddb9038d8e Mon Sep 17 00:00:00 2001 From: Guillermo Ramos Date: Sun, 18 Sep 2011 17:08:35 +0200 Subject: Fixed backspace bug --- TODO | 4 ++-- evspy-core.c | 14 ++++++++++---- evspy-core.h | 22 +++++++++++++++++----- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/TODO b/TODO index e2b5880..93ae3bb 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -* Fix backspace key (do not erase special key events) - Prio:Medium -* Implement 2nd mapping (shift) - Prio:Medium FIXED +* Differenciate between capslock and shift (they do not behave the same with + non-alphanumeric keys) - Prio:Low * Take a look at kernel's circular buffer API - Prio:Low * Which FX key has been pressed? - Prio:None diff --git a/evspy-core.c b/evspy-core.c index 55b097c..1bfa578 100644 --- a/evspy-core.c +++ b/evspy-core.c @@ -128,6 +128,9 @@ static void special_char(unsigned int code, unsigned int value) case KEY_TAB: sp_tag = "[TAB]"; break; + case KEY_BACKSPACE: + sp_tag = "[<<]"; + break; case KEY_ESC: sp_tag = "[ESC]"; break; @@ -164,15 +167,18 @@ static void special_char(unsigned int code, unsigned int value) static void evspy_event(struct input_handle *handle, unsigned int type, unsigned int code, int value) { - // Ignore hold-key events - if (unlikely(value == EVS_VAL_HOLD)) + // Ignore non-key and hold events + if (type != EV_KEY || unlikely(value == EVS_VAL_HOLD)) { return; // If caps lock is pressed, handle it the same way as left shift - if (code == KEY_CAPSLOCK && value == EVS_VAL_PRESS) { + } else if (code == KEY_CAPSLOCK && value == EVS_VAL_PRESS) { special_char(KEY_LEFTSHIFT, capslock_state); return; - } else if (type != EV_KEY) { + + // Backspace + } else if (code == KEY_BACKSPACE && value == EVS_VAL_PRESS) { + evs_backspace(); return; } diff --git a/evspy-core.h b/evspy-core.h index 0613b9f..97e9660 100644 --- a/evspy-core.h +++ b/evspy-core.h @@ -18,6 +18,11 @@ #include "maps/maps.h" +// Event values +#define EVS_VAL_FREE 0 +#define EVS_VAL_PRESS 1 +#define EVS_VAL_HOLD 2 + #define MIN(x, y) (x) < (y) ? (x) : (y) /* @@ -65,6 +70,18 @@ evs_decp(rdp); \ }) +/* + * Try to delete the last char inserted. If it is a special key ("[KEY]"), + * insert "[<<]" instead + */ +#define evs_backspace() \ +({ \ + if (*(wrp-1) != ']') \ + evs_delete(); \ + else \ + special_char(KEY_BACKSPACE, EVS_VAL_PRESS); \ +}) + /* * Is the c event code associated to any of the FX buttons? */ @@ -91,8 +108,3 @@ } \ __c; \ }) - -// Event values -#define EVS_VAL_FREE 0 -#define EVS_VAL_PRESS 1 -#define EVS_VAL_HOLD 2 -- cgit v1.2.3