# Toshy keymaps for Omarchy (Hyprland) with macOS muscle memory.
# Works with any keyboard layout.
#
# Paste between the user_apps slice marks in ~/.config/toshy/toshy_config.py:
#   ###  SLICE_MARK_START: user_apps  ###
#   ...here...
#   ###  SLICE_MARK_END: user_apps  ###
# Code outside the marks is lost when Toshy updates. Then run
# `systemctl --user restart toshy-config.service`.
#
# With Toshy on an Apple keyboard, physical Cmd reaches apps as Ctrl (written
# "RC", the virtual Cmd) and physical Ctrl reaches Hyprland as Super, except in
# terminals, where it stays Ctrl ("LC"). The terminal keymap below forwards the
# window-manager chords to Super explicitly.

keymap("User Omarchy globals", {
    C("RC-Space"):              [iEF2NT(), C("Super-Space")],   # Cmd+Space (Spotlight) -> Omarchy launcher
    C("RC-Shift-Key_3"):        C("Print"),                     # Screenshot
    C("RC-Shift-Key_4"):        C("Print"),                     # Screenshot (region)
    C("RC-Shift-Key_5"):        C("Super-C-c"),                 # Capture menu
    C("RC-H"):                  C("Super-m"),                   # Hide -> minimize to dock
    C("RC-M"):                  C("Super-m"),                   # Minimize to dock
    C("RC-Tab"):               [bind, C("Super-C-Alt-Tab")],    # Cmd+Tab: MRU workspace switcher
    C("RC-Shift-Tab"):         [bind, C("Super-C-Alt-Shift-Tab")],  # (workspace-switcher.lua)
    C("Super-RC-Space"):        C("Super-C-e"),                 # Ctrl+Cmd+Space -> emoji picker
    C("LC-RC-Space"):           C("Super-C-e"),                 # (same, in terminals)
}, when = lambda ctx:
    cnfg.screen_has_focus and
    DESKTOP_ENV == 'hyprland' and
    not ctx_app_is_remote
)

_omarchy_terms = {
    C("LC-RC-Q"):               C("Super-C-q"),                 # Cmd+Ctrl+Q lock
    C("LC-RC-F"):               C("Super-C-f"),                 # Cmd+Ctrl+F fullscreen
    C("LC-Space"):              C("Super-Space"),               # Ctrl+Space as in GUI apps
}
# Magnet: Ctrl+Opt (+Cmd) chords (magnet.lua)
for _k in ["Left", "Right", "Up", "Down", "Enter", "Backspace",
           "C", "U", "I", "J", "K", "D", "F", "G", "E", "T"]:
    _omarchy_terms[C("LC-Alt-" + _k)] = C("Super-Alt-" + _k)
for _k in ["Left", "Right"]:
    _omarchy_terms[C("LC-RC-Alt-" + _k)] = C("Super-C-Alt-" + _k)
# Ctrl+1..0 workspaces (like macOS "Switch to Desktop N"), Shift to move window
for _n in ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]:
    _omarchy_terms[C("LC-Key_" + _n)] = C("Super-Key_" + _n)
    _omarchy_terms[C("LC-Shift-Key_" + _n)] = C("Super-Shift-Key_" + _n)

keymap("User Omarchy WM chords in terminals", _omarchy_terms, when = lambda ctx:
    cnfg.screen_has_focus and
    DESKTOP_ENV == 'hyprland' and
    ctx_app_is_terminal
)


# Zed: Cmd+C/V and physical Ctrl+C both arrived as Ctrl+C, so Cmd+C in the
# integrated terminal sent SIGINT. Route Cmd+C/V to Ctrl+Insert / Shift+Insert
# (copy/paste in both editor and terminal, see ~/.config/zed/keymap.json); physical
# Ctrl+C (-> Super+C -> Hyprland universal copy -> Ctrl+C) stays SIGINT, as on macOS.
hmp_is_zed                      = matchProps(clas="^dev\\.zed\\.Zed(-Preview)?$")
keymap("User Zed", {
    C("RC-C"):                  C("C-Insert"),                  # Copy (not SIGINT in terminal)
    C("RC-V"):                  C("Shift-Insert"),              # Paste
}, when = lambda ctx:
    cnfg.screen_has_focus and
    hmp_is_zed(ctx)
)
