Skip to content

Commit

Permalink
[rmkit] re-open devices when we detect an invalid file descriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
okay committed Jun 28, 2024
1 parent 3197799 commit 3e730fe
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions src/rmkit/input/input.cpy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -88,6 +90,8 @@ namespace input:
if !syn_dropped:
event.update(ev_data[i])

return 0

class Input:
private:

Expand All @@ -104,8 +108,11 @@ namespace input:
vector<SynKeyEvent> all_key_events

Input():
FD_ZERO(&rdfs)
open_devices()

void open_devices():
close_devices()
FD_ZERO(&rdfs)
// dev only
// used by remarkable
#ifdef REMARKABLE
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 3e730fe

Please sign in to comment.