From 006f4f036b0a1643e4d942cf7e56760cde287f5b Mon Sep 17 00:00:00 2001 From: David Härdeman Date: Mon, 17 Apr 2017 11:32:30 +0200 Subject: Add hacked-up kernel protocol report support --- rcm-server-evdev.c | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/rcm-server-evdev.c b/rcm-server-evdev.c index 3b76482..15ae5ff 100644 --- a/rcm-server-evdev.c +++ b/rcm-server-evdev.c @@ -37,6 +37,15 @@ struct rc_keymap_entry { }; #define RKE_SIZE (sizeof(struct rc_scancode)) +static const char * +evdev_get_protocol_name(__u16 protocol) +{ + if (protocol > ARRAY_SIZE(rc_protocols)) + return NULL; + + return rc_protocols[protocol]; +} + static const char * evdev_guess_protocol(struct device *device, uint64_t scancode, uint32_t keycode) { @@ -60,10 +69,7 @@ evdev_guess_protocol(struct device *device, uint64_t scancode, uint32_t keycode) if (rke.keycode != keycode) continue; - if (rke.rc.protocol > ARRAY_SIZE(rc_protocols)) - return NULL; - - return rc_protocols[rke.rc.protocol]; + return evdev_get_protocol_name(rke.rc.protocol); } return NULL; @@ -202,6 +208,8 @@ evdev_read(sd_event_source *s, int fd, uint32_t revents, void *userdata) static bool pressed = false; static uint32_t scancode; static bool scancode_recv = false; + static uint32_t protocol; + static bool protocol_recv = false; int r; if (fd != device->evdev_fd) @@ -261,21 +269,30 @@ evdev_read(sd_event_source *s, int fd, uint32_t revents, void *userdata) printf("Reading from evdev - multiple scancodes?\n"); scancode_recv = true; scancode = ev.value; + } else if (ev.code == MSC_RAW) { + if (protocol_recv) + printf("Reading from evdev - multiple protocols?\n"); + protocol_recv = true; + protocol = ev.value; } break; case EV_SYN: if (keycode || scancode_recv) { - const char *protocol; - - /* FIXME: protocol reporting needs kernel support */ - if (scancode_recv) - protocol = evdev_guess_protocol(device, scancode, keycode ? keycode->value : KEY_RESERVED); + const char *protocol_name = NULL; printf("evdev -"); + /* FIXME: protocol reporting will change */ if (scancode_recv) { - printf(" protocol %s (guessed)", protocol); + if (!protocol_recv) { + protocol_name = evdev_guess_protocol(device, scancode, keycode ? keycode->value : KEY_RESERVED); + printf(" protocol %s (guessed)", protocol_name); + } else { + protocol_name = evdev_get_protocol_name(protocol); + printf(" protocol %s", protocol_name); + } + printf(" scancode 0x%08x", scancode); } @@ -286,12 +303,12 @@ evdev_read(sd_event_source *s, int fd, uint32_t revents, void *userdata) printf("\n"); - if (scancode_recv) + if (scancode_recv && protocol_name) sd_bus_emit_signal(device->mgr->bus, device->path, "org.gnome.RemoteControlManager.Device", "KeyPressed", - "sts", protocol ? protocol : "NEC", scancode, + "sts", protocol_name, scancode, keycode ? keycode->name : "KEY_RESERVED"); else if (keycode && !pressed) @@ -303,6 +320,7 @@ evdev_read(sd_event_source *s, int fd, uint32_t revents, void *userdata) } scancode_recv = false; + protocol_recv = false; pressed = false; keycode = NULL; break; -- cgit v1.2.3