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