summaryrefslogtreecommitdiff
path: root/rcm-server-keymap.c
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2015-07-22 23:39:29 +0200
committerDavid Härdeman <david@hardeman.nu>2015-07-22 23:39:29 +0200
commit10836ae78302aa778553300167f6cdebdf8d884b (patch)
treeebb7a3501b11682de18055b813ed5007cb7ffd5d /rcm-server-keymap.c
parentb51c1c648146e49c25c4d6a2a6f5b9b66ea3190d (diff)
Improve rcm-server integration with evdev generation
Diffstat (limited to 'rcm-server-keymap.c')
-rw-r--r--rcm-server-keymap.c46
1 files changed, 32 insertions, 14 deletions
diff --git a/rcm-server-keymap.c b/rcm-server-keymap.c
index 04dd1a4..15b7fe8 100644
--- a/rcm-server-keymap.c
+++ b/rcm-server-keymap.c
@@ -14,7 +14,7 @@
#include <limits.h>
#include "utils.h"
-#include "linux-input-keycodes.h"
+#include "shared.h"
#include "rcm-server-main.h"
#include "rcm-server-keymap.h"
@@ -202,13 +202,15 @@ keymap_parse(FILE *fp, char **line, size_t *buf_size, struct keymap *keymap,
char *keycode;
char *end;
uint64_t scancode;
+ unsigned protocol_numeric;
+ struct linux_input_keycode *lik;
protocol = strtok(tmp, " :");
scanstr = strtok(NULL, " :");
keycode = strtok(NULL, " :");
end = strtok(NULL, " :");
- if (!protocol || !scancode || !keycode || end) {
+ if (!protocol || !scanstr || !keycode || end) {
fprintf(stderr, "Invalid map directive\n");
return -ENOMEM;
}
@@ -219,21 +221,28 @@ keymap_parse(FILE *fp, char **line, size_t *buf_size, struct keymap *keymap,
return r;
}
- for (i = 0; linux_input_keycodes[i].name; i++) {
- if (!strcmp(keycode, linux_input_keycodes[i].name))
+ for (i = 0; rc_protocols[i]; i++) {
+ if (!strcasecmp(protocol, rc_protocols[i]))
break;
}
- if (!linux_input_keycodes[i].name || linux_input_keycodes[i].value < 1) {
+ if (!rc_protocols[i]) {
+ fprintf(stderr, "Invalid protocol value\n");
+ return -EINVAL;
+ }
+
+ protocol_numeric = i;
+
+ lik = get_linux_keycode_by_name(keycode);
+ if (!lik || lik->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].protocol = protocol_numeric;
keymap->keycodes[keycode_count].scancode = scancode;
- keymap->keycodes[keycode_count].keycode = strdup(keycode);
+ keymap->keycodes[keycode_count].lik = lik;
}
keycode_count++;
} else {
@@ -248,12 +257,21 @@ keymap_parse(FILE *fp, char **line, size_t *buf_size, struct keymap *keymap,
if (!strcasecmp(tmp, "Blank"))
keymap->layout[layout_count] = NULL;
else {
- for (i = 0; i < keycode_count; i++)
- if (!strcasecmp(tmp, keymap->keycodes[i].keycode))
+ struct linux_input_keycode *lik;
+
+ lik = get_linux_keycode_by_name(tmp);
+ if (!lik) {
+ fprintf(stderr, "Invalid keycode: %s\n", tmp);
+ return -EINVAL;
+ }
+
+ for (i = 0; i < keycode_count; i++) {
+ if (keymap->keycodes[i].lik == lik)
break;
+ }
if (i >= keycode_count) {
- fprintf(stderr, "Invalid button keycode: %s\n", tmp);
+ fprintf(stderr, "Keycode '%s' not in keymap\n", tmp);
return -EINVAL;
}
@@ -490,16 +508,16 @@ keymap_write(struct keymap *keymap)
fprintf(file, "[Keymap]\n");
for (i = 0; i < keymap->keycode_count; i++) {
fprintf(file, "Map=%s:0x%08" PRIx64 ":%s\n",
- keymap->keycodes[i].protocol,
+ rc_protocols[keymap->keycodes[i].protocol],
keymap->keycodes[i].scancode,
- keymap->keycodes[i].keycode);
+ keymap->keycodes[i].lik->name);
}
fprintf(file, "\n");
fprintf(file, "[Layout]\n");
for (i = 0; i < (keymap->rows * keymap->cols); i++) {
if (keymap->layout[i])
- fprintf(file, "Button=%s\n", keymap->layout[i]->keycode);
+ fprintf(file, "Button=%s\n", keymap->layout[i]->lik->name);
else
fprintf(file, "Button=Blank\n");
}