@@ -55,10 +55,12 @@ namespace input:
55
55
56
56
57
57
58
- void handle_event_fd():
58
+ int handle_event_fd():
59
59
int bytes = read (fd , ev_data, sizeof(input_event) * 64 );
60
+ if bytes == - 1:
61
+ debug " ERRNO" , errno, strerror(errno)
60
62
if bytes < sizeof(input_event) || bytes == - 1:
61
- return
63
+ return bytes
62
64
63
65
#ifndef DEV
64
66
// in DEV mode we allow event coalescing between calls to read() for
@@ -88,6 +90,8 @@ namespace input:
88
90
if !syn_dropped:
89
91
event .update (ev_data[i])
90
92
93
+ return 0
94
+
91
95
class Input :
92
96
private:
93
97
@@ -104,8 +108,11 @@ namespace input:
104
108
vector< SynKeyEvent> all_key_events
105
109
106
110
Input ():
107
- FD_ZERO(&rdfs )
111
+ open_devices( )
108
112
113
+ void open_devices():
114
+ close_devices()
115
+ FD_ZERO(&rdfs)
109
116
// dev only
110
117
// used by remarkable
111
118
#ifdef REMARKABLE
@@ -141,11 +148,16 @@ namespace input:
141
148
self .has_stylus = supports_stylus()
142
149
return
143
150
151
+ void close_devices():
152
+ if self .touch.fd :
153
+ close (self .touch.fd )
154
+ if self .wacom.fd :
155
+ close (self .wacom.fd )
156
+ if self .button.fd :
157
+ close (self .button.fd )
144
158
145
159
~Input ():
146
- close (self .touch.fd )
147
- close (self .wacom.fd )
148
- close (self .button.fd )
160
+ close_devices()
149
161
150
162
void open_device(string fname):
151
163
fd := open (fname.c_str(), O_RDWR)
@@ -267,13 +279,17 @@ namespace input:
267
279
else :
268
280
retval = select (max_fd, &rdfs_cp, NULL , NULL , NULL )
269
281
282
+
270
283
if retval > 0:
271
284
if FD_ISSET(self .wacom.fd , &rdfs_cp):
272
- self .wacom.handle_event_fd()
285
+ if self .wacom.handle_event_fd() < 0:
286
+ self .open_devices()
273
287
if FD_ISSET(self .touch.fd , &rdfs_cp):
274
- self .touch.handle_event_fd()
288
+ if self .touch.handle_event_fd() < 0:
289
+ self .open_devices()
275
290
if FD_ISSET(self .button.fd , &rdfs_cp):
276
- self .button.handle_event_fd()
291
+ if self .button.handle_event_fd() < 0:
292
+ self .open_devices()
277
293
if FD_ISSET(input ::ipc_fd [ 0 ], &rdfs_cp):
278
294
self .handle_ipc()
279
295
0 commit comments