diff --git a/docs/wiki/Configuration:-Key-Bindings.md b/docs/wiki/Configuration:-Key-Bindings.md index 3a51b410..4a7f1237 100644 --- a/docs/wiki/Configuration:-Key-Bindings.md +++ b/docs/wiki/Configuration:-Key-Bindings.md @@ -100,6 +100,67 @@ binds { This is mostly useful for the scroll bindings. +### Press and Release Bindings + +Since: next release + +Binds can be set to trigger on key press, on key release, or both. +By default, binds trigger on key press. +You can change it using `press {}` and `release {}` blocks: + +```kdl +binds { + // Trigger on press (default behavior). + Mod+T { spawn "alacritty"; } + + // Trigger on release. + // Press and release Mod by itself to open the overview. + Mod { + release { toggle-overview; } + } + + // Trigger on both press and release with different actions. + // + // If the press action runs, the release action is guaranteed to run, + // no matter how you release the keys. + // You can safely use these binds for things like push-to-talk. + Control_R { + press { spawn "notify-send" "Enable push-to-talk"; } + release { spawn "notify-send" "Disable push-to-talk"; } + } + + // Release binds trigger only if you don't press anything else in between. + // So, an Alt+Shift bind like this still lets you hit + // Alt+Shift+arrows and other shortcuts in applications. + Alt+Shift { + release { switch-layout "next"; } + } +} +``` + +Release bindings are especially useful when you want to bind a modifier key. +A normal press bind would effectively prevent you from having any other bind containing that modifier. + +Release-only binds only trigger when you don't press anything else while holding it. +If you have a release-only `Mod` bind from the example above, and press any other key or mouse button while holding `Mod`, the bind will not trigger (the overview won't open). + +In bindings with both press and release, the release action is guaranteed to trigger if the press action triggers. +So, your push-to-talk press-release binding will never get stuck pressed, no matter how you release the keys. + +By default, any bind with both press and release action does not repeat. +You can explicitly set `repeat=true` if needed: + +```kdl +binds { + // Doesn't repeat automatically + // because it has a release {} section. + Mod+Shift+Q repeat=true { + press { spawn "notify-send" "Pressed (repeating)"; } + release { spawn "notify-send" "Released"; } + } +} +``` + ### Scroll Bindings You can bind mouse wheel scroll ticks using the following syntax. diff --git a/resources/default-config.kdl b/resources/default-config.kdl index 117f2a5d..190e5950 100644 --- a/resources/default-config.kdl +++ b/resources/default-config.kdl @@ -401,7 +401,21 @@ binds { // Open/close the Overview: a zoomed-out view of workspaces and windows. // You can also move the mouse into the top-left hot corner, // or do a four-finger swipe up on a touchpad. - Mod+O repeat=false { toggle-overview; } + // + // This is a release bind. + // Press and release Mod by itself to trigger it. + Mod { + release { toggle-overview; } + } + + // You can also bind both press and release actions like so. + // If the press action fires, the release action + // is also guaranteed to fire. + // This is useful for binds like push-to-talk. + // Alt+Shift { + // press { spawn "notify-send" "Enable push-to-talk!"; } + // release { spawn "notify-send" "Disable push-to-talk!"; } + // } Mod+Q repeat=false { close-window; } Alt+F4 repeat=false { close-window; }