From 88e0899617229db57ae2c616fddcf40543c8e392 Mon Sep 17 00:00:00 2001 From: Dima Zavin Date: Fri, 2 Sep 2011 14:24:43 -0700 Subject: minui: events: only open input devices with EV_KEY and/or EV_REL Change-Id: I8283d7aaa0f66d488f462cd108350cc49657a745 Signed-off-by: Dima Zavin --- minui/events.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'minui/events.c') 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; -- cgit v1.2.3