summaryrefslogtreecommitdiff
path: root/src/libsystemd-terminal/idev.c
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@gmail.com>2014-08-27 18:31:34 +0200
committerDavid Herrmann <dh.herrmann@gmail.com>2014-08-27 18:42:28 +0200
commitc93e5a62ff599528c3bf2a8656825403aaebe093 (patch)
tree4aed2f2ccaad553397e60d68851b5fdc80307d6e /src/libsystemd-terminal/idev.c
parente202fa31fb2d60084e7b2ab7976a81c138184d40 (diff)
terminal: add evdev elements to idev
The evdev-element provides linux evdev interfaces as idev-elements. This way, all real input hardware devices on linux can be used with the idev interface. We use libevdev to interface with the kernel. It's a simple wrapper library around the kernel evdev API that takes care to resync devices after kernel-queue overflows, which is a rather non-trivial task. Furthermore, it's a well tested interface used by all other major input users (Xorg, weston, libinput, ...). Last but not least, it provides nice keycode to keyname lookup tables (and vice versa), which is really nice for debugging input problems.
Diffstat (limited to 'src/libsystemd-terminal/idev.c')
-rw-r--r--src/libsystemd-terminal/idev.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/libsystemd-terminal/idev.c b/src/libsystemd-terminal/idev.c
index 5e3080797a..2316a66529 100644
--- a/src/libsystemd-terminal/idev.c
+++ b/src/libsystemd-terminal/idev.c
@@ -20,6 +20,8 @@
***/
#include <inttypes.h>
+#include <libudev.h>
+#include <linux/input.h>
#include <stdbool.h>
#include <stdlib.h>
#include <systemd/sd-bus.h>
@@ -31,6 +33,7 @@
#include "login-shared.h"
#include "macro.h"
#include "set.h"
+#include "udev-util.h"
#include "util.h"
static void element_open(idev_element *e);
@@ -522,6 +525,51 @@ void idev_session_disable(idev_session *s) {
}
}
+int idev_session_add_evdev(idev_session *s, struct udev_device *ud) {
+ idev_element *e;
+ dev_t devnum;
+ int r;
+
+ assert_return(s, -EINVAL);
+ assert_return(ud, -EINVAL);
+
+ devnum = udev_device_get_devnum(ud);
+ if (devnum == 0)
+ return 0;
+
+ e = idev_find_evdev(s, devnum);
+ if (e)
+ return 0;
+
+ r = idev_evdev_new(&e, s, ud);
+ if (r < 0)
+ return r;
+
+ r = session_add_element(s, e);
+ if (r != 0)
+ return r;
+
+ return 0;
+}
+
+int idev_session_remove_evdev(idev_session *s, struct udev_device *ud) {
+ idev_element *e;
+ dev_t devnum;
+
+ assert(s);
+ assert(ud);
+
+ devnum = udev_device_get_devnum(ud);
+ if (devnum == 0)
+ return 0;
+
+ e = idev_find_evdev(s, devnum);
+ if (!e)
+ return 0;
+
+ return session_remove_element(s, e);
+}
+
/*
* Contexts
*/