2018-10-12 03:02:13 +02:00
|
|
|
|
from kmk.consts import UnicodeModes
|
2018-10-17 07:43:47 +02:00
|
|
|
|
from kmk.keycodes import (Common, Macro, Modifiers,
|
|
|
|
|
generate_codepoint_keysym_seq)
|
|
|
|
|
from kmk.macros.simple import simple_key_sequence
|
2018-10-16 13:04:39 +02:00
|
|
|
|
from kmk.types import AttrDict
|
2018-10-12 03:02:13 +02:00
|
|
|
|
from kmk.util import get_wide_ordinal
|
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
|
|
|
|
|
|
|
|
|
IBUS_KEY_COMBO = Modifiers.KC_LCTRL(Modifiers.KC_LSHIFT(Common.KC_U))
|
2018-10-16 13:04:39 +02:00
|
|
|
|
RALT_KEY = Modifiers.KC_RALT
|
|
|
|
|
U_KEY = Common.KC_U
|
|
|
|
|
ENTER_KEY = Common.KC_ENTER
|
|
|
|
|
RALT_DOWN_NO_RELEASE = Modifiers.KC_RALT(no_release=True)
|
|
|
|
|
RALT_UP_NO_PRESS = Modifiers.KC_RALT(no_press=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def compile_unicode_string_sequences(string_table):
|
|
|
|
|
for k, v in string_table.items():
|
|
|
|
|
string_table[k] = unicode_string_sequence(v)
|
|
|
|
|
|
|
|
|
|
return AttrDict(string_table)
|
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-08 12:50:55 +02:00
|
|
|
|
def unicode_string_sequence(unistring):
|
|
|
|
|
'''
|
|
|
|
|
Allows sending things like (╯°□°)╯︵ ┻━┻ directly, without
|
|
|
|
|
manual conversion to Unicode codepoints.
|
|
|
|
|
'''
|
2018-10-08 12:59:16 +02:00
|
|
|
|
return unicode_codepoint_sequence([
|
2018-10-08 12:50:55 +02:00
|
|
|
|
hex(get_wide_ordinal(s))[2:]
|
|
|
|
|
for s in unistring
|
2018-10-08 12:59:16 +02:00
|
|
|
|
])
|
2018-10-08 12:50:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def unicode_codepoint_sequence(codepoints):
|
2018-10-08 14:04:06 +02:00
|
|
|
|
kc_seqs = (
|
|
|
|
|
generate_codepoint_keysym_seq(codepoint)
|
|
|
|
|
for codepoint in codepoints
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
kc_macros = [
|
|
|
|
|
simple_key_sequence(kc_seq)
|
|
|
|
|
for kc_seq in kc_seqs
|
|
|
|
|
]
|
|
|
|
|
|
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(state):
|
|
|
|
|
if state.unicode_mode == UnicodeModes.IBUS:
|
2018-10-08 14:04:06 +02:00
|
|
|
|
yield from _ibus_unicode_sequence(kc_macros, 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
|
|
|
|
elif state.unicode_mode == UnicodeModes.RALT:
|
2018-10-08 14:04:06 +02:00
|
|
|
|
yield from _ralt_unicode_sequence(kc_macros, state)
|
2018-10-01 05:35:41 +02:00
|
|
|
|
elif state.unicode_mode == UnicodeModes.WINC:
|
2018-10-08 14:04:06 +02:00
|
|
|
|
yield from _winc_unicode_sequence(kc_macros, 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
|
|
|
|
|
|
|
|
|
|
2018-10-08 14:04:06 +02:00
|
|
|
|
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 RALT_UP_NO_PRESS
|
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-08 14:04:06 +02:00
|
|
|
|
def _ibus_unicode_sequence(kc_macros, state):
|
|
|
|
|
for kc_macro in kc_macros:
|
2018-10-16 13:04:39 +02:00
|
|
|
|
yield IBUS_KEY_COMBO
|
2018-10-08 14:04:06 +02:00
|
|
|
|
yield from kc_macro.keydown(state)
|
2018-10-16 13:04:39 +02:00
|
|
|
|
yield ENTER_KEY
|
2018-10-01 05:35:41 +02:00
|
|
|
|
|
|
|
|
|
|
2018-10-08 14:04:06 +02:00
|
|
|
|
def _winc_unicode_sequence(kc_macros, state):
|
2018-10-01 05:35:41 +02:00
|
|
|
|
'''
|
|
|
|
|
Send unicode sequence using WinCompose:
|
|
|
|
|
|
|
|
|
|
http://wincompose.info/
|
|
|
|
|
https://github.com/SamHocevar/wincompose
|
|
|
|
|
'''
|
2018-10-08 14:04:06 +02:00
|
|
|
|
for kc_macro in kc_macros:
|
2018-10-16 13:04:39 +02:00
|
|
|
|
yield RALT_KEY
|
|
|
|
|
yield U_KEY
|
2018-10-08 14:04:06 +02:00
|
|
|
|
yield from kc_macro.keydown(state)
|