From 3e730fe928c25fcdb038e3dabd5a06260348d4bf Mon Sep 17 00:00:00 2001 From: okay Date: Fri, 28 Jun 2024 14:14:56 -0700 Subject: [PATCH] [rmkit] re-open devices when we detect an invalid file descriptor --- src/rmkit/input/input.cpy | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/rmkit/input/input.cpy b/src/rmkit/input/input.cpy index a13c2bd..ce60c68 100644 --- a/src/rmkit/input/input.cpy +++ b/src/rmkit/input/input.cpy @@ -55,10 +55,12 @@ namespace input: - void handle_event_fd(): + int handle_event_fd(): int bytes = read(fd, ev_data, sizeof(input_event) * 64); + if bytes == -1: + debug "ERRNO", errno, strerror(errno) if bytes < sizeof(input_event) || bytes == -1: - return + return bytes #ifndef DEV // in DEV mode we allow event coalescing between calls to read() for @@ -88,6 +90,8 @@ namespace input: if !syn_dropped: event.update(ev_data[i]) + return 0 + class Input: private: @@ -104,8 +108,11 @@ namespace input: vector all_key_events Input(): - FD_ZERO(&rdfs) + open_devices() + void open_devices(): + close_devices() + FD_ZERO(&rdfs) // dev only // used by remarkable #ifdef REMARKABLE @@ -141,11 +148,16 @@ namespace input: self.has_stylus = supports_stylus() return + void close_devices(): + if self.touch.fd: + close(self.touch.fd) + if self.wacom.fd: + close(self.wacom.fd) + if self.button.fd: + close(self.button.fd) ~Input(): - close(self.touch.fd) - close(self.wacom.fd) - close(self.button.fd) + close_devices() void open_device(string fname): fd := open(fname.c_str(), O_RDWR) @@ -267,13 +279,17 @@ namespace input: else: retval = select(max_fd, &rdfs_cp, NULL, NULL, NULL) + if retval > 0: if FD_ISSET(self.wacom.fd, &rdfs_cp): - self.wacom.handle_event_fd() + if self.wacom.handle_event_fd() < 0: + self.open_devices() if FD_ISSET(self.touch.fd, &rdfs_cp): - self.touch.handle_event_fd() + if self.touch.handle_event_fd() < 0: + self.open_devices() if FD_ISSET(self.button.fd, &rdfs_cp): - self.button.handle_event_fd() + if self.button.handle_event_fd() < 0: + self.open_devices() if FD_ISSET(input::ipc_fd[0], &rdfs_cp): self.handle_ipc()