Massive refactor largely to support Unicode on Mac

This does a bunch of crazy stuff:

- The ability to set a unicode mode (right now only Linux+ibus or
MacOS-RALT) in the keymap. This will be changeable at runtime soon, to
allow a single keyboard to be able to send table flips and whatever
other crazy stuff on any OS the board is plugged into (something that's
not currently doable on QMK, so yay us?)

- As part of the above, there is now just one user-facing macro for
unicode codepoint submission,
`kmk.common.macros.unicode.unicode_sequence`. Users should never use the
platform-specific macros, partly because they just outright won't work.
There's all sorts of fun stuff in these methods now, thank goodness
MicroPython supports the `yield from` construct.

- Keycode (these should really be renamed Keysym or something) objects
that are intended to not be pressed, or not be released. Right now these
properties are completely ignored if not part of a macro, and it's
probably sane to keep it that way. This was necessary to support MacOS's
"hold RALT while typing the codepoint characters" flow.

- Other refactor-y bits, like moving macro support to `kmk/common`
rather than sitting at the top level of the tree. One day `kmk/common`
may make sense to surface at top level `kmk/`, but that's a discussion
for another day.
This commit is contained in:
Josh Klar
2018-09-30 19:33:23 -07:00
parent 2024eb959f
commit ffa81bcf43
11 changed files with 126 additions and 58 deletions

View File

@@ -1,14 +1,14 @@
import logging
import sys
from kmk.common.consts import DiodeOrientation
from kmk.common.consts import DiodeOrientation, UnicodeModes
from kmk.common.event_defs import (HID_REPORT_EVENT, INIT_FIRMWARE_EVENT,
KEY_DOWN_EVENT, KEY_UP_EVENT,
KEYCODE_DOWN_EVENT, KEYCODE_UP_EVENT,
MACRO_COMPLETE_EVENT, NEW_MATRIX_EVENT)
from kmk.common.internal_keycodes import process_internal_key_event
from kmk.common.keycodes import FIRST_KMK_INTERNAL_KEYCODE, Keycodes
from kmk.macros import KMKMacro
from kmk.common.macros import KMKMacro
class ReduxStore:
@@ -54,7 +54,8 @@ class ReduxStore:
class InternalState:
modifiers_pressed = frozenset()
keys_pressed = frozenset()
macros_pending = []
macro_pending = None
unicode_mode = UnicodeModes.NOOP
keymap = []
row_pins = []
col_pins = []
@@ -77,6 +78,7 @@ class InternalState:
'keys_pressed': self.keys_pressed,
'modifiers_pressed': self.modifiers_pressed,
'active_layers': self.active_layers,
'unicode_mode': self.unicode_mode,
}
if verbose:
@@ -164,7 +166,7 @@ def kmk_reducer(state=None, action=None, logger=None):
if isinstance(changed_key, KMKMacro):
if changed_key.keyup:
return state.update(
macros_pending=state.macros_pending + [changed_key.keyup],
macro_pending=changed_key.keyup,
)
return state
@@ -194,7 +196,7 @@ def kmk_reducer(state=None, action=None, logger=None):
if isinstance(changed_key, KMKMacro):
if changed_key.keydown:
return state.update(
macros_pending=state.macros_pending + [changed_key.keydown],
macro_pending=changed_key.keydown,
)
return state
@@ -216,6 +218,7 @@ def kmk_reducer(state=None, action=None, logger=None):
row_pins=action['row_pins'],
col_pins=action['col_pins'],
diode_orientation=action['diode_orientation'],
unicode_mode=action['unicode_mode'],
matrix=[
[False for c in action['col_pins']]
for r in action['row_pins']
@@ -230,12 +233,7 @@ def kmk_reducer(state=None, action=None, logger=None):
return state
if action['type'] == MACRO_COMPLETE_EVENT:
return state.update(
macros_pending=[
m for m in state.macros_pending
if m != action['macro']
],
)
return state.update(macro_pending=None)
# On unhandled events, log and do not mutate state
logger.warning('Unhandled event! Returning state unmodified.')