tony / oxwm

Branch: 736f91b
Switch branches/tags
master
Pascal0577 hm.nix: add descriptions and examples 736f91b 2026-02-18
412 lines · 13.5 KB Raw Blame History
1 {self}: {
2 config,
3 lib,
4 pkgs,
5 ...
6 }: let
7 inherit (lib) mkEnableOption mkOption mkIf types getExe;
8 cfg = config.programs.oxwm;
9
10 # Converts a nix submodule into a single oxwm bar block
11 blockToLua = block: let
12 common = ''
13 interval = ${toString block.interval},
14 color = "#${block.color}",
15 underline = ${lib.boolToString block.underline},'';
16 in
17 "oxwm.bar.block.${block.kind}({\n"
18 + (
19 if block.kind == "static"
20 then ''
21 text = "${block.text}",
22 ${common}
23 ''
24 else if block.kind == "shell"
25 then ''
26 format = "${block.format}",
27 command = "${block.command}",
28 ${common}
29 ''
30 else if block.kind == "datetime"
31 then ''
32 format = "${block.format}",
33 date_format = "${block.date_format}",
34 ${common}
35 ''
36 else if block.kind == "battery"
37 then ''
38 format = "${block.format}",
39 charging = "${block.charging}",
40 discharging = "${block.discharging}",
41 full = "${block.full}",
42 ${common}
43 ''
44 else ''
45 format = "${block.format}",
46 ${common}
47 ''
48 )
49 + "})";
50
51 ruleToLua = rule: let
52 fields = lib.concatStringsSep ", " (
53 lib.optional (rule.match.class != null) ''class = "${rule.match.class}"''
54 ++ lib.optional (rule.match.instance != null) ''instance = "${rule.match.instance}"''
55 ++ lib.optional (rule.match.title != null) ''title = "${rule.match.title}"''
56 ++ lib.optional (rule.match.role != null) ''role = "${rule.match.role}"''
57 ++ lib.optional (rule.floating != null) ''floating = ${lib.boolToString rule.floating}''
58 ++ lib.optional (rule.tag != null) ''tag = ${toString rule.tag}''
59 ++ lib.optional (rule.fullscreen != null) ''fullscreen = ${lib.boolToString rule.fullscreen}''
60 ++ lib.optional (rule.focus != null) ''focus = ${lib.boolToString rule.fullscreen}''
61 );
62 in "oxwm.rule.add({ ${fields} })";
63 in {
64 options.programs.oxwm = {
65 enable = mkEnableOption "oxwm window manager";
66 package = mkOption {
67 type = types.package;
68 default = self.packages.${pkgs.stdenv.hostPlatform.system}.default;
69 description = "The oxwm package to use";
70 };
71 extraSessionCommands = mkOption {
72 type = types.lines;
73 default = "";
74 description = "Shell commands executed just before oxwm is started";
75 };
76 settings = {
77 terminal = mkOption {
78 type = types.str;
79 default = "alacritty";
80 description = "Terminal used";
81 };
82 modkey = mkOption {
83 type = types.str;
84 default = "Mod4";
85 description = "Modifier key. Used for mouse dragging";
86 };
87 tags = mkOption {
88 type = types.listOf types.str;
89 default = ["1" "2" "3" "4" "5" "6" "7" "8" "9"];
90 description = "Workspace tags";
91 example = ["" "󰊯" "" "" "󰙯" "󱇤" "" "󱘶" "󰧮"];
92 };
93 layoutSymbol = {
94 tiling = mkOption {
95 type = types.str;
96 default = "[T]";
97 description = "Symbol in tiling mode";
98 };
99 normie = mkOption {
100 type = types.str;
101 default = "[F]";
102 description = "Symbol in normie mode";
103 };
104 tabbed = mkOption {
105 type = types.str;
106 default = "[=]";
107 description = "Symbol in tabbed mode";
108 };
109 };
110 autostart = mkOption {
111 type = types.listOf types.str;
112 default = [];
113 description = "A list of commands to run when oxwm starts";
114 };
115 binds = mkOption {
116 type = types.listOf (types.submodule {
117 options = {
118 mods = mkOption {
119 type = types.listOf types.str;
120 default = ["${cfg.modkey}"];
121 description = "The modifier keys to invoke the command";
122 };
123 key = mkOption {
124 type = types.str;
125 description = "The keystroke to invoke the command";
126 };
127 action = mkOption {
128 type = types.str;
129 description = "The command to invoke";
130 };
131 };
132 });
133 default = [];
134 description = "The list of keybinds";
135 example = ''[
136 {
137 mods = [ "Mod4" "Shift" ];
138 key = "Slash";
139 action = "oxwm.show_keybinds()";
140 }
141 {
142 mods = [ "Mod4" ];
143 key = "D";
144 action = "oxwm.spawn({ "sh", "-c", "dmenu_run -l 10" })";
145 }
146 ];'';
147 };
148 border = {
149 width = mkOption {
150 type = types.int;
151 default = 2;
152 description = "Width of the window borders";
153 };
154 focusedColor = mkOption {
155 type = types.str;
156 default = "6dade3";
157 description = "Color of the focused window";
158 };
159 unfocusedColor = mkOption {
160 type = types.str;
161 default = "bbbbbb";
162 description = "Color of the unfocused window";
163 };
164 };
165 gaps = {
166 smart = mkOption {
167 type = types.enum ["enabled" "disabled"];
168 default = "enabled";
169 description = "If enabled, removes border if single window in tag";
170 };
171 inner = mkOption {
172 type = types.listOf types.int;
173 default = [5 5];
174 description = "Inner gaps [ horizontal vertical ] in pixels";
175 };
176 outer = mkOption {
177 type = types.listOf types.int;
178 default = [5 5];
179 description = "Outer gaps [ horizontal vertical ] in pixels";
180 };
181 };
182 bar = {
183 font = mkOption {
184 type = types.str;
185 default = "monospace 10";
186 description = "The font displayed on the bar";
187 };
188 hideVacantTags = mkOption {
189 type = types.bool;
190 default = false;
191 description = "Whether to hide tags with no windows from the bar";
192 };
193 unoccupiedScheme = mkOption {
194 type = types.listOf types.str;
195 default = ["bbbbbb" "1a1b26" "444444"];
196 description = "The colorscheme to use for unoccupied tags as hex colors. Do not put a `#` before each color.";
197 };
198 occupiedScheme = mkOption {
199 type = types.listOf types.str;
200 default = ["0db9d7" "1a1b26" "0db9d7"];
201 description = "The colorscheme to use for occupied tags as hex colors. Do not put a `#` before each color.";
202 };
203 selectedScheme = mkOption {
204 type = types.listOf types.str;
205 default = ["0db9d7" "1a1b26" "ad8ee6"];
206 description = "The colorscheme to use for selected tags as hex colors. Do not put a `#` before each color.";
207 };
208 urgentScheme = mkOption {
209 type = types.listOf types.str;
210 default = ["f7768e" "1a1b26" "f7768e"];
211 description = "The colorscheme to use for tags with a window requesting attention as hex colors. Do not put a `#` before each color.";
212 };
213 blocks = mkOption {
214 type = types.listOf (types.submodule {
215 options = {
216 kind = mkOption {
217 type = types.enum ["ram" "static" "shell" "datetime" "battery"];
218 default = "static";
219 description = "The kind of block to be used";
220 };
221 interval = mkOption {
222 type = types.int;
223 default = 5;
224 };
225 color = mkOption {
226 type = types.str;
227 default = "";
228 };
229 underline = mkOption {
230 type = types.bool;
231 default = true;
232 };
233 text = mkOption {
234 type = types.str;
235 default = "|";
236 };
237 format = mkOption {
238 type = types.str;
239 default = "{}";
240 };
241 command = mkOption {
242 type = types.str;
243 default = "uname -r";
244 };
245 date_format = mkOption {
246 type = types.str;
247 default = "%a, %b %d - %-I:%M %P";
248 };
249 charging = mkOption {
250 type = types.str;
251 default = "⚡ Bat: {}%";
252 };
253 discharging = mkOption {
254 type = types.str;
255 default = "- Bat: {}%";
256 };
257 full = mkOption {
258 type = types.str;
259 default = "✓ Bat: {}%";
260 };
261 };
262 });
263 description = "The modules to put on the bar";
264 example = ''[
265 {
266 kind = "ram";
267 interval = 5;
268 format = "Ram: {used}/{total} GB";
269 color = "9ece6a";
270 }
271 {
272 kind = "static";
273 text = "|";
274 interval = 99999999;
275 color = "6dade3";
276 }
277 {
278 kind = "shell";
279 format = "{}";
280 command = "uname -r";
281 interval = 9999999;
282 color = "f7768e";
283 underline = true;
284 }
285 ];'';
286 };
287 };
288 rules = mkOption {
289 type = types.listOf (types.submodule {
290 options = {
291 match = {
292 class = mkOption {
293 type = types.nullOr types.str;
294 default = null;
295 description = "The class to match windows with";
296 };
297 instance = mkOption {
298 type = types.nullOr types.str;
299 default = null;
300 description = "The instance to match windows with";
301 };
302 title = mkOption {
303 type = types.nullOr types.str;
304 default = null;
305 description = "The title to match windows with";
306 };
307 role = mkOption {
308 type = types.nullOr types.str;
309 default = null;
310 description = "The role to match windows with";
311 };
312 };
313 floating = mkOption {
314 type = types.nullOr types.bool;
315 default = null;
316 description = "Whether to apply floating to the matched window";
317 };
318 tag = mkOption {
319 type = types.nullOr types.int;
320 default = null;
321 description = "What tag the matched window should be opened on";
322 };
323 fullscreen = mkOption {
324 type = types.nullOr types.bool;
325 default = null;
326 description = "Whether to apply fullscreen to the matched window";
327 };
328 focus = mkOption {
329 type = types.nullOr types.bool;
330 default = null;
331 description = "Whether to apply focus to the matched window";
332 };
333 };
334 });
335 description = "A list of window rules for the window manager to follow";
336 example = ''[
337 {
338 match.class = "gimp";
339 floating = true;
340 }
341 {
342 match.class = "firefox";
343 match.title = "Library";
344 tag = 9;
345 focus = true;
346 }
347 ];'';
348 };
349 extraConfig = mkOption {
350 type = types.lines;
351 default = "";
352 description = "Extra lua confguration that gets inserted at the bottom of the file";
353 };
354 };
355 };
356
357 config = mkIf cfg.enable {
358 home.packages = [cfg.package];
359
360 xsession.windowManager.command = ''
361 ${cfg.extraSessionCommands}
362 export _JAVA_AWT_WM_NONREPARENTING=1
363 exec ${getExe cfg.package}
364 '';
365
366 xdg.configFile."oxwm/config.lua".text = ''
367 @meta
368 @module 'oxwm'
369
370 oxwm.set_terminal("${cfg.terminal}")
371 oxwm.set_modkey("${cfg.modkey}")
372 oxwm.set_tags({${lib.concatMapStringsSep ", " (t: ''"${t}"'') cfg.tags}})
373
374 local blocks = {
375 ${lib.concatMapStringsSep ",\n" blockToLua cfg.bar.blocks}
376 };
377 oxwm.bar.set_blocks(blocks)
378 oxwm.bar.set_font("${cfg.bar.font}")
379 oxwm.bar.set_scheme_normal(${lib.concatMapStringsSep ", " (c: ''"#${c}"'') cfg.bar.unoccupiedScheme})
380 oxwm.bar.set_scheme_occupied(${lib.concatMapStringsSep ", " (c: ''"#${c}"'') cfg.bar.occupiedScheme})
381 oxwm.bar.set_scheme_selected(${lib.concatMapStringsSep ", " (c: ''"#${c}"'') cfg.bar.selectedScheme})
382 oxwm.bar.set_scheme_urgent(${lib.concatMapStringsSep ", " (c: ''"#${c}"'') cfg.bar.urgentScheme})
383 oxwm.bar.set_hide_vacant_tags(${lib.boolToString cfg.bar.hideVacantTags})
384
385 oxwm.border.set_width(${toString cfg.border.width})
386 oxwm.border.set_focused_color("#${cfg.border.focusedColor}")
387 oxwm.border.set_unfocused_color("#${cfg.border.unfocusedColor}")
388
389 oxwm.gaps.set_smart(${cfg.gaps.smart})
390 oxwm.gaps.set_inner(${lib.concatMapStringsSep ", " toString cfg.gaps.inner})
391 oxwm.gaps.set_outer(${lib.concatMapStringsSep ", " toString cfg.gaps.outer})
392
393 oxwm.set_layout_symbol("tiling", "${cfg.layoutSymbol.tiling}")
394 oxwm.set_layout_symbol("normie", "${cfg.layoutSymbol.normie}")
395 oxwm.set_layout_symbol("tabbed", "${cfg.layoutSymbol.tabbed}")
396
397 ${lib.concatMapStrings (cmd: ''
398 oxwm.autostart("${cmd}")
399 '')
400 cfg.autostart}
401 ${lib.concatMapStrings (bind: ''
402 oxwm.key.bind({ ${lib.concatMapStringsSep ", " (m: ''"${m}"'') bind.mods} }, "${bind.key}", ${bind.action})
403 '')
404 cfg.binds}
405 ${cfg.extraConfig}
406 ${lib.concatMapStrings (rule: ''
407 ${ruleToLua rule}
408 '')
409 cfg.rules}
410 '';
411 };
412 }