diff options
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | evspy-core.c | 16 | ||||
-rw-r--r-- | evspy-core.h | 22 | ||||
-rw-r--r-- | khm/Makefile | 8 | ||||
-rw-r--r-- | khm/test_khm.c | 9 | ||||
-rw-r--r-- | maps/map_en.h | 55 | ||||
-rw-r--r-- | maps/map_es.h | 86 | ||||
-rw-r--r-- | maps/maps.h | 9 |
8 files changed, 151 insertions, 56 deletions
@@ -1,5 +1,3 @@ -* Register ALTGR-KEY - Prio:Mid - * Differenciate between capslock and shift (they do not behave the same with non-alphanumeric keys) - Prio:Low * Support non-ascii characters - Prio:Low diff --git a/evspy-core.c b/evspy-core.c index 0f5799b..49ec3f8 100644 --- a/evspy-core.c +++ b/evspy-core.c @@ -28,6 +28,7 @@ static char *rdp; // read pointer static char *wrp; // write pointer static unsigned short int capslock_state = EVS_VAL_FREE; static unsigned short int shift = 0; +static unsigned short int altgr = 0; /* * Executed when the procfs file is read (EVS_PROCNAME) @@ -115,8 +116,13 @@ static void special_char(unsigned int code, unsigned int value) sp_tag = "[+ALT]"; break; case KEY_RIGHTALT: +#ifdef EVS_ALTGR_ENABLED + altgr = !altgr; + return; +#else sp_tag = "[+ALTGR]"; break; +#endif case KEY_LEFTCTRL: case KEY_RIGHTCTRL: sp_tag = "[+CTRL]"; @@ -189,7 +195,9 @@ static void evspy_event(struct input_handle *handle, unsigned int type, // "Direct" keys (alphanumeric + some symbols) } else if (value == EVS_VAL_PRESS) { - if (shift) + if (altgr) + evs_insert(evs_altgr(code)); + else if (shift) evs_insert(evs_shift(code)); else evs_insert(map[code]); @@ -253,6 +261,9 @@ static int __init evspy_init(void) { create_proc_read_entry(EVS_PROCNAME, 0, NULL, evspy_read_proc, NULL); init_shiftmap(); +#ifdef EVS_ALTGR_ENABLED + init_altgrmap(); +#endif buffer = kmalloc(EVS_BUFSIZE, GFP_KERNEL); rdp = wrp = buffer; return !buffer || input_register_handler(&evspy_handler); @@ -262,6 +273,9 @@ static void __exit evspy_exit(void) { input_unregister_handler(&evspy_handler); kfree(buffer); +#ifdef EVS_ALTGR_ENABLED + exit_altgrmap(); +#endif exit_shiftmap(); remove_proc_entry(EVS_PROCNAME, NULL); } diff --git a/evspy-core.h b/evspy-core.h index 03ade62..5b7abec 100644 --- a/evspy-core.h +++ b/evspy-core.h @@ -111,7 +111,7 @@ /* * Is the c event code associated to any of the FX buttons? */ -#define evs_isfX(c) \ +#define evs_isfX(c) \ ({ \ ((c) >= KEY_F1 && (c) <= KEY_F10) || \ ((c) == KEY_F11 || (c) == KEY_F12) || \ @@ -134,3 +134,23 @@ } \ __c; \ }) + +/* + * Returns the character associated with event code c when altgr is pressed + */ +#ifdef EVS_ALTGR_ENABLED +# define evs_altgr(c) \ + ({ \ + void *__vp; \ + char __c; \ + __vp = khm_get(ahm, (c)); \ + if (__vp) __c = *(char *)__vp; \ + else __c = map[c]; \ + __c; \ + }) +#else +# define evs_altgr(c) \ + ({ \ + (c); \ + }) +#endif diff --git a/khm/Makefile b/khm/Makefile new file mode 100644 index 0000000..74ffd5f --- /dev/null +++ b/khm/Makefile @@ -0,0 +1,8 @@ +obj-m += test.o +test-objs := khm.o test_khm.o + +all: + make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules + +clean: + make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean diff --git a/khm/test_khm.c b/khm/test_khm.c index 5b822b5..d8b0180 100644 --- a/khm/test_khm.c +++ b/khm/test_khm.c @@ -1,6 +1,6 @@ #include <linux/module.h> #include <linux/init.h> -#include "khashmap.h" +#include "khm.h" #define Z_ASD 1 #define Z_QWE 2 @@ -14,6 +14,11 @@ static int __init test_init(void) hm = khm_create(); + if ((values = (char*)khm_get(hm, Z_BLR))) + printk(KERN_ALERT "ERROR: Z_BLR exists: %s\n", values); + else + printk(KERN_ALERT "Z_BLR does not exist (good)\n"); + if (khm_insert(hm, Z_ASD, "ASDF")) goto insert_err; if (khm_insert(hm, Z_QWE, "QWERTY")) @@ -46,7 +51,7 @@ static int __init test_init(void) return 0; insert_err: - printk(KERN_ALERT "Error inserting!\n"); + printk(KERN_ALERT "Error inserting (good)\n"); return 0; } diff --git a/maps/map_en.h b/maps/map_en.h index 58a379e..93b9db7 100644 --- a/maps/map_en.h +++ b/maps/map_en.h @@ -6,31 +6,42 @@ #ifndef __EVS_MAP_EN #define __EVS_MAP_EN + +// Shift map +#define EVS_SHIFT_BIND(KEY, VALUE) khm_insert(shm, (KEY), (VALUE)) + +static struct khashmap *shm; + static void init_shiftmap(void) { shm = khm_create(); - EVS_SHIFT(KEY_1, "!"); - EVS_SHIFT(KEY_2, "@"); - EVS_SHIFT(KEY_3, "#"); - EVS_SHIFT(KEY_4, "$"); - EVS_SHIFT(KEY_5, "%"); - EVS_SHIFT(KEY_6, "^"); - EVS_SHIFT(KEY_7, "&"); - EVS_SHIFT(KEY_8, "*"); - EVS_SHIFT(KEY_9, "("); - EVS_SHIFT(KEY_0, ")"); - EVS_SHIFT(KEY_MINUS, "_"); - EVS_SHIFT(KEY_EQUAL, "+"); - EVS_SHIFT(KEY_LEFTBRACE, "{"); - EVS_SHIFT(KEY_RIGHTBRACE, "}"); - EVS_SHIFT(KEY_SEMICOLON, ":"); - EVS_SHIFT(KEY_APOSTROPHE, "\""); - EVS_SHIFT(KEY_GRAVE, "|"); - EVS_SHIFT(KEY_BACKSLASH, "|"); - EVS_SHIFT(KEY_COMMA, "<"); - EVS_SHIFT(KEY_DOT, ">"); - EVS_SHIFT(KEY_SLASH, "?"); - EVS_SHIFT(KEY_102ND, ">"); + EVS_SHIFT_BIND(KEY_1, "!"); + EVS_SHIFT_BIND(KEY_2, "@"); + EVS_SHIFT_BIND(KEY_3, "#"); + EVS_SHIFT_BIND(KEY_4, "$"); + EVS_SHIFT_BIND(KEY_5, "%"); + EVS_SHIFT_BIND(KEY_6, "^"); + EVS_SHIFT_BIND(KEY_7, "&"); + EVS_SHIFT_BIND(KEY_8, "*"); + EVS_SHIFT_BIND(KEY_9, "("); + EVS_SHIFT_BIND(KEY_0, ")"); + EVS_SHIFT_BIND(KEY_MINUS, "_"); + EVS_SHIFT_BIND(KEY_EQUAL, "+"); + EVS_SHIFT_BIND(KEY_LEFTBRACE, "{"); + EVS_SHIFT_BIND(KEY_RIGHTBRACE, "}"); + EVS_SHIFT_BIND(KEY_SEMICOLON, ":"); + EVS_SHIFT_BIND(KEY_APOSTROPHE, "\""); + EVS_SHIFT_BIND(KEY_GRAVE, "|"); + EVS_SHIFT_BIND(KEY_BACKSLASH, "|"); + EVS_SHIFT_BIND(KEY_COMMA, "<"); + EVS_SHIFT_BIND(KEY_DOT, ">"); + EVS_SHIFT_BIND(KEY_SLASH, "?"); + EVS_SHIFT_BIND(KEY_102ND, ">"); +} + +static inline void exit_shiftmap(void) +{ + khm_destroy(shm); } static char map[] = { diff --git a/maps/map_es.h b/maps/map_es.h index 763e7cc..1b0946f 100644 --- a/maps/map_es.h +++ b/maps/map_es.h @@ -6,28 +6,76 @@ #ifndef __EVS_MAP_ES #define __EVS_MAP_ES + +// Right Alt (ALTGR) map +#define EVS_ALTGR_ENABLED +#define EVS_ALTGR_BIND(KEY, VALUE) khm_insert(ahm, (KEY), (VALUE)) + +static struct khashmap *ahm; + +static void init_altgrmap(void) +{ + ahm = khm_create(); + EVS_ALTGR_BIND(KEY_1, "|"); + EVS_ALTGR_BIND(KEY_2, "@"); + EVS_ALTGR_BIND(KEY_3, "#"); + EVS_ALTGR_BIND(KEY_4, "~"); +// EVS_ALTGR_BIND(KEY_5, "½"); // TODO enable +// EVS_ALTGR_BIND(KEY_6, "¬"); // TODO enable + EVS_ALTGR_BIND(KEY_7, "{"); + EVS_ALTGR_BIND(KEY_8, "["); + EVS_ALTGR_BIND(KEY_9, "]"); + EVS_ALTGR_BIND(KEY_0, "}"); + EVS_ALTGR_BIND(KEY_MINUS, "\\"); + EVS_ALTGR_BIND(KEY_EQUAL, "~"); + EVS_ALTGR_BIND(KEY_LEFTBRACE, "["); + EVS_ALTGR_BIND(KEY_RIGHTBRACE, "]"); + EVS_ALTGR_BIND(KEY_SEMICOLON, "~"); + EVS_ALTGR_BIND(KEY_APOSTROPHE, "{"); + EVS_ALTGR_BIND(KEY_GRAVE, "}"); + EVS_ALTGR_BIND(KEY_BACKSLASH, "}"); + EVS_ALTGR_BIND(KEY_COMMA, "─"); +// EVS_ALTGR_BIND(KEY_DOT, "·"); // TODO enable + EVS_ALTGR_BIND(KEY_102ND, "|"); +} + +static inline void exit_altgrmap(void) +{ + khm_destroy(ahm); +} + +// Shift map +#define EVS_SHIFT_BIND(KEY, VALUE) khm_insert(shm, (KEY), (VALUE)) + +static struct khashmap *shm; + static void init_shiftmap(void) { shm = khm_create(); - EVS_SHIFT(KEY_1, "!"); - EVS_SHIFT(KEY_2, "\""); - EVS_SHIFT(KEY_4, "$"); - EVS_SHIFT(KEY_5, "%"); - EVS_SHIFT(KEY_6, "&"); - EVS_SHIFT(KEY_7, "/"); - EVS_SHIFT(KEY_8, "("); - EVS_SHIFT(KEY_9, ")"); - EVS_SHIFT(KEY_0, "="); - EVS_SHIFT(KEY_MINUS, "?"); - EVS_SHIFT(KEY_EQUAL, "?"); // TODO change to '¿' - EVS_SHIFT(KEY_LEFTBRACE, "^"); - EVS_SHIFT(KEY_RIGHTBRACE, "*"); - EVS_SHIFT(KEY_SEMICOLON, "N"); // TODO change to 'Ñ' -// EVS_SHIFT(KEY_GRAVE, "Ç"); // TODO enable - EVS_SHIFT(KEY_COMMA, ";"); - EVS_SHIFT(KEY_DOT, ":"); - EVS_SHIFT(KEY_SLASH, "_"); - EVS_SHIFT(KEY_102ND, ">"); + EVS_SHIFT_BIND(KEY_1, "!"); + EVS_SHIFT_BIND(KEY_2, "\""); + EVS_SHIFT_BIND(KEY_4, "$"); + EVS_SHIFT_BIND(KEY_5, "%"); + EVS_SHIFT_BIND(KEY_6, "&"); + EVS_SHIFT_BIND(KEY_7, "/"); + EVS_SHIFT_BIND(KEY_8, "("); + EVS_SHIFT_BIND(KEY_9, ")"); + EVS_SHIFT_BIND(KEY_0, "="); + EVS_SHIFT_BIND(KEY_MINUS, "?"); + EVS_SHIFT_BIND(KEY_EQUAL, "?"); // TODO change to '¿' + EVS_SHIFT_BIND(KEY_LEFTBRACE, "^"); + EVS_SHIFT_BIND(KEY_RIGHTBRACE, "*"); + EVS_SHIFT_BIND(KEY_SEMICOLON, "N"); // TODO change to 'Ñ' +// EVS_SHIFT_BIND(KEY_GRAVE, "Ç"); // TODO enable + EVS_SHIFT_BIND(KEY_COMMA, ";"); + EVS_SHIFT_BIND(KEY_DOT, ":"); + EVS_SHIFT_BIND(KEY_SLASH, "_"); + EVS_SHIFT_BIND(KEY_102ND, ">"); +} + +static inline void exit_shiftmap(void) +{ + khm_destroy(shm); } static char map[] = { diff --git a/maps/maps.h b/maps/maps.h index f4fc856..37497bc 100644 --- a/maps/maps.h +++ b/maps/maps.h @@ -29,15 +29,6 @@ #include <linux/input.h> #include "../khm/khm.h" -#define EVS_SHIFT(KEY, VALUE) khm_insert(shm, (KEY), (VALUE)) - -// Shift map -static struct khashmap *shm; - -static inline void exit_shiftmap(void) -{ - khm_destroy(shm); -} // Load the map associated with the given keyboard layout #ifndef EVS_KLAY |