From 8a21b4135defdd93d3ae9df47b4c6ac3668af1b3 Mon Sep 17 00:00:00 2001 From: Josh Klar Date: Sat, 29 Dec 2018 06:58:08 -0800 Subject: [PATCH] Restore Unicode Macro support --- kmk/firmware.py | 9 ++ kmk/handlers/sequences.py | 2 - kmk/keycodes.py | 15 ---- kmk/macros/unicode.py | 51 +++++++----- user_keymaps/klardotsh/klarank_featherm4.py | 92 ++++++++++----------- 5 files changed, 87 insertions(+), 82 deletions(-) diff --git a/kmk/firmware.py b/kmk/firmware.py index a98f23c..2e2714b 100644 --- a/kmk/firmware.py +++ b/kmk/firmware.py @@ -46,6 +46,7 @@ import supervisor from kmk.consts import LeaderMode, UnicodeMode from kmk.hid import USB_HID from kmk.internal_state import InternalState +from kmk.keycodes import KC from kmk.matrix import MatrixScanner @@ -175,6 +176,14 @@ class Firmware: self._hid_helper_inst = self.hid_helper() + # Compile string leader sequences + for k, v in self.leader_dictionary.items(): + if not isinstance(k, tuple): + new_key = tuple(KC[c] for c in k) + self.leader_dictionary[new_key] = v + + del self.leader_dictionary[k] + if self.debug_enabled: print("Firin' lazers. Keyboard is booted.") diff --git a/kmk/handlers/sequences.py b/kmk/handlers/sequences.py index d015196..2eaa371 100644 --- a/kmk/handlers/sequences.py +++ b/kmk/handlers/sequences.py @@ -1,5 +1,4 @@ from kmk.keycodes import KC, make_key -from kmk.handlers.stock import passthrough from kmk.types import KeySequenceMeta @@ -24,7 +23,6 @@ def simple_key_sequence(seq): return make_key( meta=KeySequenceMeta(seq), on_press=sequence_press_handler, - on_release=passthrough, ) diff --git a/kmk/keycodes.py b/kmk/keycodes.py index 3866a55..cda002b 100644 --- a/kmk/keycodes.py +++ b/kmk/keycodes.py @@ -18,18 +18,6 @@ KEYCODE_CONSUMER = 2 KC = AttrDict() -def generate_leader_dictionary_seq(string): - # FIXME move to kmk.macros.unicode or somewhere else more fitting - # left here for backwards compat with various keymaps that - # import this - # - # I have absolutely no idea why it was in this file to begin with, - # probably something related to import order at one point. - from kmk.macros.unicode import generate_codepoint_keysym_seq - - return tuple(generate_codepoint_keysym_seq(string, 1)) - - class Keycode: def __init__( self, @@ -530,7 +518,6 @@ make_argumented_key( validator=layer_key_validator, names=('DF',), on_press=layers.df_pressed, - on_release=handlers.passthrough, ) make_argumented_key( validator=layer_key_validator, @@ -548,13 +535,11 @@ make_argumented_key( validator=layer_key_validator, names=('TG',), on_press=layers.tg_pressed, - on_release=handlers.passthrough, ) make_argumented_key( validator=layer_key_validator, names=('TO',), on_press=layers.to_pressed, - on_release=handlers.passthrough, ) make_argumented_key( validator=layer_key_validator, diff --git a/kmk/macros/unicode.py b/kmk/macros/unicode.py index a670e32..1eac257 100644 --- a/kmk/macros/unicode.py +++ b/kmk/macros/unicode.py @@ -1,15 +1,15 @@ from kmk.consts import UnicodeMode -from kmk.keycodes import KC, Macro -from kmk.macros.simple import simple_key_sequence +from kmk.handlers.sequences import simple_key_sequence +from kmk.keycodes import KC, make_key from kmk.types import AttrDict from kmk.util import get_wide_ordinal -IBUS_KEY_COMBO = KC.LCTRL(KC.LSHIFT(KC.U)) -RALT_KEY = KC.RALT -U_KEY = KC.U -ENTER_KEY = KC.ENTER -RALT_DOWN_NO_RELEASE = KC.RALT(no_release=True) -RALT_UP_NO_PRESS = KC.RALT(no_press=True) +IBUS_KEY_COMBO = simple_key_sequence((KC.LCTRL(KC.LSHIFT(KC.U)),)) +RALT_KEY = simple_key_sequence((KC.RALT,)) +U_KEY = simple_key_sequence((KC.U,)) +ENTER_KEY = simple_key_sequence((KC.ENTER,)) +RALT_DOWN_NO_RELEASE = simple_key_sequence((KC.RALT(no_release=True),)) +RALT_UP_NO_PRESS = simple_key_sequence((KC.RALT(no_press=True),)) def compile_unicode_string_sequences(string_table): @@ -50,6 +50,10 @@ def generate_codepoint_keysym_seq(codepoint, expected_length=4): return seq +def generate_leader_dictionary_seq(string): + return tuple(generate_codepoint_keysym_seq(string, 1)) + + def unicode_codepoint_sequence(codepoints): kc_seqs = ( generate_codepoint_keysym_seq(codepoint) @@ -61,28 +65,37 @@ def unicode_codepoint_sequence(codepoints): for kc_seq in kc_seqs ] - def _unicode_sequence(state): - if state.unicode_mode == UnicodeMode.IBUS: - yield from _ibus_unicode_sequence(kc_macros, state) - elif state.unicode_mode == UnicodeMode.RALT: - yield from _ralt_unicode_sequence(kc_macros, state) - elif state.unicode_mode == UnicodeMode.WINC: - yield from _winc_unicode_sequence(kc_macros, state) + def _unicode_sequence(key, state, *args, **kwargs): + if state.config.unicode_mode == UnicodeMode.IBUS: + state.process_key( + simple_key_sequence(_ibus_unicode_sequence(kc_macros, state)), + True, + ) + elif state.config.unicode_mode == UnicodeMode.RALT: + state.process_key( + simple_key_sequence(_ralt_unicode_sequence(kc_macros, state)), + True, + ) + elif state.config.unicode_mode == UnicodeMode.WINC: + state.process_key( + simple_key_sequence(_winc_unicode_sequence(kc_macros, state)), + True, + ) - return Macro(keydown=_unicode_sequence) + return make_key(on_press=_unicode_sequence) def _ralt_unicode_sequence(kc_macros, state): for kc_macro in kc_macros: yield RALT_DOWN_NO_RELEASE - yield from kc_macro.keydown(state) + yield kc_macro yield RALT_UP_NO_PRESS def _ibus_unicode_sequence(kc_macros, state): for kc_macro in kc_macros: yield IBUS_KEY_COMBO - yield from kc_macro.keydown(state) + yield kc_macro yield ENTER_KEY @@ -96,4 +109,4 @@ def _winc_unicode_sequence(kc_macros, state): for kc_macro in kc_macros: yield RALT_KEY yield U_KEY - yield from kc_macro.keydown(state) + yield kc_macro diff --git a/user_keymaps/klardotsh/klarank_featherm4.py b/user_keymaps/klardotsh/klarank_featherm4.py index 8aceb70..5393759 100644 --- a/user_keymaps/klardotsh/klarank_featherm4.py +++ b/user_keymaps/klardotsh/klarank_featherm4.py @@ -1,10 +1,8 @@ from kmk.boards.klarank import Firmware from kmk.consts import LeaderMode, UnicodeMode +from kmk.handlers.sequences import send_string from kmk.keycodes import KC - -# from kmk.keycodes import generate_leader_dictionary_seq as glds -# from kmk.macros.simple import send_string -# from kmk.macros.unicode import compile_unicode_string_sequences as cuss +from kmk.macros.unicode import compile_unicode_string_sequences as cuss keyboard = Firmware() @@ -12,55 +10,57 @@ keyboard.debug_enabled = True keyboard.unicode_mode = UnicodeMode.LINUX keyboard.tap_time = 750 -# emoticons = cuss({ -# # Emojis -# 'BEER': r'🍺', -# 'BEER_TOAST': r'🍻', -# 'FACE_CUTE_SMILE': r'😊', -# 'FACE_HEART_EYES': r'😍', -# 'FACE_JOY': r'πŸ˜‚', -# 'FACE_SWEAT_SMILE': r'πŸ˜…', -# 'FACE_THINKING': r'πŸ€”', -# 'FIRE': r'πŸ”₯', -# 'FLAG_CA': r'πŸ‡¨πŸ‡¦', -# 'FLAG_US': r'πŸ‡ΊπŸ‡Έ', -# 'HAND_CLAP': r'πŸ‘', -# 'HAND_HORNS': r'🀘', -# 'HAND_OK': r'πŸ‘Œ', -# 'HAND_THUMB_DOWN': r'πŸ‘Ž', -# 'HAND_THUMB_UP': r'πŸ‘', -# 'HAND_WAVE': r'πŸ‘‹', -# 'HEART': r'❀️', -# 'MAPLE_LEAF': r'🍁', -# 'POOP': r'πŸ’©', -# 'TADA': r'πŸŽ‰', -# -# # Emoticons, but fancier -# 'ANGRY_TABLE_FLIP': r'(γƒŽΰ² η—Šΰ² )γƒŽε½‘β”»β”β”»', -# 'CELEBRATORY_GLITTER': r'+q:.οΎŸγƒ½(Β΄βˆ€ο½‘)οΎ‰οΎŸ.:q+゚゚+q:.οΎŸγƒ½(*Β΄βˆ€)οΎ‰οΎŸ.:q+゚', -# 'SHRUGGIE': r'Β―\_(ツ)_/Β―', -# 'TABLE_FLIP': r'(β•―Β°β–‘Β°οΌ‰β•―οΈ΅ ┻━┻', -# }) +emoticons = cuss({ + # Emojis + 'BEER': r'🍺', + 'BEER_TOAST': r'🍻', + 'FACE_CUTE_SMILE': r'😊', + 'FACE_HEART_EYES': r'😍', + 'FACE_JOY': r'πŸ˜‚', + 'FACE_SWEAT_SMILE': r'πŸ˜…', + 'FACE_THINKING': r'πŸ€”', + 'FIRE': r'πŸ”₯', + 'FLAG_CA': r'πŸ‡¨πŸ‡¦', + 'FLAG_US': r'πŸ‡ΊπŸ‡Έ', + 'HAND_CLAP': r'πŸ‘', + 'HAND_HORNS': r'🀘', + 'HAND_OK': r'πŸ‘Œ', + 'HAND_THUMB_DOWN': r'πŸ‘Ž', + 'HAND_THUMB_UP': r'πŸ‘', + 'HAND_WAVE': r'πŸ‘‹', + 'HEART': r'❀️', + 'MAPLE_LEAF': r'🍁', + 'POOP': r'πŸ’©', + 'TADA': r'πŸŽ‰', -# WPM = send_string("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Bibendum arcu vitae elementum curabitur vitae nunc sed. Facilisis sed odio morbi quis.") -# -# keyboard.leader_mode = LeaderMode.TIMEOUT -# keyboard.leader_dictionary = { -# glds('hello'): send_string('hello world from kmk macros'), -# glds('wpm'): WPM, -# glds('atf'): emoticons.ANGRY_TABLE_FLIP, -# glds('tf'): emoticons.TABLE_FLIP, -# glds('fca'): emoticons.FLAG_CA, -# glds('fus'): emoticons.FLAG_US, -# glds('cel'): emoticons.CELEBRATORY_GLITTER, -# } + # Emoticons, but fancier + 'ANGRY_TABLE_FLIP': r'(γƒŽΰ² η—Šΰ² )γƒŽε½‘β”»β”β”»', + 'CELEBRATORY_GLITTER': r'+q:.οΎŸγƒ½(Β΄βˆ€ο½‘)οΎ‰οΎŸ.:q+゚゚+q:.οΎŸγƒ½(*Β΄βˆ€)οΎ‰οΎŸ.:q+゚', + 'SHRUGGIE': r'Β―\_(ツ)_/Β―', + 'TABLE_FLIP': r'(β•―Β°β–‘Β°οΌ‰β•―οΈ΅ ┻━┻', +}) + +WPM = send_string("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Bibendum arcu vitae elementum curabitur vitae nunc sed. Facilisis sed odio morbi quis.") + +keyboard.leader_mode = LeaderMode.TIMEOUT +keyboard.leader_dictionary = { + 'hello': send_string('hello world from kmk macros'), + 'wpm': WPM, + 'atf': emoticons.ANGRY_TABLE_FLIP, + 'tf': emoticons.TABLE_FLIP, + 'fca': emoticons.FLAG_CA, + 'fus': emoticons.FLAG_US, + 'cel': emoticons.CELEBRATORY_GLITTER, + 'shr': emoticons.SHRUGGIE, + 'poop': emoticons.POOP, +} _______ = KC.TRNS xxxxxxx = KC.NO HELLA_TD = KC.TD( KC.A, KC.B, - # send_string('macros in a tap dance? I think yes'), + send_string('macros in a tap dance? I think yes'), KC.TG(1), )