diff options
author | David Härdeman <david@hardeman.nu> | 2015-07-22 23:39:29 +0200 |
---|---|---|
committer | David Härdeman <david@hardeman.nu> | 2015-07-22 23:39:29 +0200 |
commit | 10836ae78302aa778553300167f6cdebdf8d884b (patch) | |
tree | ebb7a3501b11682de18055b813ed5007cb7ffd5d /rcm-server-main.c | |
parent | b51c1c648146e49c25c4d6a2a6f5b9b66ea3190d (diff) |
Improve rcm-server integration with evdev generation
Diffstat (limited to 'rcm-server-main.c')
-rw-r--r-- | rcm-server-main.c | 75 |
1 files changed, 54 insertions, 21 deletions
diff --git a/rcm-server-main.c b/rcm-server-main.c index 290ebdc..8dc5a6b 100644 --- a/rcm-server-main.c +++ b/rcm-server-main.c @@ -14,9 +14,9 @@ #include "utils.h" #include "shared.h" -#include "linux-input-keycodes.h" #include "rcm-server-main.h" #include "rcm-server-keymap.h" +#include "rcm-server-evdev.h" static struct device * find_device_by_path(struct manager *mgr, const char *path) @@ -156,9 +156,9 @@ method_getkeymap(sd_bus_message *m, void *userdata, sd_bus_error *error) for (i = 0; i < keymap->keycode_count; i++) { r = sd_bus_message_append(reply, "a{sv}", 3, - "protocol", "s", keymap->keycodes[i].protocol, + "protocol", "s", rc_protocols[keymap->keycodes[i].protocol], "scancode", "t", keymap->keycodes[i].scancode, - "keycode", "s", keymap->keycodes[i].keycode); + "keycode", "s", keymap->keycodes[i].lik->name); if (r < 0) goto out; } @@ -179,7 +179,7 @@ method_getkeymap(sd_bus_message *m, void *userdata, sd_bus_error *error) else r = sd_bus_message_append(reply, "a{sv}", 2, "type", "s", "button", - "keycode", "s", keymap->layout[i]->keycode); + "keycode", "s", keymap->layout[i]->lik->name); if (r < 0) goto out; } @@ -264,9 +264,12 @@ method_setkeymap_parse_dbus_msg(sd_bus_message *m, struct keymap *keymap, while ((r = sd_bus_message_enter_container(m, 'a', "{sv}")) > 0) { const char *protocol = NULL; + unsigned protocol_numeric; uint64_t scancode; bool scancode_found = false; - const char *keycode = NULL; + struct linux_input_keycode *lik = NULL; + const char *keycode; + unsigned i; while ((r = sd_bus_message_enter_container(m, SD_BUS_TYPE_DICT_ENTRY, "sv")) > 0) { const char *name; @@ -304,6 +307,18 @@ method_setkeymap_parse_dbus_msg(sd_bus_message *m, struct keymap *keymap, if (r < 0) return r; + for (i = 0; rc_protocols[i]; i++) { + if (!strcmp(rc_protocols[i], protocol)) + break; + } + + if (!rc_protocols[i]) { + printf("Invalid protocol name (%s)\n", protocol); + return -EINVAL; + } + + protocol_numeric = i; + } else if (!strcmp(name, "scancode")) { if (type != SD_BUS_TYPE_UINT64) { printf("Invalid type for scancode (%c)\n", type); @@ -327,7 +342,7 @@ method_setkeymap_parse_dbus_msg(sd_bus_message *m, struct keymap *keymap, return -EINVAL; } - if (keycode) { + if (lik) { printf("Keycode specified more than once\n"); return -EINVAL; } @@ -336,6 +351,12 @@ method_setkeymap_parse_dbus_msg(sd_bus_message *m, struct keymap *keymap, if (r < 0) return r; + lik = get_linux_keycode_by_name(keycode); + if (!lik) { + printf("Invalid keycode name (%s)\n", keycode); + return -EINVAL; + } + } else { r = sd_bus_message_skip(m, contents); if (r < 0) @@ -364,19 +385,15 @@ method_setkeymap_parse_dbus_msg(sd_bus_message *m, struct keymap *keymap, return -EINVAL; } - if (!keycode) { + if (!lik) { printf("Keycode entry without keycode\n"); return -EINVAL; } if (keymap) { - 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); - - if (!keymap->keycodes[keycode_count].protocol || - !keymap->keycodes[keycode_count].keycode) - return -ENOMEM; + keymap->keycodes[keycode_count].lik = lik; } keycode_count++; @@ -400,12 +417,13 @@ method_setkeymap_parse_dbus_msg(sd_bus_message *m, struct keymap *keymap, while ((r = sd_bus_message_enter_container(m, 'a', "{sv}")) > 0) { bool blank = false; bool button = false; - const char *keycode = NULL; + struct linux_input_keycode *lik = NULL; while ((r = sd_bus_message_enter_container(m, SD_BUS_TYPE_DICT_ENTRY, "sv")) > 0) { const char *name; const char *contents; const char *button_type; + const char *keycode; char type; r = sd_bus_message_read_basic(m, SD_BUS_TYPE_STRING, &name); @@ -454,7 +472,7 @@ method_setkeymap_parse_dbus_msg(sd_bus_message *m, struct keymap *keymap, return -EINVAL; } - if (keycode) { + if (lik) { printf("Multiple keycodes specified in layout\n"); return -EINVAL; } @@ -463,6 +481,12 @@ method_setkeymap_parse_dbus_msg(sd_bus_message *m, struct keymap *keymap, if (r < 0) return r; + lik = get_linux_keycode_by_name(keycode); + if (!lik) { + printf("Invalid keycode name in layout (%s)\n", keycode); + return -EINVAL; + } + } else { r = sd_bus_message_skip(m, contents); if (r < 0) @@ -482,7 +506,7 @@ method_setkeymap_parse_dbus_msg(sd_bus_message *m, struct keymap *keymap, return r; if ((!blank && !button) || (blank && button) || - (button && !keycode) || (blank && keycode)) { + (button && !lik) || (blank && lik)) { printf("Invalid layout specification\n"); return -EINVAL; } @@ -492,12 +516,12 @@ method_setkeymap_parse_dbus_msg(sd_bus_message *m, struct keymap *keymap, keymap->layout[layout_count] = NULL; else { for (i = 0; i < keycode_count; i++) { - if (!strcasecmp(keycode, keymap->keycodes[i].keycode)) + if (keymap->keycodes[i].lik == lik) break; } if (i >= keycode_count) { - printf("Invalid keycode in layout: '%s'\n", keycode); + printf("Invalid keycode in layout: '%s'\n", lik->name); return -EINVAL; } @@ -627,7 +651,7 @@ static const sd_bus_vtable device_vtable[] = { SD_BUS_METHOD("ListKeymaps", NULL, "as", method_listkeymaps, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("GetKeymap", "s", "ssqqaa{sv}aa{sv}", method_getkeymap, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("SetKeymap", "sssqqaa{sv}aa{sv}", NULL, method_setkeymap, SD_BUS_VTABLE_UNPRIVILEGED), - SD_BUS_SIGNAL("KeyPressed", "s", 0), + SD_BUS_SIGNAL("KeyPressed", "sts", 0), SD_BUS_SIGNAL("KeyReleased", "s", 0), SD_BUS_VTABLE_END }; @@ -765,11 +789,18 @@ evdev_read(sd_event_source *s, int fd, uint32_t revents, void *userdata) printf(" scancode 0x%08x", scancode); printf("\n"); - if (keycode != KEY_RESERVED) + /* FIXME: protocol needs kernel support */ + if (pressed && scancode_recv) sd_bus_emit_signal(device->mgr->bus, device->path, "org.gnome.RemoteControlManager.Device", - pressed ? "KeyPressed" : "KeyReleased", + "KeyPressed", + "sts", "nec", scancode, keycode_str); + else if (!pressed && keycode != KEY_RESERVED) + sd_bus_emit_signal(device->mgr->bus, + device->path, + "org.gnome.RemoteControlManager.Device", + "KeyReleased", "s", keycode_str); } @@ -867,6 +898,8 @@ add_device(struct manager *mgr, struct udev_device *udev) continue; } + evdev_setup(device); + if (sd_event_add_io(mgr->event, &device->evdev_ev, device->evdev_fd, EPOLLIN, evdev_read, device) < 0) { printf("Failed to add event source for evdev device %s: %s\n", |