Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add key forwarding #254

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jackielii
Copy link

@jackielii jackielii commented Mar 25, 2023

try to fix #209, fix #204, fix #227.

Pardon the naming, I can't think of a better one, same goes for the | token.

This works by sending the synthetic event with a user data 0x12345 (feel free to suggest a different one) and If we see the key press with this user data, we ignore it, hence achieve forwarding (hence the naming as we're just forwarding one key press to another).

Update:: This now works my modifying the original event and return it directly. This won't trigger another event loop thus preventing skhd from capturing the key press again.

Update: also merged the service updates from upstream into jackielii/tap/skhd. You can install and start via:

brew install jackielii/tap/skhd
skhd --start-service

Just in case this is not merged, you can try this by compiling locally:

make && ./bin/skhd  -V -P

Or install using my tap:

brew install jackielii/tap/skhd
brew services start jackielii/tap/skhd

Config can be simply:

cmd - 1 : yabai -m space --focus 1
ctrl - 1 | cmd - 1

You should see in the log:

skhd: using config '/Users/jackieli/.config/skhd/skhdrc'
hotkey :: #446 {
        mod: 'cmd'
        key: '1' (0x12)
        cmd: 'yabai -m space --focus 1'
}
hotkey :: #447 {
        mod: 'ctrl'
        key: '1' (0x12)
  forward key stroke: {
        mod: 'cmd'
        key: '1' (0x12)
  }
}
skhd: watching files for changes:
        /Users/jackieli/.config/skhd/skhdrc
0.3050ms (parse_config)
3.4878ms (begin_eventtap)
22.3339ms (total_time)
0.0038ms (handle_keypress)
2.9850ms (handle_keypress)
skhd: ignoring synthetic event

The alternative presented in #204 has data races :

# 1. define default & capture mode
:: default
:: tabmode

# 2. define an impossible key to switch to capture mode
hyper - 0x80 ; tabmode
tabmode < hyper - 0x80 ; default

# 3. define ctrl + number to send mode switch key, send cmd + number, switch back
ctrl - 1 : skhd -k "hyper - 0x80" ; skhd -k "cmd - 1" ; skhd -k "hyper - 0x80"
ctrl - 2 : skhd -k "hyper - 0x80" ; skhd -k "cmd - 2" ; skhd -k "hyper - 0x80"

When you press ctrl - 1 & ctrl - 2 too quickly, you may end up in the tabmode.

This PR solves this problem.

@jackielii jackielii force-pushed the key-forwarding branch 2 times, most recently from 6e3c717 to b88674b Compare March 27, 2023 22:58
@jackielii
Copy link
Author

jackielii commented Dec 13, 2023

I keep maintaining my fork: https://github.com/jackielii/skhd. Now support wildcard forwarding in proc map:

ctrl - backspace | alt - backspace
ctrl - delete | alt - delete
# move word
# ctrl - left | alt - left
ctrl - left [
    "kitty" ~
    "wezterm" ~
    *       | alt - left
]
# ctrl - right | alt - right
ctrl - right [
    "kitty" ~
    "wezterm" ~
    # "Google Chrome" ~
    *       | alt - right
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant