From 0878538f428cdfcc4f7ed362402e9e61049a7d66 Mon Sep 17 00:00:00 2001 From: Josh Klar Date: Sat, 29 Dec 2018 16:52:06 -0800 Subject: [PATCH] Resolve issues with leader mode, allow single-key targets (HID or internal) --- kmk/firmware.py | 7 ++++++- kmk/handlers/sequences.py | 2 ++ kmk/internal_state.py | 11 ++++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/kmk/firmware.py b/kmk/firmware.py index e916de9..1bfcb54 100644 --- a/kmk/firmware.py +++ b/kmk/firmware.py @@ -182,7 +182,9 @@ class Firmware: new_key = tuple(KC[c] for c in k) self.leader_dictionary[new_key] = v - del self.leader_dictionary[k] + for k, v in self.leader_dictionary.items(): + if not isinstance(k, tuple): + del self.leader_dictionary[k] if self.debug_enabled: print("Firin' lazers. Keyboard is booted.") @@ -216,6 +218,9 @@ class Firmware: if old_timeouts_len != new_timeouts_len: state_changed = True + if self._state.hid_pending: + self._send_hid() + if self.debug_enabled and state_changed: print('New State: {}'.format(self._state._to_dict())) diff --git a/kmk/handlers/sequences.py b/kmk/handlers/sequences.py index bbb57ad..8f11cbf 100644 --- a/kmk/handlers/sequences.py +++ b/kmk/handlers/sequences.py @@ -1,4 +1,5 @@ from kmk.consts import UnicodeMode +from kmk.handlers.stock import passthrough from kmk.keys import KC, make_key from kmk.types import AttrDict, KeySequenceMeta from kmk.util import get_wide_ordinal @@ -25,6 +26,7 @@ def simple_key_sequence(seq): return make_key( meta=KeySequenceMeta(seq), on_press=sequence_press_handler, + on_release=passthrough, ) diff --git a/kmk/internal_state.py b/kmk/internal_state.py index f264b06..cc692eb 100644 --- a/kmk/internal_state.py +++ b/kmk/internal_state.py @@ -219,11 +219,20 @@ class InternalState: def _handle_leader_sequence(self): lmh = tuple(self.leader_mode_history) + # Will get caught in infinite processing loops if we don't + # exit leader mode before processing the target key + self._exit_leader_mode() if lmh in self.config.leader_dictionary: + # Stack depth exceeded if try to use add_key here with a unicode sequence self.process_key(self.config.leader_dictionary[lmh], True) - return self._exit_leader_mode() + self.set_timeout( + False, + lambda: self.remove_key(self.config.leader_dictionary[lmh]), + ) + + return self def _process_leader_mode(self): keys_pressed = self.keys_pressed