6 #include <linux/input.h>
8 #include "libautomation.h"
10 static void atm_input_cb(EV_P_ ev_io
*w
, int revents
) {
11 struct ATM_INPUT
*input
= (struct ATM_INPUT
*) w
;
12 struct input_event event
;
14 if (read(w
->fd
, &event
, sizeof(event
)) == sizeof(event
))
18 struct ATM_INPUT
*atm_input_by_path(const char *path
,
19 void (*cb
)(struct input_event
*)) {
20 char *realpath
= atm_globdup(path
);
22 struct ATM_INPUT
*input
= NULL
;
27 if ((fd
= open(realpath
, O_RDONLY
| O_NONBLOCK
)) < 0) {
28 atm_log("Can't open %s", realpath
);
32 input
= malloc(sizeof(*input
));
34 ev_io_init(&input
->watcher
, atm_input_cb
, fd
, EV_READ
);
35 ev_io_start(EV_A_
&input
->watcher
);