tony / oxwm

Branch: 0499e00
Switch branches/tags
master
Pascal0577 hm.nix: formatted with nix fmt 0499e00 2026-02-18
457 lines · 15.4 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.settings;
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 chords = mkOption {
149 type = types.listOf (types.submodule {
150 options = {
151 notes = mkOption {
152 type = types.listOf (types.submodule {
153 options = {
154 mods = mkOption {
155 type = types.listOf types.str;
156 default = [];
157 };
158 key = mkOption {type = types.str;};
159 };
160 });
161 };
162 action = mkOption {type = types.str;};
163 };
164 });
165 default = [];
166 description = "A list of key chords for OXWM to use";
167 example = '' [
168 {
169 notes = [
170 {
171 mods = [ "Mod4" ];
172 key = "Space";
173 }
174 {
175 mods = [];
176 key = "T";
177 }
178 ];
179 action = "oxwm.spawn_terminal()";
180 }
181 ];
182 '';
183 };
184 border = {
185 width = mkOption {
186 type = types.int;
187 default = 2;
188 description = "Width of the window borders";
189 };
190 focusedColor = mkOption {
191 type = types.str;
192 default = "6dade3";
193 description = "Color of the focused window";
194 };
195 unfocusedColor = mkOption {
196 type = types.str;
197 default = "bbbbbb";
198 description = "Color of the unfocused window";
199 };
200 };
201 gaps = {
202 smart = mkOption {
203 type = types.enum ["enabled" "disabled"];
204 default = "enabled";
205 description = "If enabled, removes border if single window in tag";
206 };
207 inner = mkOption {
208 type = types.listOf types.int;
209 default = [5 5];
210 description = "Inner gaps [ horizontal vertical ] in pixels";
211 };
212 outer = mkOption {
213 type = types.listOf types.int;
214 default = [5 5];
215 description = "Outer gaps [ horizontal vertical ] in pixels";
216 };
217 };
218 bar = {
219 font = mkOption {
220 type = types.str;
221 default = "monospace 10";
222 description = "The font displayed on the bar";
223 };
224 hideVacantTags = mkOption {
225 type = types.bool;
226 default = false;
227 description = "Whether to hide tags with no windows from the bar";
228 };
229 unoccupiedScheme = mkOption {
230 type = types.listOf types.str;
231 default = ["bbbbbb" "1a1b26" "444444"];
232 description = "The colorscheme to use for unoccupied tags as hex colors. Do not put a `#` before each color.";
233 };
234 occupiedScheme = mkOption {
235 type = types.listOf types.str;
236 default = ["0db9d7" "1a1b26" "0db9d7"];
237 description = "The colorscheme to use for occupied tags as hex colors. Do not put a `#` before each color.";
238 };
239 selectedScheme = mkOption {
240 type = types.listOf types.str;
241 default = ["0db9d7" "1a1b26" "ad8ee6"];
242 description = "The colorscheme to use for selected tags as hex colors. Do not put a `#` before each color.";
243 };
244 urgentScheme = mkOption {
245 type = types.listOf types.str;
246 default = ["f7768e" "1a1b26" "f7768e"];
247 description = "The colorscheme to use for tags with a window requesting attention as hex colors. Do not put a `#` before each color.";
248 };
249 blocks = mkOption {
250 type = types.listOf (types.submodule {
251 options = {
252 kind = mkOption {
253 type = types.enum ["ram" "static" "shell" "datetime" "battery"];
254 default = "static";
255 description = "The kind of block to be used";
256 };
257 interval = mkOption {
258 type = types.int;
259 default = 5;
260 };
261 color = mkOption {
262 type = types.str;
263 default = "";
264 };
265 underline = mkOption {
266 type = types.bool;
267 default = true;
268 };
269 text = mkOption {
270 type = types.str;
271 default = "|";
272 };
273 format = mkOption {
274 type = types.str;
275 default = "{}";
276 };
277 command = mkOption {
278 type = types.str;
279 default = "uname -r";
280 };
281 date_format = mkOption {
282 type = types.str;
283 default = "%a, %b %d - %-I:%M %P";
284 };
285 charging = mkOption {
286 type = types.str;
287 default = "⚡ Bat: {}%";
288 };
289 discharging = mkOption {
290 type = types.str;
291 default = "- Bat: {}%";
292 };
293 full = mkOption {
294 type = types.str;
295 default = "✓ Bat: {}%";
296 };
297 };
298 });
299 description = "The modules to put on the bar";
300 example = '' [
301 {
302 kind = "ram";
303 interval = 5;
304 format = "Ram: {used}/{total} GB";
305 color = "9ece6a";
306 }
307 {
308 kind = "static";
309 text = "|";
310 interval = 99999999;
311 color = "6dade3";
312 }
313 {
314 kind = "shell";
315 format = "{}";
316 command = "uname -r";
317 interval = 9999999;
318 color = "f7768e";
319 underline = true;
320 }
321 ];'';
322 };
323 };
324 rules = mkOption {
325 type = types.listOf (types.submodule {
326 options = {
327 match = {
328 class = mkOption {
329 type = types.nullOr types.str;
330 default = null;
331 description = "The class to match windows with";
332 };
333 instance = mkOption {
334 type = types.nullOr types.str;
335 default = null;
336 description = "The instance to match windows with";
337 };
338 title = mkOption {
339 type = types.nullOr types.str;
340 default = null;
341 description = "The title to match windows with";
342 };
343 role = mkOption {
344 type = types.nullOr types.str;
345 default = null;
346 description = "The role to match windows with";
347 };
348 };
349 floating = mkOption {
350 type = types.nullOr types.bool;
351 default = null;
352 description = "Whether to apply floating to the matched window";
353 };
354 tag = mkOption {
355 type = types.nullOr types.int;
356 default = null;
357 description = "What tag the matched window should be opened on";
358 };
359 fullscreen = mkOption {
360 type = types.nullOr types.bool;
361 default = null;
362 description = "Whether to apply fullscreen to the matched window";
363 };
364 focus = mkOption {
365 type = types.nullOr types.bool;
366 default = null;
367 description = "Whether to apply focus to the matched window";
368 };
369 };
370 });
371 description = "A list of window rules for the window manager to follow";
372 example = '' [
373 {
374 match.class = "gimp";
375 floating = true;
376 }
377 {
378 match.class = "firefox";
379 match.title = "Library";
380 tag = 9;
381 focus = true;
382 }
383 ];'';
384 };
385 extraConfig = mkOption {
386 type = types.lines;
387 default = "";
388 description = "Extra lua confguration that gets inserted at the bottom of the file";
389 };
390 };
391 };
392
393 config = mkIf config.programs.oxwm.enable {
394 home.packages = [config.programs.oxwm.package];
395
396 xsession.windowManager.command = ''
397 ${config.programs.oxwm.extraSessionCommands}
398 export _JAVA_AWT_WM_NONREPARENTING=1
399 exec ${getExe config.programs.oxwm.package}
400 '';
401
402 xdg.configFile."oxwm/config.lua".text = ''
403 @meta
404 @module 'oxwm'
405
406 oxwm.set_terminal("${cfg.terminal}")
407 oxwm.set_modkey("${cfg.modkey}")
408 oxwm.set_tags({${lib.concatMapStringsSep ", " (t: ''"${t}"'') cfg.tags}})
409
410 local blocks = {
411 ${lib.concatMapStringsSep ",\n" blockToLua cfg.bar.blocks}
412 };
413 oxwm.bar.set_blocks(blocks)
414 oxwm.bar.set_font("${cfg.bar.font}")
415 oxwm.bar.set_scheme_normal(${lib.concatMapStringsSep ", " (c: ''"#${c}"'') cfg.bar.unoccupiedScheme})
416 oxwm.bar.set_scheme_occupied(${lib.concatMapStringsSep ", " (c: ''"#${c}"'') cfg.bar.occupiedScheme})
417 oxwm.bar.set_scheme_selected(${lib.concatMapStringsSep ", " (c: ''"#${c}"'') cfg.bar.selectedScheme})
418 oxwm.bar.set_scheme_urgent(${lib.concatMapStringsSep ", " (c: ''"#${c}"'') cfg.bar.urgentScheme})
419 oxwm.bar.set_hide_vacant_tags(${lib.boolToString cfg.bar.hideVacantTags})
420
421 oxwm.border.set_width(${toString cfg.border.width})
422 oxwm.border.set_focused_color("#${cfg.border.focusedColor}")
423 oxwm.border.set_unfocused_color("#${cfg.border.unfocusedColor}")
424
425 oxwm.gaps.set_smart(${cfg.gaps.smart})
426 oxwm.gaps.set_inner(${lib.concatMapStringsSep ", " toString cfg.gaps.inner})
427 oxwm.gaps.set_outer(${lib.concatMapStringsSep ", " toString cfg.gaps.outer})
428
429 oxwm.set_layout_symbol("tiling", "${cfg.layoutSymbol.tiling}")
430 oxwm.set_layout_symbol("normie", "${cfg.layoutSymbol.normie}")
431 oxwm.set_layout_symbol("tabbed", "${cfg.layoutSymbol.tabbed}")
432
433 ${lib.concatMapStrings (cmd: ''
434 oxwm.autostart("${cmd}")
435 '')
436 cfg.autostart}
437 ${lib.concatMapStrings (bind: ''
438 oxwm.key.bind({ ${lib.concatMapStringsSep ", " (m: ''"${m}"'') bind.mods} }, "${bind.key}", ${bind.action})
439 '')
440 cfg.binds}
441 ${lib.concatMapStrings (chord: ''
442 oxwm.key.chord({
443 ${lib.concatMapStringsSep ",\n " (
444 note: ''{ { ${lib.concatMapStringsSep ", " (m: ''"${m}"'') note.mods} }, "${note.key}" }''
445 )
446 chord.notes}
447 }, ${chord.action})
448 '')
449 cfg.chords}
450 ${lib.concatMapStrings (rule: ''
451 ${ruleToLua rule}
452 '')
453 cfg.rules}
454 ${cfg.extraConfig}
455 '';
456 };
457 }