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.
2018-10-01 04:33:23 +02:00
|
|
|
from kmk.common.consts import UnicodeModes
|
|
|
|
from kmk.common.event_defs import (hid_report_event, keycode_down_event,
|
|
|
|
keycode_up_event)
|
2018-10-01 20:52:47 +02:00
|
|
|
from kmk.common.keycodes import Common, Macro, Modifiers
|
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.
2018-10-01 04:33:23 +02:00
|
|
|
from kmk.common.macros.simple import simple_key_sequence
|
|
|
|
|
|
|
|
IBUS_KEY_COMBO = Modifiers.KC_LCTRL(Modifiers.KC_LSHIFT(Common.KC_U))
|
|
|
|
|
|
|
|
|
|
|
|
def generate_codepoint_keysym_seq(codepoint):
|
2018-10-01 05:49:40 +02:00
|
|
|
# To make MacOS and Windows happy, always try to send
|
|
|
|
# sequences that are of length 4 at a minimum
|
|
|
|
# On Linux systems, we can happily send longer strings.
|
|
|
|
# They will almost certainly break on MacOS and Windows,
|
|
|
|
# but this is a documentation problem more than anything.
|
|
|
|
# Not sure how to send emojis on Mac/Windows like that,
|
|
|
|
# though, since (for example) the Canadian flag is assembled
|
|
|
|
# from two five-character codepoints, 1f1e8 and 1f1e6
|
|
|
|
seq = [Common.KC_0 for _ in range(max(len(codepoint), 4))]
|
|
|
|
|
|
|
|
for idx, codepoint_fragment in enumerate(reversed(codepoint)):
|
|
|
|
seq[-(idx + 1)] = getattr(Common, 'KC_{}'.format(codepoint_fragment.upper()))
|
|
|
|
|
|
|
|
return seq
|
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.
2018-10-01 04:33:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
def unicode_sequence(codepoints):
|
|
|
|
def _unicode_sequence(state):
|
|
|
|
if state.unicode_mode == UnicodeModes.IBUS:
|
|
|
|
yield from _ibus_unicode_sequence(codepoints, state)
|
|
|
|
elif state.unicode_mode == UnicodeModes.RALT:
|
|
|
|
yield from _ralt_unicode_sequence(codepoints, state)
|
2018-10-01 05:35:41 +02:00
|
|
|
elif state.unicode_mode == UnicodeModes.WINC:
|
|
|
|
yield from _winc_unicode_sequence(codepoints, state)
|
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.
2018-10-01 04:33:23 +02:00
|
|
|
|
2018-10-01 20:52:47 +02:00
|
|
|
return Macro(keydown=_unicode_sequence)
|
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.
2018-10-01 04:33:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
def _ralt_unicode_sequence(codepoints, state):
|
|
|
|
for codepoint in codepoints:
|
|
|
|
yield keycode_down_event(Modifiers.RALT(no_release=True))
|
|
|
|
yield from simple_key_sequence(generate_codepoint_keysym_seq(codepoint)).keydown(state)
|
|
|
|
yield keycode_up_event(Modifiers.RALT(no_press=True))
|
|
|
|
|
|
|
|
|
|
|
|
def _ibus_unicode_sequence(codepoints, state):
|
|
|
|
for codepoint in codepoints:
|
|
|
|
yield keycode_down_event(IBUS_KEY_COMBO)
|
|
|
|
yield hid_report_event()
|
|
|
|
yield keycode_up_event(IBUS_KEY_COMBO)
|
|
|
|
yield hid_report_event()
|
|
|
|
|
|
|
|
seq = generate_codepoint_keysym_seq(codepoint)
|
|
|
|
seq.append(Common.KC_ENTER)
|
|
|
|
|
|
|
|
yield from simple_key_sequence(seq).keydown(state)
|
2018-10-01 05:35:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
def _winc_unicode_sequence(codepoints, state):
|
|
|
|
'''
|
|
|
|
Send unicode sequence using WinCompose:
|
|
|
|
|
|
|
|
http://wincompose.info/
|
|
|
|
https://github.com/SamHocevar/wincompose
|
|
|
|
'''
|
|
|
|
for codepoint in codepoints:
|
|
|
|
yield keycode_down_event(Modifiers.RALT())
|
|
|
|
yield keycode_down_event(Common.KC_U())
|
|
|
|
yield from simple_key_sequence(generate_codepoint_keysym_seq(codepoint)).keydown(state)
|