fix stack exhaustion for certain hold-tap actions

This commit is contained in:
xs5871 2022-09-10 18:11:31 +00:00 committed by Kyle Brown
parent fdb07dd82b
commit f9203dbb85
3 changed files with 13 additions and 22 deletions

View File

@ -146,10 +146,7 @@ class HoldTap(Module):
elif state.activated == ActivationType.PRESSED:
# press and release tap because key released within tap time
self.ht_activate_tap(key, keyboard, *args, **kwargs)
keyboard.set_timeout(
False,
lambda: self.ht_deactivate_tap(key, keyboard, *args, **kwargs),
)
self.ht_deactivate_tap(key, keyboard, *args, **kwargs)
state.activated = ActivationType.RELEASED
self.send_key_buffer(keyboard)
del self.key_states[key]
@ -187,13 +184,20 @@ class HoldTap(Module):
keyboard.resume_process_key(self, key.meta.hold, True)
def ht_deactivate_hold(self, key, keyboard, *args, **kwargs):
keyboard.resume_process_key(self, key.meta.hold, False)
keyboard.set_timeout(
False, lambda: keyboard.resume_process_key(self, key.meta.hold, False)
)
def ht_activate_tap(self, key, keyboard, *args, **kwargs):
keyboard.resume_process_key(self, key.meta.tap, True)
def ht_deactivate_tap(self, key, keyboard, *args, **kwargs):
keyboard.resume_process_key(self, key.meta.tap, False)
def ht_deactivate_tap(self, key, keyboard, *args, delayed=True, **kwargs):
if delayed:
keyboard.set_timeout(
False, lambda: keyboard.resume_process_key(self, key.meta.tap, False)
)
else:
keyboard.resume_process_key(self, key.meta.tap, False)
def ht_activate_on_interrupt(self, key, keyboard, *args, **kwargs):
if key.meta.prefer_hold:
@ -205,4 +209,4 @@ class HoldTap(Module):
if key.meta.prefer_hold:
self.ht_deactivate_hold(key, keyboard, *args, **kwargs)
else:
self.ht_deactivate_tap(key, keyboard, *args, **kwargs)
self.ht_deactivate_tap(key, keyboard, *args, delayed=False, **kwargs)

View File

@ -1,4 +1,3 @@
import kmk.handlers.stock as handlers
from kmk.keys import make_argumented_key
from kmk.modules.holdtap import HoldTap, HoldTapKeyMeta
@ -32,15 +31,3 @@ class ModTap(HoldTap):
on_press=self.ht_pressed,
on_release=self.ht_released,
)
def ht_activate_hold(self, key, keyboard, *args, **kwargs):
handlers.default_pressed(key.meta.hold, keyboard, None)
def ht_deactivate_hold(self, key, keyboard, *args, **kwargs):
handlers.default_released(key.meta.hold, keyboard, None)
def ht_activate_tap(self, key, keyboard, *args, **kwargs):
handlers.default_pressed(key.meta.tap, keyboard, None)
def ht_deactivate_tap(self, key, keyboard, *args, **kwargs):
handlers.default_released(key.meta.tap, keyboard, None)

View File

@ -49,7 +49,7 @@ class TapDance(HoldTap):
keyboard.cancel_timeout(state.timeout_key)
self.ht_activate_tap(_key, keyboard)
keyboard._send_hid()
self.ht_deactivate_tap(_key, keyboard)
self.ht_deactivate_tap(_key, keyboard, delayed=False)
del self.key_states[_key]
del self.td_counts[state.tap_dance]