From e02bde2201a424978f1fe70aff934a3c688dbddd Mon Sep 17 00:00:00 2001 From: Alessandro Mauri Date: Wed, 16 Feb 2022 17:58:17 +0100 Subject: [PATCH] works kinda --- Makefile | 2 +- btor.c | 23 ++++++++--------------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 17d3552..89d89bc 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ .POSIX: CC = gcc -CFLAGS = -Wall -Werror -Wextra -pedantic -std=c11 +CFLAGS = -Wall -Werror -Wextra -pedantic -std=c11 -O2 btor: btor.c ${CC} ${LDFLAGS} ${CFLAGS} btor.c -o btor diff --git a/btor.c b/btor.c index 2756f4f..ed2a283 100644 --- a/btor.c +++ b/btor.c @@ -38,7 +38,8 @@ int main(int argc, char **argv) if ((st.st_mode & S_IFMT) != S_IFCHR) continue; - int tmp_fd = openat(dirfd(dir), dp->d_name, O_RDWR | O_NONBLOCK); + // blocking io + int tmp_fd = openat(dirfd(dir), dp->d_name, O_RDWR); if (tmp_fd < 0) err(1, "openat:"); union { @@ -47,12 +48,12 @@ int main(int argc, char **argv) } vec; if (ioctl(tmp_fd, EVIOCGBIT(0, EV_MAX), vec.b) < 0) err(1, "ioctl:"); - if (!test_bit(EV_KEY, vec.b)) + if (!test_bit(EV_KEY, vec.b) || !test_bit(EV_ABS, vec.b)) continue; if (ioctl(tmp_fd, EVIOCGBIT(EV_KEY, KEY_MAX), vec.k) < 0) err(1, "ioctl:"); - if (test_bit(BTN_STYLUS, vec.k) && test_bit(EV_ABS, vec.k)) { + if (test_bit(BTN_STYLUS, vec.k) && test_bit(BTN_TOOL_RUBBER, vec.k)) { stylus = tmp_fd; break; } @@ -65,28 +66,20 @@ int main(int argc, char **argv) int poll_set = epoll_create(1); if (poll_set < 0) err(1, "epoll_create:"); - struct epoll_event poll_ev = { .events = EPOLLIN | EPOLLOUT | EPOLLET }; + struct epoll_event poll_ev = { .events = EPOLLIN }; if (epoll_ctl(poll_set, EPOLL_CTL_ADD, stylus, &poll_ev) < 0) err(1, "epoll_ctl:"); - - unsigned char button_recived = 0; struct input_event in_ev, out_ev; while (epoll_wait(poll_set, &poll_ev, 1, -1) != -1) { switch (poll_ev.events) { case EPOLLIN: if (read(stylus, &in_ev, sizeof(struct input_event)) < 0) err(1, "read:"); - if (in_ev.type != BTN_STYLUS) - break; - out_ev.type = BTN_TOOL_RUBBER; - out_ev.value = in_ev.value; - button_recived = 1; - break; - case EPOLLOUT: - if (!button_recived) + if (in_ev.code != BTN_STYLUS) break; - button_recived = 0; + out_ev = in_ev; + out_ev.code = BTN_TOOL_RUBBER; if (write(stylus, &out_ev, sizeof(struct input_event)) < 0) err(1, "write:"); break;