minui: events: only open input devices with EV_KEY and/or EV_REL
Change-Id: I8283d7aaa0f66d488f462cd108350cc49657a745 Signed-off-by: Dima Zavin <dima@android.com>
This commit is contained in:
parent
365836736c
commit
88e0899617
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user