@@ -22,10 +22,14 @@ namespace input:
22
22
extern int ipc_fd[ 2 ] = { -1 , -1 };
23
23
extern bool CRASH_ON_BAD_DEVICE = (getenv(" RMKIT_CRASH_ON_BAD_DEVICE" ) != NULL )
24
24
25
+ class IInputClass:
26
+ public:
27
+ int fd = 0
28
+ bool reopen = false
29
+
25
30
template< class T, class EV>
26
- class InputClass:
31
+ class InputClass : public IInputClass :
27
32
public:
28
- int fd
29
33
input_event ev_data[ 64 ]
30
34
T prev_ev, event
31
35
vector< T> events
@@ -60,6 +64,8 @@ namespace input:
60
64
if bytes == - 1:
61
65
debug " ERRNO" , errno, strerror(errno)
62
66
if bytes < sizeof(input_event) || bytes == - 1:
67
+ if errno == ENODEV:
68
+ self .reopen = true
63
69
return bytes
64
70
65
71
#ifndef DEV
@@ -149,12 +155,10 @@ namespace input:
149
155
return
150
156
151
157
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 )
158
+ vector< IInputClass> fds = { self .touch, self .wacom, self .button}
159
+ for auto in : fds:
160
+ if in .fd > 0:
161
+ close (in .fd )
158
162
159
163
~Input ():
160
164
close_devices()
@@ -261,6 +265,19 @@ namespace input:
261
265
for auto fd : { self .touch.fd , self .wacom.fd , self .button.fd }:
262
266
ioctl(fd , EVIOCGRAB, false )
263
267
268
+ void check_reopen():
269
+ vector< IInputClass*> inputs = { &self.wacom, &self.touch, &self.button }
270
+ needs_reopen := false
271
+ for auto in : inputs:
272
+ if in-> reopen:
273
+ needs_reopen = true
274
+ break
275
+
276
+ if needs_reopen:
277
+ self .open_devices()
278
+
279
+ for auto in : inputs:
280
+ in-> reopen = false
264
281
265
282
void listen_all(long timeout_ms = 0 ):
266
283
fd_set rdfs_cp
@@ -284,17 +301,16 @@ namespace input:
284
301
// and we only re-open the specific device that fail
285
302
if retval > 0:
286
303
if FD_ISSET(self .wacom.fd , &rdfs_cp):
287
- if self .wacom.handle_event_fd() < 0 and errno == ENODEV:
288
- self .open_devices()
304
+ self .wacom.handle_event_fd()
289
305
if FD_ISSET(self .touch.fd , &rdfs_cp):
290
- if self .touch.handle_event_fd() < 0 and errno == ENODEV:
291
- self .open_devices()
306
+ self .touch.handle_event_fd()
292
307
if FD_ISSET(self .button.fd , &rdfs_cp):
293
- if self .button.handle_event_fd() < 0 and errno == ENODEV:
294
- self .open_devices()
308
+ self .button.handle_event_fd()
295
309
if FD_ISSET(input ::ipc_fd [ 0 ], &rdfs_cp):
296
310
self .handle_ipc()
297
311
312
+ self .check_reopen()
313
+
298
314
for auto ev : self .wacom.events:
299
315
self .all_motion_events.push_back(self .wacom.marshal(ev))
300
316
0 commit comments