-
-
Notifications
You must be signed in to change notification settings - Fork 153
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 request] Ignore key binds for specific apps/windows #412
Comments
Well isn't that wild, I literally went here to request this feature as I myself was having the issue when trying to use terminal navigation within Wezterm. (alt+b/f for jumping words) Happy to see a much more advanced version of what I was intending to ask already being proposed. In this case just an hour earlier. I second this feature request in case that has any bearing. |
The request makes sense. One other use case that I wanted to cover is to disable macOS "hide application" Alternative 1. A different syntax: [main.mode.binding]
alt-h = { if.app-bundle-id.not = 'com.github.wez.wezterm', run = 'focus left' } Unfortunately we have to use TOML and we can't reuse #278, because by the time the command inside the binding runs, the key event is already intercepted. Alternative 2. Teach [main.mode.binding]
alt-h = '''
if test --app-bundle-id com.github.wez.wezterm do
trigger-binding alt-h --send-to-macos # fallthrough
else
focus left
end
''' And it unlocks other use cases. For example keys can be remapped this way. (partially covers karabiner elements use cases) [mode.main.binding]
ctrl-left = 'trigger-binding --send-to-macos alt-left' # Bring Linux muscle memory to macOS
ctrl-right = 'trigger-binding --send-to-macos alt-right' # Bring Linux muscle memory to macOS |
I like your second suggestion the most. It's something that can provide value in the meantime as in your final example (also in shell scripts) and would eventually tie in nicely with the embedded scripting language. Would you be open to a PR for this? I'd like to have a go. As a real world use case example, it would simplify my #!/bin/bash
DIR=$1
# just an example here. I'd have to map the direction to a key or change the script input
KEY='somekey'
if aerospace list-windows --focused | grep -q "WezTerm"; then
aerospace trigger-binding --send-to-macos alt-$KEY
else
aerospace focus $DIR
fi |
Go ahead, thanks I'm not sure if |
I'll see what's possible and we can go from there. I'm not precious about my code so I'm happy just to prove it's doable and throw it away for a future PR if needs be 😃 |
If it works the alternative 3 could be:
|
There are just too many bindings I really want to have in emacs. The binding mode is also switched back to main when any other app's window is in front. This is my work-around for nikitabobko/AeroSpace#412
Hey folks, I didn't mean to make all those changes in my emacs.d/init.el in the same commit with the aerospace hackery. Essentially, I set up a special Then, I listen for Works like a charm. |
If anyone needs something now, my workaround which is a bit based on @\eljobe, is to utilize skhd's I added this to my aerospace.toml: [mode.passthrough.binding]
# this one does nothing, here just so that we have passthrough
ctrl-cmd-alt-shift-9 = 'close' I then have a script to do the passthrough magic: #!/usr/bin/env bash
# ~/aerospace/remap-passthrough.sh
# adds flags --key, --only, --except
while [[ "$#" -gt 0 ]]; do
case $1 in
--key) key="$2"; shift ;;
--only) only="$2"; shift ;;
--except) except="$2"; shift ;;
*) echo "Unknown parameter passed: $1"; exit 1 ;;
esac
shift
done
if [ -z "$key" ]; then
echo "Key not provided"
exit 1
fi
# --only handling: comma separated keys of apps for this keybind to act on
if [ -n "$only" ]; then
IFS=',' read -r -a only_array <<< "$only"
found=false
for item in "${only_array[@]}"; do
if aerospace list-windows --focused --format "%{app-name} | %{app-bundle-id}" | grep -q "$item"; then
found=true
break
fi
done
if [ "$found" = false ]; then
exit 0
fi
fi
# --except handling: comma separated keys of apps for this keybind to NOT act on.
if [ -n "$except" ]; then
IFS=',' read -r -a except_array <<< "$except"
for item in "${except_array[@]}"; do
if aerospace list-windows --focused --format "%{app-name} | %{app-bundle-id}" | grep -q "$item"; then
exit 0
fi
done
fi
aerospace mode passthrough
skhd -k "$key"
aerospace mode main So at the end, we can then bind something like this: # linux muscle memory
ctrl-a = 'exec-and-forget ~/aerospace/remap-passthrough.sh --key cmd-a --except "Edge,Firefox"' There's a slight delay as we're basically executing a bash script in the background each time, but it's good enough for me. |
If you're going to the effort of integrating SKHD, you may as well just use it to manage all of your Aerospace keybinds as it supports passthrough out of the box. Here is an example from my old skhdrc to ignore my yabai focus commands when wezterm is focused:
|
Apologies if this has been requested before - I couldn't find anything similar.
I would like to request a feature that allows us to ignore key binds if a specific app/window is focused and instead allow the keys to be sent to the application.
My use case is that I would like to integrate my
focus
keybinds with my terminal/multiplexer (Wezterm in this case). I was able to do this with yabai/skhd by leveraging Wezterms scriptable config. If it was focused, wezterm would handle the keypress and decide if it should navigate within its panes, based on the current panes siblings or if it should execute the yabai focus command.I have achieved something similar to this by executing a shell script on my focus keybinds and writing custom user vars to wezterm for it to handle. However this has introduced latency when switching focus even outside of wezterm. My setup for this is shared at the bottom if anyone else wants to achieve similar behaviour in the meantime.
Proposal
TOML isn't the greatest format for dynamic config, so I wonder if this can wait until #278 is implemented. Maybe there could be a feature to propagate key presses under arbitrary conditions.
Otherwise, I would draw inspiration from the callback syntax.
I would be happy to have a go at implementing this if it's a feature that aligns with the projects goals. Thanks for considering.
My config
My keybinds
focus.sh
wezterm user-var-changed handler (this is a stripped down version, I also have it set up to manage navigating within neovim windows)
The text was updated successfully, but these errors were encountered: