summaryrefslogtreecommitdiff
path: root/rcm-server-keymap.c
diff options
context:
space:
mode:
Diffstat (limited to 'rcm-server-keymap.c')
-rw-r--r--rcm-server-keymap.c40
1 files changed, 34 insertions, 6 deletions
diff --git a/rcm-server-keymap.c b/rcm-server-keymap.c
index af72045..8a4fa3e 100644
--- a/rcm-server-keymap.c
+++ b/rcm-server-keymap.c
@@ -14,6 +14,7 @@
#include <limits.h>
#include "utils.h"
+#include "linux-input-keycodes.h"
#include "rcm-server-main.h"
#include "rcm-server-keymap.h"
@@ -175,7 +176,6 @@ keymap_parse(FILE *fp, char **line, size_t *buf_size, struct keymap *keymap,
char *end;
uint64_t scancode;
- printf("Map %s\n", tmp);
protocol = strtok(tmp, " :");
scanstr = strtok(NULL, " :");
keycode = strtok(NULL, " :");
@@ -192,14 +192,24 @@ keymap_parse(FILE *fp, char **line, size_t *buf_size, struct keymap *keymap,
return r;
}
- printf("Map means protocol %s scancode 0x%08" PRIx64 " keycode %s\n",
- protocol, scancode, keycode);
+ for (i = 0; linux_input_keycodes[i].name; i++) {
+ if (!strcmp(keycode, linux_input_keycodes[i].name))
+ break;
+ }
+
+ if (!linux_input_keycodes[i].name || linux_input_keycodes[i].value < 1) {
+ fprintf(stderr, "Invalid keycode name: %s\n", keycode);
+ return -EINVAL;
+ }
if (keymap) {
/* FIXME: leaks */
keymap->keycodes[keycode_count].protocol = strdup(protocol);
keymap->keycodes[keycode_count].scancode = scancode;
keymap->keycodes[keycode_count].keycode = strdup(keycode);
+ printf("\tMapping: protocol %s scancode 0x%08" PRIx64 " keycode %s\n",
+ protocol, scancode, keycode);
+
}
keycode_count++;
} else {
@@ -236,8 +246,18 @@ keymap_parse(FILE *fp, char **line, size_t *buf_size, struct keymap *keymap,
if (keymap) {
if (!strcasecmp(tmp, "Blank"))
keymap->layout[layout_count] = NULL;
- else
- keymap->layout[layout_count] = &keymap->keycodes[1];
+ else {
+ for (i = 0; i < keycode_count; i++)
+ if (!strcasecmp(tmp, keymap->keycodes[i].keycode))
+ break;
+
+ if (i >= keycode_count) {
+ fprintf(stderr, "Invalid button keycode: %s\n", tmp);
+ return -EINVAL;
+ }
+
+ keymap->layout[layout_count] = &keymap->keycodes[i];
+ }
}
layout_count++;
@@ -321,6 +341,7 @@ keymap_read(int dfd, const char *name)
return NULL;
fd = -1;
+ printf("Parsing keymap %s\n", name);
r = keymap_parse(fp, &line, &buf_size, NULL, &rows, &cols, &keycode_count);
if (r < 0) {
fprintf(stderr, "Invalid keymap: %s\n", name);
@@ -337,7 +358,14 @@ keymap_read(int dfd, const char *name)
return NULL;
}
- keymap_parse(fp, &line, &buf_size, keymap, NULL, NULL, NULL);
+ r = keymap_parse(fp, &line, &buf_size, keymap, NULL, NULL, NULL);
+ if (r < 0) {
+ fprintf(stderr, "Invalid keymap: %s\n", name);
+ free(keymap->layout);
+ free(keymap);
+ return NULL;
+ }
+ printf("\tLayout: %u rows x %u cols = %u entries\n", rows, cols, rows * cols);
return keymap;
}