Initial attempt to merge internal_state with kmk_keyboard. Seems to work on Plank so far
fix formatting Example of new "Extension"/plugin system, using LED Cleanup of RGB code staticmethod to proper, normal methods Needs cleanup, but: migrate Leader to Extension API remove useless self reurns fix an AttributeError with Leader key removal Checkpoint from the weekend: split as an Extension (not working or done yet) wip
This commit is contained in:
@@ -5,7 +5,7 @@ def df_pressed(key, state, *args, **kwargs):
|
||||
'''
|
||||
Switches the default layer
|
||||
'''
|
||||
state.active_layers[-1] = key.meta.layer
|
||||
state._active_layers[-1] = key.meta.layer
|
||||
return state
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ def mo_pressed(key, state, *args, **kwargs):
|
||||
'''
|
||||
Momentarily activates layer, switches off when you let go
|
||||
'''
|
||||
state.active_layers.insert(0, key.meta.layer)
|
||||
state._active_layers.insert(0, key.meta.layer)
|
||||
return state
|
||||
|
||||
|
||||
@@ -27,8 +27,8 @@ def mo_released(key, state, KC, *args, **kwargs):
|
||||
# triggered by MO() and then defaulting to the MO()'s layer
|
||||
# would result in no layers active
|
||||
try:
|
||||
del_idx = state.active_layers.index(key.meta.layer)
|
||||
del state.active_layers[del_idx]
|
||||
del_idx = state._active_layers.index(key.meta.layer)
|
||||
del state._active_layers[del_idx]
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
@@ -39,10 +39,10 @@ def lm_pressed(key, state, *args, **kwargs):
|
||||
'''
|
||||
As MO(layer) but with mod active
|
||||
'''
|
||||
state.hid_pending = True
|
||||
state._hid_pending = True
|
||||
# Sets the timer start and acts like MO otherwise
|
||||
state.start_time['lm'] = ticks_ms()
|
||||
state.keys_pressed.add(key.meta.kc)
|
||||
state._start_time['lm'] = ticks_ms()
|
||||
state._keys_pressed.add(key.meta.kc)
|
||||
return mo_pressed(key, state, *args, **kwargs)
|
||||
|
||||
|
||||
@@ -50,28 +50,28 @@ def lm_released(key, state, *args, **kwargs):
|
||||
'''
|
||||
As MO(layer) but with mod active
|
||||
'''
|
||||
state.hid_pending = True
|
||||
state.keys_pressed.discard(key.meta.kc)
|
||||
state.start_time['lm'] = None
|
||||
state._hid_pending = True
|
||||
state._keys_pressed.discard(key.meta.kc)
|
||||
state._start_time['lm'] = None
|
||||
return mo_released(key, state, *args, **kwargs)
|
||||
|
||||
|
||||
def lt_pressed(key, state, *args, **kwargs):
|
||||
# Sets the timer start and acts like MO otherwise
|
||||
state.start_time['lt'] = ticks_ms()
|
||||
state._start_time['lt'] = ticks_ms()
|
||||
return mo_pressed(key, state, *args, **kwargs)
|
||||
|
||||
|
||||
def lt_released(key, state, *args, **kwargs):
|
||||
# On keyup, check timer, and press key if needed.
|
||||
if state.start_time['lt'] and (
|
||||
ticks_diff(ticks_ms(), state.start_time['lt']) < state.config.tap_time
|
||||
if state._start_time['lt'] and (
|
||||
ticks_diff(ticks_ms(), state._start_time['lt']) < state.tap_time
|
||||
):
|
||||
state.hid_pending = True
|
||||
state.tap_key(key.meta.kc)
|
||||
state._hid_pending = True
|
||||
state._tap_key(key.meta.kc)
|
||||
|
||||
mo_released(key, state, *args, **kwargs)
|
||||
state.start_time['lt'] = None
|
||||
state._start_time['lt'] = None
|
||||
return state
|
||||
|
||||
|
||||
@@ -81,10 +81,10 @@ def tg_pressed(key, state, *args, **kwargs):
|
||||
'''
|
||||
# See mo_released for implementation details around this
|
||||
try:
|
||||
del_idx = state.active_layers.index(key.meta.layer)
|
||||
del state.active_layers[del_idx]
|
||||
del_idx = state._active_layers.index(key.meta.layer)
|
||||
del state._active_layers[del_idx]
|
||||
except ValueError:
|
||||
state.active_layers.insert(0, key.meta.layer)
|
||||
state._active_layers.insert(0, key.meta.layer)
|
||||
|
||||
return state
|
||||
|
||||
@@ -93,8 +93,8 @@ def to_pressed(key, state, *args, **kwargs):
|
||||
'''
|
||||
Activates layer and deactivates all other layers
|
||||
'''
|
||||
state.active_layers.clear()
|
||||
state.active_layers.insert(0, key.meta.layer)
|
||||
state._active_layers.clear()
|
||||
state._active_layers.insert(0, key.meta.layer)
|
||||
|
||||
return state
|
||||
|
||||
@@ -104,23 +104,21 @@ def tt_pressed(key, state, *args, **kwargs):
|
||||
Momentarily activates layer if held, toggles it if tapped repeatedly
|
||||
'''
|
||||
# TODO Make this work with tap dance to function more correctly, but technically works.
|
||||
if state.start_time['tt'] is None:
|
||||
if state._start_time['tt'] is None:
|
||||
# Sets the timer start and acts like MO otherwise
|
||||
state.start_time['tt'] = ticks_ms()
|
||||
state._start_time['tt'] = ticks_ms()
|
||||
return mo_pressed(key, state, *args, **kwargs)
|
||||
elif ticks_diff(ticks_ms(), state.start_time['tt']) < state.config.tap_time:
|
||||
state.start_time['tt'] = None
|
||||
elif ticks_diff(ticks_ms(), state._start_time['tt']) < state.tap_time:
|
||||
state._start_time['tt'] = None
|
||||
return tg_pressed(key, state, *args, **kwargs)
|
||||
|
||||
|
||||
def tt_released(key, state, *args, **kwargs):
|
||||
tap_timed_out = (
|
||||
ticks_diff(ticks_ms(), state.start_time['tt']) >= state.config.tap_time
|
||||
)
|
||||
if state.start_time['tt'] is None or tap_timed_out:
|
||||
tap_timed_out = ticks_diff(ticks_ms(), state._start_time['tt']) >= state.tap_time
|
||||
if state._start_time['tt'] is None or tap_timed_out:
|
||||
# On first press, works like MO. On second press, does nothing unless let up within
|
||||
# time window, then acts like TG.
|
||||
state.start_time['tt'] = None
|
||||
state._start_time['tt'] = None
|
||||
return mo_released(key, state, *args, **kwargs)
|
||||
|
||||
return state
|
||||
|
Reference in New Issue
Block a user