Holy refactor, Batman: full layer support (MO/DF)
Wow, what a trip this was. Layer support is now fully implemented. Other changes here mostly revolve around the event dispatching model: more floating state (hidden in clases wherever) has been purged, with the reducer (now mutable, comments inline) serving, as it should, as the sole source of truth. Thunk support has been added to our fake Redux clone, allowing Action Creators to handle sequences of events (which is arguably a cleaner way of handling matrix changes when not all matrix changes should result in a new HID report - in the case of internal keys). A whole class has been deprecated (Keymap) which only served as another arbitor of state: instead, the MatrixScanner has been made smarter and handles diffing internally, dispatching an Action when needed (and allowing the reducer to parse the keymap and figure out what key is pressed - this is the infinitely cleaner solution when layers come into play).
This commit is contained in:
@@ -4,53 +4,41 @@ from kmk.common.event_defs import KEY_DOWN_EVENT, KEY_UP_EVENT
|
||||
from kmk.common.keycodes import Keycodes
|
||||
|
||||
|
||||
def process(state, action, logger=None):
|
||||
if action['keycode'].code < 1000:
|
||||
return state
|
||||
|
||||
def process_internal_key_event(state, action, changed_key, logger=None):
|
||||
if logger is None:
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
logger.warning(action['keycode'])
|
||||
if action['keycode'] == Keycodes.KMK.KC_RESET:
|
||||
return reset(state, action, logger=logger)
|
||||
elif action['keycode'].code == Keycodes.Layers._KC_DF:
|
||||
return df(state, action, logger=logger)
|
||||
elif action['keycode'].code == Keycodes.Layers._KC_MO:
|
||||
return tilde(state, action, logger=logger)
|
||||
elif action['keycode'].code == Keycodes.Layers.KC_TILDE:
|
||||
if changed_key.code == Keycodes.Layers._KC_DF:
|
||||
return df(state, action, changed_key, logger=logger)
|
||||
elif changed_key.code == Keycodes.Layers._KC_MO:
|
||||
return mo(state, action, changed_key, logger=logger)
|
||||
elif changed_key.code == Keycodes.Layers.KC_TILDE:
|
||||
pass
|
||||
else:
|
||||
return state
|
||||
|
||||
|
||||
def tilde(state, action, logger):
|
||||
def tilde(state, action, changed_key, logger):
|
||||
# TODO Actually process keycodes
|
||||
return state
|
||||
|
||||
|
||||
def reset(state, action, logger):
|
||||
logger.debug('Rebooting to bootloader')
|
||||
import machine
|
||||
machine.bootloader()
|
||||
|
||||
|
||||
def df(state, action, logger):
|
||||
def df(state, action, changed_key, logger):
|
||||
"""Switches the default layer"""
|
||||
state.active_layers[0] = action['keycode'].layer
|
||||
state.active_layers[0] = changed_key.layer
|
||||
|
||||
return state
|
||||
|
||||
|
||||
def mo(state, action, logger):
|
||||
def mo(state, action, changed_key, logger):
|
||||
"""Momentarily activates layer, switches off when you let go"""
|
||||
if action['type'] == KEY_UP_EVENT:
|
||||
state.active_layers = [
|
||||
layer for layer in state.active_layers
|
||||
if layer != action['keycode'].layer
|
||||
if layer != changed_key.layer
|
||||
]
|
||||
elif action['type'] == KEY_DOWN_EVENT:
|
||||
state.active_layers.append(action['keycode'].layer)
|
||||
state.active_layers.append(changed_key.layer)
|
||||
|
||||
return state
|
||||
|
||||
|
Reference in New Issue
Block a user