# Toshy keymap: Left Option types characters, like Right Option.
# ONLY for Mac keyboard layouts whose Option key types characters, such as
# Swiss (ch, de_mac) and German (de, mac). Not for the plain US layout.
#
# On these layouts Linux treats only Right Option as the AltGr / Level3 key, so
# Left Option+key arrives in apps as an Alt shortcut instead of a character
# (Swiss: @ on G, # on 3, [ on 5, | on 7; German: @ on L, ...). This sends
# Left Option (+Shift) as Right Option on every typing key.
#
# Only the plain chords are remapped: Ctrl+Opt (Magnet), Cmd+Opt, Opt+Tab and
# Opt+arrows are different combos and keep working. Trade-off: apps lose their
# Alt+letter shortcuts, and in terminals Alt+B/F (word jumps) type characters,
# as on a Mac.
#
# Paste between the user_apps slice marks in ~/.config/toshy/toshy_config.py,
# then `systemctl --user restart toshy-config.service`. Leave Toshy's own
# "Option-key special characters" setting disabled: it uses US characters.

_option_char_keys = [
    "GRAVE", "KEY_1", "KEY_2", "KEY_3", "KEY_4", "KEY_5", "KEY_6", "KEY_7",
    "KEY_8", "KEY_9", "KEY_0", "MINUS", "EQUAL",
    "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "LEFT_BRACE", "RIGHT_BRACE",
    "A", "S", "D", "F", "G", "H", "J", "K", "L", "SEMICOLON", "APOSTROPHE", "BACKSLASH",
    "KEY_102ND", "Z", "X", "C", "V", "B", "N", "M", "COMMA", "DOT", "SLASH",
]
_option_chars = {}
for _k in _option_char_keys:
    _option_chars[C("LAlt-" + _k)] = C("RAlt-" + _k)
    _option_chars[C("Shift-LAlt-" + _k)] = C("Shift-RAlt-" + _k)

keymap("User Left Option types characters", _option_chars, when = lambda ctx:
    cnfg.screen_has_focus and
    not ctx_app_is_remote
)
