niri
Clone
https://git.tahinli.com/Tahinli/niri.git
0 watching·0 forks·Rust·GPL-3.0·12.1 MiB·9d8f4f8·Ivan Molodetskikh·1 month ago·2997 commits
| 1 | <sup>Since: 25.11</sup> |
| 2 | |
| 3 | You can include other files at the top level of the config. |
| 4 | |
| 5 | ```kdl,must-fail |
| 6 | // Some settings... |
| 7 | |
| 8 | include "colors.kdl" |
| 9 | |
| 10 | // Some more settings... |
| 11 | ``` |
| 12 | |
| 13 | Included files have the same structure as the main config file. |
| 14 | Settings from included files will be merged with the settings from the main config file. |
| 15 | |
| 16 | Included config files can in turn include more files. |
| 17 | All included files are watched for changes, and the config live-reloads when any of them change. |
| 18 | |
| 19 | You can include by filename or path. |
| 20 | |
| 21 | * Relative to the current file: `other.kdl` or `./other.kdl` |
| 22 | * By absolute path: `/path/to/file.kdl` |
| 23 | * <sup>Since: 26.04</sup> Home dir paths: `~/file.kdl` expands to `/home/user/file.kdl` |
| 24 | |
| 25 | Includes work only at the top level of the config: |
| 26 | |
| 27 | ```kdl,must-fail |
| 28 | // All good: include at the top level. |
| 29 | include "something.kdl" |
| 30 | |
| 31 | layout { |
| 32 | // NOT allowed: include inside some other section. |
| 33 | include "other.kdl" |
| 34 | } |
| 35 | ``` |
| 36 | |
| 37 | ### Positionality |
| 38 | |
| 39 | Includes are *positional*. |
| 40 | They will override options set *prior* to them. |
| 41 | Window rules from included files will be inserted at the position of the `include` line. |
| 42 | For example: |
| 43 | |
| 44 | ```kdl |
| 45 | // colors.kdl |
| 46 | layout { |
| 47 | border { |
| 48 | active-color "green" |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | overview { |
| 53 | backdrop-color "green" |
| 54 | } |
| 55 | ``` |
| 56 | |
| 57 | ```kdl,must-fail |
| 58 | // config.kdl |
| 59 | layout { |
| 60 | border { |
| 61 | active-color "red" |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | // This overrides the border color and the backdrop color to green. |
| 66 | include "colors.kdl" |
| 67 | |
| 68 | // This sets the overview backdrop color to red again. |
| 69 | overview { |
| 70 | backdrop-color "red" |
| 71 | } |
| 72 | ``` |
| 73 | |
| 74 | The end result: |
| 75 | |
| 76 | - the border color is green (from `colors.kdl`), |
| 77 | - the overview backdrop color is red (it was set *after* `colors.kdl`). |
| 78 | |
| 79 | Another example: |
| 80 | |
| 81 | ```kdl |
| 82 | // rules.kdl |
| 83 | window-rule { |
| 84 | match app-id="Alacritty" |
| 85 | open-maximized false |
| 86 | } |
| 87 | ``` |
| 88 | |
| 89 | ```kdl,must-fail |
| 90 | // config.kdl |
| 91 | window-rule { |
| 92 | open-maximized true |
| 93 | } |
| 94 | |
| 95 | // Window rules get inserted at this position. |
| 96 | include "rules.kdl" |
| 97 | |
| 98 | window-rule { |
| 99 | match app-id="firefox$" |
| 100 | open-maximized true |
| 101 | } |
| 102 | ``` |
| 103 | |
| 104 | This is equivalent to the following config file: |
| 105 | |
| 106 | ```kdl |
| 107 | window-rule { |
| 108 | open-maximized true |
| 109 | } |
| 110 | |
| 111 | // Included from rules.kdl. |
| 112 | window-rule { |
| 113 | match app-id="Alacritty" |
| 114 | open-maximized false |
| 115 | } |
| 116 | |
| 117 | window-rule { |
| 118 | match app-id="firefox$" |
| 119 | open-maximized true |
| 120 | } |
| 121 | ``` |
| 122 | |
| 123 | ### Optional includes |
| 124 | |
| 125 | <sup>Since: 26.04</sup> |
| 126 | |
| 127 | By default, including a nonexistent file will cause an error. |
| 128 | You can allow nonexistent includes by setting `optional=true`: |
| 129 | |
| 130 | ```kdl,must-fail |
| 131 | // Won't fail if this file doesn't exist. |
| 132 | include optional=true "optional-config.kdl" |
| 133 | |
| 134 | // Regular include, will fail if the file doesn't exist. |
| 135 | include "required-config.kdl" |
| 136 | ``` |
| 137 | |
| 138 | When an optional include file is missing, niri will emit a warning in the logs on every config reload. |
| 139 | This reminds you that the file is missing while still loading the config successfully. |
| 140 | |
| 141 | The optional file is still watched for changes, so if you create it later, the config will automatically reload and apply the new settings. |
| 142 | |
| 143 | Note that `optional` only affects whether a missing file causes an error. |
| 144 | If the file exists but contains invalid syntax or other errors, those errors will still cause a parsing failure. |
| 145 | |
| 146 | |
| 147 | ### Merging |
| 148 | |
| 149 | Most config sections are merged between includes, meaning that you can set only a few properties, and only those properties will change. |
| 150 | |
| 151 | ```kdl |
| 152 | // colors.kdl |
| 153 | layout { |
| 154 | // Does not affect gaps, border width, etc. |
| 155 | // Only changes colors as written. |
| 156 | focus-ring { |
| 157 | active-color "blue" |
| 158 | } |
| 159 | |
| 160 | border { |
| 161 | active-color "green" |
| 162 | } |
| 163 | } |
| 164 | ``` |
| 165 | |
| 166 | ```kdl,must-fail |
| 167 | // config.kdl |
| 168 | include "colors.kdl" |
| 169 | |
| 170 | layout { |
| 171 | // Does not set border and focus-ring colors, |
| 172 | // so colors from colors.kdl are used. |
| 173 | gaps 8 |
| 174 | |
| 175 | border { |
| 176 | width 8 |
| 177 | } |
| 178 | } |
| 179 | ``` |
| 180 | |
| 181 | #### Multipart sections |
| 182 | |
| 183 | Multipart sections like `window-rule`, `output`, or `workspace` are inserted as is without merging: |
| 184 | |
| 185 | ```kdl |
| 186 | // laptop.kdl |
| 187 | output "eDP-1" { |
| 188 | // ... |
| 189 | } |
| 190 | ``` |
| 191 | |
| 192 | ```kdl,must-fail |
| 193 | // config.kdl |
| 194 | output "DP-2" { |
| 195 | // ... |
| 196 | } |
| 197 | |
| 198 | include "laptop.kdl" |
| 199 | |
| 200 | // End result: both DP-2 and eDP-1 settings. |
| 201 | ``` |
| 202 | |
| 203 | #### Binds |
| 204 | |
| 205 | `binds` will override previously-defined conflicting keys: |
| 206 | |
| 207 | ```kdl |
| 208 | // binds.kdl |
| 209 | binds { |
| 210 | Mod+T { spawn "alacritty"; } |
| 211 | } |
| 212 | ``` |
| 213 | |
| 214 | ```kdl,must-fail |
| 215 | // config.kdl |
| 216 | include "binds.kdl" |
| 217 | |
| 218 | binds { |
| 219 | // Overrides Mod+T from binds.kdl. |
| 220 | Mod+T { spawn "foot"; } |
| 221 | } |
| 222 | ``` |
| 223 | |
| 224 | #### Flags |
| 225 | |
| 226 | Most flags can be disabled with `false`: |
| 227 | |
| 228 | ```kdl |
| 229 | // csd.kdl |
| 230 | |
| 231 | // Write "false" to explicitly disable. |
| 232 | prefer-no-csd false |
| 233 | ``` |
| 234 | |
| 235 | ```kdl,must-fail |
| 236 | // config.kdl |
| 237 | |
| 238 | // Enable prefer-no-csd in the main config. |
| 239 | prefer-no-csd |
| 240 | |
| 241 | // Including csd.kdl will disable it again. |
| 242 | include "csd.kdl" |
| 243 | ``` |
| 244 | |
| 245 | #### Non-merging sections |
| 246 | |
| 247 | Some sections where the contents represent a combined structure are not merged. |
| 248 | Examples are `struts`, `preset-column-widths`, individual subsections in `animations`, pointing device sections in `input`. |
| 249 | |
| 250 | ```kdl |
| 251 | // struts.kdl |
| 252 | layout { |
| 253 | struts { |
| 254 | left 64 |
| 255 | right 64 |
| 256 | } |
| 257 | } |
| 258 | ``` |
| 259 | |
| 260 | ```kdl,must-fail |
| 261 | // config.kdl |
| 262 | layout { |
| 263 | struts { |
| 264 | top 64 |
| 265 | bottom 64 |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | include "struts.kdl" |
| 270 | |
| 271 | // Struts are not merged. |
| 272 | // End result is only left and right struts. |
| 273 | ``` |
| 274 | |
| 275 | ### Border special case |
| 276 | |
| 277 | There's one special case that differs between the main config and included configs. |
| 278 | |
| 279 | Writing `layout { border {} }` in an included config does nothing (since no properties are changed). |
| 280 | However, writing the same in the main config will *enable* the border, i.e. it's equivalent to `layout { border { on; } }`. |
| 281 | |
| 282 | So, if you want to move your layout configuration from the main config to a separate file, remember to add `on` to the border section, for example: |
| 283 | |
| 284 | ```kdl |
| 285 | // separate.kdl |
| 286 | layout { |
| 287 | border { |
| 288 | // Add this line: |
| 289 | on |
| 290 | |
| 291 | width 4 |
| 292 | active-color "#ffc87f" |
| 293 | inactive-color "#505050" |
| 294 | } |
| 295 | } |
| 296 | ``` |
| 297 | |
| 298 | The reason for this special case is that this is how it historically worked: back when I added borders, we didn't have any `on` flags, so I made writing the `border {}` section enable the border, with an explicit `off` to disable it. |
| 299 | It wouldn't be too problematic to change it, however the default config always had a pre-filled `layout { border { off; } }` section with a note saying that commenting out the `off` is enough to enable the border. |
| 300 | Many people likely have this part of the default config embedded in their configs now, so changing how it works would just cause a lot of confusion. |