Skip to content

Commit f693c97

Browse files
committed
Refactor keyboard capture
1 parent aefc425 commit f693c97

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

plover/oslayer/linux/keyboardcontrol_uinput.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,6 @@ class KeyboardCapture(Capture):
442442
def __init__(self):
443443
super().__init__()
444444
self._devices = self._get_devices()
445-
self._running = False
446445

447446
self._selector = selectors.DefaultSelector()
448447
self._device_thread = None
@@ -511,10 +510,9 @@ def start(self):
511510

512511
self._device_thread = threading.Thread(target=self._run)
513512
self._device_thread.start()
514-
515-
self._running = True
516513
except Exception:
517514
self._ungrab_devices()
515+
self._ui.close()
518516
raise
519517

520518
def cancel(self):
@@ -523,20 +521,18 @@ def cancel(self):
523521
or self._device_thread_write_pipe is None
524522
):
525523
# The only way for these pipes to be None is if pipe creation in start() failed
526-
# In that case, no other code after pipe creation would have run such as selectors.register or thread creation,
524+
# In that case, no other code after pipe creation would have run
527525
# and no cleanup is required
528526
return
529527
try:
530528
# Write some arbitrary data to the pipe to signal the _run thread to stop
531529
os.write(self._device_thread_write_pipe, b"a")
532-
533530
if self._device_thread is not None:
534531
self._device_thread.join()
535532
self._selector.close()
536533
except Exception:
537-
log.debug(exc_info=True)
534+
log.debug("error stopping KeyboardCapture", exc_info=True)
538535
finally:
539-
self._ungrab_devices()
540536
os.close(self._device_thread_read_pipe)
541537
os.close(self._device_thread_write_pipe)
542538

0 commit comments

Comments
 (0)