Resolve issues with leader mode, allow single-key targets (HID or internal)

This commit is contained in:
Josh Klar 2018-12-29 16:52:06 -08:00
parent ea63c888d6
commit 0878538f42
No known key found for this signature in database
GPG Key ID: 220F99BD7DB7A99E
3 changed files with 18 additions and 2 deletions

View File

@ -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()))

View File

@ -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,
)

View File

@ -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