forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiB9d8f4f8Ivan Molodetskikh1 month ago2997 commits

Configuration:-Include.md300 lines, 6.3 KiBHistoryRawDownload
1<sup>Since: 25.11</sup>
2
3You can include other files at the top level of the config.
4
5```kdl,must-fail
6// Some settings...
7
8include "colors.kdl"
9
10// Some more settings...
11```
12
13Included files have the same structure as the main config file.
14Settings from included files will be merged with the settings from the main config file.
15
16Included config files can in turn include more files.
17All included files are watched for changes, and the config live-reloads when any of them change.
18
19You 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
25Includes work only at the top level of the config:
26
27```kdl,must-fail
28// All good: include at the top level.
29include "something.kdl"
30
31layout {
32 // NOT allowed: include inside some other section.
33 include "other.kdl"
34}
35```
36
37### Positionality
38
39Includes are *positional*.
40They will override options set *prior* to them.
41Window rules from included files will be inserted at the position of the `include` line.
42For example:
43
44```kdl
45// colors.kdl
46layout {
47 border {
48 active-color "green"
49 }
50}
51
52overview {
53 backdrop-color "green"
54}
55```
56
57```kdl,must-fail
58// config.kdl
59layout {
60 border {
61 active-color "red"
62 }
63}
64
65// This overrides the border color and the backdrop color to green.
66include "colors.kdl"
67
68// This sets the overview backdrop color to red again.
69overview {
70 backdrop-color "red"
71}
72```
73
74The 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
79Another example:
80
81```kdl
82// rules.kdl
83window-rule {
84 match app-id="Alacritty"
85 open-maximized false
86}
87```
88
89```kdl,must-fail
90// config.kdl
91window-rule {
92 open-maximized true
93}
94
95// Window rules get inserted at this position.
96include "rules.kdl"
97
98window-rule {
99 match app-id="firefox$"
100 open-maximized true
101}
102```
103
104This is equivalent to the following config file:
105
106```kdl
107window-rule {
108 open-maximized true
109}
110
111// Included from rules.kdl.
112window-rule {
113 match app-id="Alacritty"
114 open-maximized false
115}
116
117window-rule {
118 match app-id="firefox$"
119 open-maximized true
120}
121```
122
123### Optional includes
124
125<sup>Since: 26.04</sup>
126
127By default, including a nonexistent file will cause an error.
128You can allow nonexistent includes by setting `optional=true`:
129
130```kdl,must-fail
131// Won't fail if this file doesn't exist.
132include optional=true "optional-config.kdl"
133
134// Regular include, will fail if the file doesn't exist.
135include "required-config.kdl"
136```
137
138When an optional include file is missing, niri will emit a warning in the logs on every config reload.
139This reminds you that the file is missing while still loading the config successfully.
140
141The optional file is still watched for changes, so if you create it later, the config will automatically reload and apply the new settings.
142
143Note that `optional` only affects whether a missing file causes an error.
144If the file exists but contains invalid syntax or other errors, those errors will still cause a parsing failure.
145
146
147### Merging
148
149Most 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
153layout {
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
168include "colors.kdl"
169
170layout {
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
183Multipart sections like `window-rule`, `output`, or `workspace` are inserted as is without merging:
184
185```kdl
186// laptop.kdl
187output "eDP-1" {
188 // ...
189}
190```
191
192```kdl,must-fail
193// config.kdl
194output "DP-2" {
195 // ...
196}
197
198include "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
209binds {
210 Mod+T { spawn "alacritty"; }
211}
212```
213
214```kdl,must-fail
215// config.kdl
216include "binds.kdl"
217
218binds {
219 // Overrides Mod+T from binds.kdl.
220 Mod+T { spawn "foot"; }
221}
222```
223
224#### Flags
225
226Most flags can be disabled with `false`:
227
228```kdl
229// csd.kdl
230
231// Write "false" to explicitly disable.
232prefer-no-csd false
233```
234
235```kdl,must-fail
236// config.kdl
237
238// Enable prefer-no-csd in the main config.
239prefer-no-csd
240
241// Including csd.kdl will disable it again.
242include "csd.kdl"
243```
244
245#### Non-merging sections
246
247Some sections where the contents represent a combined structure are not merged.
248Examples are `struts`, `preset-column-widths`, individual subsections in `animations`, pointing device sections in `input`.
249
250```kdl
251// struts.kdl
252layout {
253 struts {
254 left 64
255 right 64
256 }
257}
258```
259
260```kdl,must-fail
261// config.kdl
262layout {
263 struts {
264 top 64
265 bottom 64
266 }
267}
268
269include "struts.kdl"
270
271// Struts are not merged.
272// End result is only left and right struts.
273```
274
275### Border special case
276
277There's one special case that differs between the main config and included configs.
278
279Writing `layout { border {} }` in an included config does nothing (since no properties are changed).
280However, writing the same in the main config will *enable* the border, i.e. it's equivalent to `layout { border { on; } }`.
281
282So, 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
286layout {
287 border {
288 // Add this line:
289 on
290
291 width 4
292 active-color "#ffc87f"
293 inactive-color "#505050"
294 }
295}
296```
297
298The 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.
299It 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.
300Many 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.