2 * Copyright (C) 2007 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 #include <linux/input.h>
25 #include "include/minui.h"
27 #define MAX_DEVICES 16
29 static struct pollfd ev_fds
[MAX_DEVICES
];
30 static unsigned ev_count
= 0;
38 dir
= opendir("/dev/input");
40 while((de
= readdir(dir
))) {
41 // fprintf(stderr,"/dev/input/%s\n", de->d_name);
42 if(strncmp(de
->d_name
,"event",5)) continue;
43 fd
= openat(dirfd(dir
), de
->d_name
, O_RDONLY
);
46 ev_fds
[ev_count
].fd
= fd
;
47 ev_fds
[ev_count
].events
= POLLIN
;
49 if(ev_count
== MAX_DEVICES
) break;
58 while (ev_count
> 0) {
59 close(ev_fds
[--ev_count
].fd
);
63 int ev_get(struct input_event
*ev
, unsigned dont_wait
)
69 r
= poll(ev_fds
, ev_count
, dont_wait
? 0 : -1);
72 for(n
= 0; n
< ev_count
; n
++) {
73 if(ev_fds
[n
].revents
& POLLIN
) {
74 r
= read(ev_fds
[n
].fd
, ev
, sizeof(*ev
));
75 if(r
== sizeof(*ev
)) return 0;
79 } while(dont_wait
== 0);