summaryrefslogtreecommitdiffstats
path: root/minui
diff options
context:
space:
mode:
Diffstat (limited to 'minui')
-rw-r--r--minui/events.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/minui/events.c b/minui/events.c
index 8458b2d39..c533a482a 100644
--- a/minui/events.c
+++ b/minui/events.c
@@ -27,6 +27,8 @@
#define MAX_DEVICES 16
#define MAX_MISC_FDS 16
+#define test_bit(bit, array) ((array)[(bit)/8] & (1<<((bit)%8)))
+
struct fd_info {
ev_callback cb;
void *data;
@@ -48,11 +50,26 @@ int ev_init(ev_callback input_cb, void *data)
dir = opendir("/dev/input");
if(dir != 0) {
while((de = readdir(dir))) {
+ uint8_t ev_bits[(EV_MAX + 1) / 8];
+
// fprintf(stderr,"/dev/input/%s\n", de->d_name);
if(strncmp(de->d_name,"event",5)) continue;
fd = openat(dirfd(dir), de->d_name, O_RDONLY);
if(fd < 0) continue;
+ /* read the evbits of the input device */
+ if (ioctl(fd, EVIOCGBIT(0, sizeof(ev_bits)), ev_bits) < 0) {
+ close(fd);
+ continue;
+ }
+
+ /* TODO: add ability to specify event masks. For now, just assume
+ * that only EV_KEY and EV_REL event types are ever needed. */
+ if (!test_bit(EV_KEY, ev_bits) && !test_bit(EV_REL, ev_bits)) {
+ close(fd);
+ continue;
+ }
+
ev_fds[ev_count].fd = fd;
ev_fds[ev_count].events = POLLIN;
ev_fdinfo[ev_count].cb = input_cb;