summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rcm-server-evdev.c42
1 files 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
@@ -38,6 +38,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)
{
struct rc_keymap_entry rke;
@@ -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;