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