| 1 | { self }: { config, lib, pkgs, ... }: |
| 2 | let |
| 3 | inherit (lib) mkEnableOption mkOption mkIf types getExe; |
| 4 | cfg = config.programs.oxwm; |
| 5 | |
| 6 | # Converts a nix submodule into a single oxwm bar block |
| 7 | blockToLua = block: let |
| 8 | common = '' |
| 9 | interval = ${toString block.interval}, |
| 10 | color = "#${block.color}", |
| 11 | underline = ${lib.boolToString block.underline},''; |
| 12 | in "oxwm.bar.block.${block.kind}({\n" + |
| 13 | (if block.kind == "static" then '' |
| 14 | text = "${block.text}", |
| 15 | ${common} |
| 16 | '' else if block.kind == "shell" then '' |
| 17 | format = "${block.format}", |
| 18 | command = "${block.command}", |
| 19 | ${common} |
| 20 | '' else if block.kind == "datetime" then '' |
| 21 | format = "${block.format}", |
| 22 | date_format = "${block.date_format}", |
| 23 | ${common} |
| 24 | '' else if block.kind == "battery" then '' |
| 25 | format = "${block.format}", |
| 26 | charging = "${block.charging}", |
| 27 | discharging = "${block.discharging}", |
| 28 | full = "${block.full}", |
| 29 | ${common} |
| 30 | '' else '' |
| 31 | format = "${block.format}", |
| 32 | ${common} |
| 33 | '') + "})"; |
| 34 | |
| 35 | ruleToLua = rule: let |
| 36 | fields = lib.concatStringsSep ", " ( |
| 37 | lib.optional (rule.match.class != null) ''class = "${rule.match.class}"'' ++ |
| 38 | lib.optional (rule.match.instance != null) ''instance = "${rule.match.instance}"'' ++ |
| 39 | lib.optional (rule.match.title != null) ''title = "${rule.match.title}"'' ++ |
| 40 | lib.optional (rule.match.role != null) ''role = "${rule.match.role}"'' ++ |
| 41 | lib.optional (rule.floating != null) ''floating = ${lib.boolToString rule.floating}'' ++ |
| 42 | lib.optional (rule.tag != null) ''tag = ${toString rule.tag}'' ++ |
| 43 | lib.optional (rule.fullscreen != null) ''fullscreen = ${lib.boolToString rule.fullscreen}'' |
| 44 | ); |
| 45 | in "oxwm.rule.add({ ${fields} })"; |
| 46 | in |
| 47 | { |
| 48 | options.programs.oxwm = { |
| 49 | enable = mkEnableOption "oxwm window manager"; |
| 50 | package = mkOption { |
| 51 | type = types.package; |
| 52 | default = self.packages.${pkgs.stdenv.hostPlatform.system}.default; |
| 53 | description = "The oxwm package to use"; |
| 54 | }; |
| 55 | extraSessionCommands = mkOption { |
| 56 | type = types.lines; |
| 57 | default = ""; |
| 58 | description = "Shell commands executed just before oxwm is started"; |
| 59 | }; |
| 60 | terminal = mkOption { type = types.str; default = "alacritty"; }; |
| 61 | modkey = mkOption { type = types.str; default = "Mod4"; }; |
| 62 | tags = mkOption { type = types.listOf types.str; |
| 63 | default = [ "1" "2" "3" "4" "5" "6" "7" "8" "9" ]; |
| 64 | }; |
| 65 | layoutSymbol = { |
| 66 | tiling = mkOption { type = types.str; default = "[T]"; }; |
| 67 | normie = mkOption { type = types.str; default = "[F]"; }; |
| 68 | tabbed = mkOption { type = types.str; default = "[=]"; }; |
| 69 | }; |
| 70 | autostart = mkOption { |
| 71 | type = types.listOf types.str; |
| 72 | default = []; |
| 73 | }; |
| 74 | binds = mkOption { |
| 75 | type = types.listOf (types.submodule { |
| 76 | options = { |
| 77 | mods = mkOption { type = types.listOf types.str; default = [ "${cfg.modkey}" ]; }; |
| 78 | key = mkOption { type = types.str; }; |
| 79 | action = mkOption { type = types.str; }; |
| 80 | }; |
| 81 | }); |
| 82 | default = []; |
| 83 | }; |
| 84 | border = { |
| 85 | width = mkOption { type = types.int; default = 2; }; |
| 86 | focusedColor = mkOption { type = types.str; default = "6dade3"; }; |
| 87 | unfocusedColor = mkOption { type = types.str; default = "bbbbbb"; }; |
| 88 | }; |
| 89 | gaps = { |
| 90 | smart = mkOption { type = types.enum [ "enabled" "disabled" ]; default = "enabled"; }; |
| 91 | inner = mkOption { type = types.listOf types.int; default = [ 5 5 ];}; |
| 92 | outer = mkOption { type = types.listOf types.int; default = [ 5 5 ];}; |
| 93 | }; |
| 94 | bar = { |
| 95 | font = mkOption { type = types.str; default = "monospace 10"; }; |
| 96 | hideVacantTags = mkOption { type = types.bool; default = false; }; |
| 97 | unoccupiedScheme = mkOption { |
| 98 | type = types.listOf types.str; |
| 99 | default = [ "bbbbbb" "1a1b26" "444444" ]; |
| 100 | }; |
| 101 | occupiedScheme = mkOption { |
| 102 | type = types.listOf types.str; |
| 103 | default = [ "0db9d7" "1a1b26" "0db9d7" ]; |
| 104 | }; |
| 105 | selectedScheme = mkOption { |
| 106 | type = types.listOf types.str; |
| 107 | default = [ "0db9d7" "1a1b26" "ad8ee6" ]; |
| 108 | }; |
| 109 | urgentScheme = mkOption { |
| 110 | type = types.listOf types.str; |
| 111 | default = [ "f7768e" "1a1b26" "f7768e" ]; |
| 112 | }; |
| 113 | blocks = mkOption { type = types.listOf (types.submodule { |
| 114 | options = { |
| 115 | kind = mkOption { |
| 116 | type = types.enum [ "ram" "static" "shell" "datetime" "battery" ]; |
| 117 | default = "static"; |
| 118 | }; |
| 119 | interval = mkOption { type = types.int; default = 5; }; |
| 120 | color = mkOption { type = types.str; default = ""; }; |
| 121 | underline = mkOption { type = types.bool; default = true; }; |
| 122 | text = mkOption { type = types.str; default = "|"; }; |
| 123 | format = mkOption { type = types.str; default = "{}"; }; |
| 124 | command = mkOption { type = types.str; default = "uname -r"; }; |
| 125 | date_format = mkOption { type = types.str; default = "%a, %b %d - %-I:%M %P"; }; |
| 126 | charging = mkOption { type = types.str; default = "⚡ Bat: {}%"; }; |
| 127 | discharging = mkOption { type = types.str; default = "- Bat: {}%"; }; |
| 128 | full = mkOption { type = types.str; default = "✓ Bat: {}%"; }; |
| 129 | }; |
| 130 | }); }; |
| 131 | }; |
| 132 | rules = mkOption { type = types.listOf (types.submodule { |
| 133 | options = { |
| 134 | match = { |
| 135 | class = mkOption { type = types.nullOr types.str; default = null; }; |
| 136 | instance = mkOption { type = types.nullOr types.str; default = null; }; |
| 137 | title = mkOption { type = types.nullOr types.str; default = null; }; |
| 138 | role = mkOption { type = types.nullOr types.str; default = null; }; |
| 139 | }; |
| 140 | floating = mkOption { type = types.nullOr types.bool; default = null; }; |
| 141 | tag = mkOption { type = types.nullOr types.int; default = null; }; |
| 142 | fullscreen = mkOption { type = types.nullOr types.bool; default = null; }; |
| 143 | }; |
| 144 | }); }; |
| 145 | extraConfig = mkOption { type = types.lines; default = ""; }; |
| 146 | }; |
| 147 | |
| 148 | config = mkIf cfg.enable { |
| 149 | home.packages = [ cfg.package ]; |
| 150 | |
| 151 | xsession.windowManager.command = '' |
| 152 | ${cfg.extraSessionCommands} |
| 153 | export _JAVA_AWT_WM_NONREPARENTING=1 |
| 154 | exec ${getExe cfg.package} |
| 155 | ''; |
| 156 | |
| 157 | xdg.configFile."oxwm/config.lua".text = '' |
| 158 | @meta |
| 159 | @module 'oxwm' |
| 160 | |
| 161 | oxwm.set_terminal("${cfg.terminal}") |
| 162 | oxwm.set_modkey("${cfg.modkey}") |
| 163 | oxwm.set_tags({${lib.concatMapStringsSep ", " (t: ''"${t}"'') cfg.tags}}) |
| 164 | |
| 165 | local blocks = { |
| 166 | ${lib.concatMapStringsSep ",\n" blockToLua cfg.bar.blocks} |
| 167 | }; |
| 168 | oxwm.bar.set_blocks(blocks) |
| 169 | oxwm.bar.set_font("${cfg.bar.font}") |
| 170 | oxwm.bar.set_scheme_normal(${lib.concatMapStringsSep ", " (c: ''"#${c}"'') cfg.bar.unoccupiedScheme}) |
| 171 | oxwm.bar.set_scheme_occupied(${lib.concatMapStringsSep ", " (c: ''"#${c}"'') cfg.bar.occupiedScheme}) |
| 172 | oxwm.bar.set_scheme_selected(${lib.concatMapStringsSep ", " (c: ''"#${c}"'') cfg.bar.selectedScheme}) |
| 173 | oxwm.bar.set_scheme_urgent(${lib.concatMapStringsSep ", " (c: ''"#${c}"'') cfg.bar.urgentScheme}) |
| 174 | oxwm.bar.set_hide_vacant_tags(${lib.boolToString cfg.bar.hideVacantTags}) |
| 175 | |
| 176 | oxwm.border.set_width(${toString cfg.border.width}) |
| 177 | oxwm.border.set_focused_color("#${cfg.border.focusedColor}") |
| 178 | oxwm.border.set_unfocused_color("#${cfg.border.unfocusedColor}") |
| 179 | |
| 180 | oxwm.gaps.set_smart(${cfg.gaps.smart}) |
| 181 | oxwm.gaps.set_inner(${lib.concatMapStringsSep ", " toString cfg.gaps.inner}) |
| 182 | oxwm.gaps.set_outer(${lib.concatMapStringsSep ", " toString cfg.gaps.outer}) |
| 183 | |
| 184 | oxwm.set_layout_symbol("tiling", "${cfg.layoutSymbol.tiling}") |
| 185 | oxwm.set_layout_symbol("normie", "${cfg.layoutSymbol.normie}") |
| 186 | oxwm.set_layout_symbol("tabbed", "${cfg.layoutSymbol.tabbed}") |
| 187 | |
| 188 | ${lib.concatMapStrings (cmd: '' |
| 189 | oxwm.autostart("${cmd}") |
| 190 | '') cfg.autostart} |
| 191 | ${lib.concatMapStrings (bind: '' |
| 192 | oxwm.key.bind({ ${lib.concatMapStringsSep ", " (m: ''"${m}"'') bind.mods} }, "${bind.key}", ${bind.action}) |
| 193 | '') cfg.binds} |
| 194 | ${cfg.extraConfig} |
| 195 | ${lib.concatMapStrings (rule: '' |
| 196 | ${ruleToLua rule} |
| 197 | '') cfg.rules} |
| 198 | ''; |
| 199 | }; |
| 200 | } |