summaryrefslogtreecommitdiff
path: root/rcm-server-evdev.c
diff options
context:
space:
mode:
Diffstat (limited to 'rcm-server-evdev.c')
-rw-r--r--rcm-server-evdev.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/rcm-server-evdev.c b/rcm-server-evdev.c
index 9423806..bc8361e 100644
--- a/rcm-server-evdev.c
+++ b/rcm-server-evdev.c
@@ -33,6 +33,38 @@ struct rc_keymap_entry {
};
#define RKE_SIZE (sizeof(struct rc_scancode))
+const char *
+evdev_guess_protocol(struct device *device, uint64_t scancode, uint32_t keycode)
+{
+ struct rc_keymap_entry rke;
+ unsigned i;
+
+ if (!device || device->evdev_fd < 0)
+ return NULL;
+
+ for (i = 0; ; i++) {
+ memset(&rke, 0, sizeof(rke));
+ rke.len = RKE_SIZE;
+ rke.index = i;
+ rke.flags = INPUT_KEYMAP_BY_INDEX;
+ if (ioctl(device->evdev_fd, EVIOCGKEYCODE_V2, &rke))
+ break;
+
+ if (rke.u.rc.scancode != scancode)
+ continue;
+
+ if (rke.keycode != keycode)
+ continue;
+
+ if (rke.u.rc.protocol > ARRAY_SIZE(rc_protocols))
+ return NULL;
+
+ return rc_protocols[rke.u.rc.protocol];
+ }
+
+ return NULL;
+}
+
static int
evdev_clear_keymap(struct device *device)
{