wiki: Add key bindings
Browse files at this commit3c75082df2ef976b1e8ab03585f5b083f98651d7Parent: 9927c154 changed files +188 -7
- resources/default-config.kdl +0 -7
- wiki/Configuration:-Debug-Options.md +13 -0
- wiki/Configuration:-Key-Bindings.md +174 -0
- wiki/_Sidebar.md +1 -0
resources/default-config.kdlmodified+0 -7
| @@ -469,16 +469,9 @@ binds { | |||
| 469 | Alt+Print { screenshot-window; } | 469 | Alt+Print { screenshot-window; } |
| 470 | 470 | ||
| 471 | // The quit action will show a confirmation dialog to avoid accidental exits. | 471 | // The quit action will show a confirmation dialog to avoid accidental exits. |
| 472 | - // If you want to skip the confirmation dialog, set the flag like so: | ||
| 473 | - // Mod+Shift+E { quit skip-confirmation=true; } | ||
| 474 | Mod+Shift+E { quit; } | 472 | Mod+Shift+E { quit; } |
| 475 | 473 | ||
| 476 | // Powers off the monitors. To turn them back on, do any input like | 474 | // Powers off the monitors. To turn them back on, do any input like |
| 477 | // moving the mouse or pressing any other key. | 475 | // moving the mouse or pressing any other key. |
| 478 | Mod+Shift+P { power-off-monitors; } | 476 | Mod+Shift+P { power-off-monitors; } |
| 479 | - | ||
| 480 | - // This debug bind will tint all surfaces green, unless they are being | ||
| 481 | - // directly scanned out. It's therefore useful to check if direct scanout | ||
| 482 | - // is working. | ||
| 483 | - // Mod+Shift+Ctrl+T { toggle-debug-tint; } | ||
| 484 | } | 477 | } |
wiki/Configuration:-Debug-Options.mdmodified+13 -0
| @@ -125,3 +125,16 @@ debug { | |||
| 125 | enable-color-transformations-capability | 125 | enable-color-transformations-capability |
| 126 | } | 126 | } |
| 127 | ``` | 127 | ``` |
| 128 | + | ||
| 129 | +### `toggle-debug-tint` Key Binding | ||
| 130 | + | ||
| 131 | +This one is not a debug option, but rather a key binding. | ||
| 132 | + | ||
| 133 | +It will tint all surfaces green, unless they are being directly scanned out. | ||
| 134 | +It's therefore useful to check if direct scanout is working. | ||
| 135 | + | ||
| 136 | +``` | ||
| 137 | +binds { | ||
| 138 | + Mod+Shift+Ctrl+T { toggle-debug-tint; } | ||
| 139 | +} | ||
| 140 | +``` | ||
wiki/Configuration:-Key-Bindings.mdadded+174 -0
| @@ -0,0 +1,174 @@ | |||
| 1 | +### Overview | ||
| 2 | + | ||
| 3 | +Key bindings are declared in the `binds {}` section of the config. | ||
| 4 | + | ||
| 5 | +> [!NOTE] | ||
| 6 | +> This is one of the few sections that *does not* get automatically filled with defaults if you omit it, so make sure to copy it from the default config. | ||
| 7 | + | ||
| 8 | +Each bind is a hotkey followed by one action enclosed in curly brackets. | ||
| 9 | +For example: | ||
| 10 | + | ||
| 11 | +``` | ||
| 12 | +binds { | ||
| 13 | + Mod+Left { focus-column-left; } | ||
| 14 | +} | ||
| 15 | +``` | ||
| 16 | + | ||
| 17 | +The hotkey consists of modifiers separated by `+` signs, followed by an XKB key name in the end. | ||
| 18 | + | ||
| 19 | +Valid modifiers are: | ||
| 20 | + | ||
| 21 | +- `Ctrl` or `Control`; | ||
| 22 | +- `Shift`; | ||
| 23 | +- `Alt`; | ||
| 24 | +- `Super` or `Win`; | ||
| 25 | +- `ISO_Level3_Shift` or `Mod5`---this is the AltGr key on certain layouts; | ||
| 26 | +- `Mod`. | ||
| 27 | + | ||
| 28 | +`Mod` is a special modifier that is equal to `Super` when running niri on a TTY, and to `Alt` when running niri as a nested winit window. | ||
| 29 | +This way, you can test niri in a window without causing too many conflicts with the host compositor's key bindings. | ||
| 30 | +For this reason, most of the default keys use the `Mod` modifier. | ||
| 31 | + | ||
| 32 | +> [!TIP] | ||
| 33 | +> To find an XKB name for a particular key, you may use a program like [`wev`](https://git.sr.ht/~sircmpwn/wev). | ||
| 34 | +> | ||
| 35 | +> Open it from a terminal and press the key that you want to detect. | ||
| 36 | +> In the terminal, you will see output like this: | ||
| 37 | +> | ||
| 38 | +> ``` | ||
| 39 | +> [14: wl_keyboard] key: serial: 757775; time: 44940343; key: 113; state: 1 (pressed) | ||
| 40 | +> sym: Left (65361), utf8: '' | ||
| 41 | +> [14: wl_keyboard] key: serial: 757776; time: 44940432; key: 113; state: 0 (released) | ||
| 42 | +> sym: Left (65361), utf8: '' | ||
| 43 | +> [14: wl_keyboard] key: serial: 757777; time: 44940753; key: 114; state: 1 (pressed) | ||
| 44 | +> sym: Right (65363), utf8: '' | ||
| 45 | +> [14: wl_keyboard] key: serial: 757778; time: 44940846; key: 114; state: 0 (released) | ||
| 46 | +> sym: Right (65363), utf8: '' | ||
| 47 | +> ``` | ||
| 48 | +> | ||
| 49 | +> Here, look at `sym: Left` and `sym: Right`: these are the key names. | ||
| 50 | +> I was pressing the left and the right arrow in this example. | ||
| 51 | + | ||
| 52 | +Binds can also have a cooldown, which will rate-limit the bind and prevent it from repeatedly triggering too quickly. | ||
| 53 | + | ||
| 54 | +``` | ||
| 55 | +binds { | ||
| 56 | + Mod+T cooldown-ms=500 { spawn "alacritty"; } | ||
| 57 | +} | ||
| 58 | +``` | ||
| 59 | + | ||
| 60 | +This is mostly useful for the scroll bindings. | ||
| 61 | + | ||
| 62 | +### Scroll Bindings | ||
| 63 | + | ||
| 64 | +You can bind mouse wheel scroll ticks using the following syntax. | ||
| 65 | +These binds will change direction based on the `natural-scroll` setting. | ||
| 66 | + | ||
| 67 | +``` | ||
| 68 | +binds { | ||
| 69 | + Mod+WheelScrollDown cooldown-ms=150 { focus-workspace-down; } | ||
| 70 | + Mod+WheelScrollUp cooldown-ms=150 { focus-workspace-up; } | ||
| 71 | + Mod+WheelScrollRight { focus-column-right; } | ||
| 72 | + Mod+WheelScrollLeft { focus-column-left; } | ||
| 73 | +} | ||
| 74 | +``` | ||
| 75 | + | ||
| 76 | +Similarly, you can bind touchpad scroll "ticks". | ||
| 77 | +Touchpad scrolling is continuous, so for these binds it is split into discrete intervals based on distance travelled. | ||
| 78 | + | ||
| 79 | +These binds are also affected by touchpad's `natural-scroll`, so these example binds are "inverted", since niri has `natural-scroll` enabled for touchpads by default. | ||
| 80 | + | ||
| 81 | +``` | ||
| 82 | +binds { | ||
| 83 | + Mod+TouchpadScrollDown { spawn "wpctl" "set-volume" "@DEFAULT_AUDIO_SINK@" "0.02+"; } | ||
| 84 | + Mod+TouchpadScrollUp { spawn "wpctl" "set-volume" "@DEFAULT_AUDIO_SINK@" "0.02-"; } | ||
| 85 | +} | ||
| 86 | +``` | ||
| 87 | + | ||
| 88 | +Both mouse wheel and touchpad scroll binds will prevent applications from receiving any scroll events when their modifiers are held down. | ||
| 89 | +For example, if you have a `Mod+WheelScrollDown` bind, then while holding `Mod`, all mouse wheel scrolling will be consumed by niri. | ||
| 90 | + | ||
| 91 | +### Actions | ||
| 92 | + | ||
| 93 | +Every action that you can bind is also available for programmatic invocation via `niri msg action`. | ||
| 94 | +Run `niri msg action` to get a full list of actions along with their short descriptions. | ||
| 95 | + | ||
| 96 | +Here are a few actions that benefit from more explanation. | ||
| 97 | + | ||
| 98 | +#### `spawn` | ||
| 99 | + | ||
| 100 | +Run a program. | ||
| 101 | + | ||
| 102 | +`spawn` accepts a path to the program binary as the first argument, followed by arguments to the program. | ||
| 103 | +For example: | ||
| 104 | + | ||
| 105 | +``` | ||
| 106 | +binds { | ||
| 107 | + // Run alacritty. | ||
| 108 | + Mod+T { spawn "alacritty"; } | ||
| 109 | + | ||
| 110 | + // Run `wpctl set-volume @DEFAULT_AUDIO_SINK@ 0.1+`. | ||
| 111 | + XF86AudioRaiseVolume { spawn "wpctl" "set-volume" "@DEFAULT_AUDIO_SINK@" "0.1+"; } | ||
| 112 | +} | ||
| 113 | +``` | ||
| 114 | + | ||
| 115 | +Currently, niri *does not* use a shell to run commands, which means that you need to manually separate arguments. | ||
| 116 | + | ||
| 117 | +``` | ||
| 118 | +binds { | ||
| 119 | + // Correct: every argument is in its own quotes. | ||
| 120 | + Mod+T { spawn "alacritty" "-e" "/usr/bin/fish"; } | ||
| 121 | + | ||
| 122 | + // Wrong: will interpret the whole `alacritty -e /usr/bin/fish` string as the binary path. | ||
| 123 | + Mod+T { spawn "alacritty -e /usr/bin/fish"; } | ||
| 124 | + | ||
| 125 | + // Wrong: will pass `-e /usr/bin/fish` as one argument, which alacritty won't understand. | ||
| 126 | + Mod+T { spawn "alacritty" "-e /usr/bin/fish"; } | ||
| 127 | +} | ||
| 128 | +``` | ||
| 129 | + | ||
| 130 | +This also means that you cannot expand environment variables or `~`. | ||
| 131 | +If you need this, you can run the command through a shell manually. | ||
| 132 | + | ||
| 133 | +``` | ||
| 134 | +binds { | ||
| 135 | + // Wrong: no shell expansion here. These strings will be passed literally to the program. | ||
| 136 | + Mod+T { spawn "grim" "-o" "$MAIN_OUTPUT" "~/screenshot.png"; } | ||
| 137 | + | ||
| 138 | + // Correct: run this through a shell manually so that it can expand the arguments. | ||
| 139 | + // Note that the entire command is passed as a SINGLE argument, | ||
| 140 | + // because shell will do its own argument splitting by whitespace. | ||
| 141 | + Mod+T { spawn "sh" "-c" "grim -o $MAIN_OUTPUT ~/screenshot.png"; } | ||
| 142 | + | ||
| 143 | + // You can also use a shell to run multiple commands, | ||
| 144 | + // use pipes, process substitution, and so on. | ||
| 145 | + Mod+T { spawn "sh" "-c" "notify-send clipboard \"$(wl-paste)\""; } | ||
| 146 | +} | ||
| 147 | +``` | ||
| 148 | + | ||
| 149 | +As a special case, niri will expand `~` to the home directory *only* at the beginning of the program name. | ||
| 150 | + | ||
| 151 | +``` | ||
| 152 | +binds { | ||
| 153 | + // This will work: one ~ at the very beginning. | ||
| 154 | + Mod+T { spawn "~/scripts/do-something.sh"; } | ||
| 155 | +} | ||
| 156 | +``` | ||
| 157 | + | ||
| 158 | +#### `quit` | ||
| 159 | + | ||
| 160 | +Exit niri after showing a confirmation dialog to avoid accidentally triggering it. | ||
| 161 | + | ||
| 162 | +``` | ||
| 163 | +binds { | ||
| 164 | + Mod+Shift+E { quit; } | ||
| 165 | +} | ||
| 166 | +``` | ||
| 167 | + | ||
| 168 | +If you want to skip the confirmation dialog, set the flag like so: | ||
| 169 | + | ||
| 170 | +``` | ||
| 171 | +binds { | ||
| 172 | + Mod+Shift+E { quit skip-confirmation=true; } | ||
| 173 | +} | ||
| 174 | +``` | ||
wiki/_Sidebar.mdmodified+1 -0
| @@ -9,6 +9,7 @@ | |||
| 9 | * [Overview](./Configuration:-Overview.md) | 9 | * [Overview](./Configuration:-Overview.md) |
| 10 | * [Input](./Configuration:-Input.md) | 10 | * [Input](./Configuration:-Input.md) |
| 11 | * [Outputs](./Configuration:-Outputs.md) | 11 | * [Outputs](./Configuration:-Outputs.md) |
| 12 | +* [Key Bindings](./Configuration:-Key-Bindings.md) | ||
| 12 | * [Window Rules](./Configuration:-Window-Rules.md) | 13 | * [Window Rules](./Configuration:-Window-Rules.md) |
| 13 | * [Animations](./Configuration:-Animations.md) | 14 | * [Animations](./Configuration:-Animations.md) |
| 14 | * [Debug Options](./Configuration:-Debug-Options.md) | 15 | * [Debug Options](./Configuration:-Debug-Options.md) |