about summary refs log tree commit diff stats
path: root/modules/by-name/i3/i3bar-river/module.nix
blob: b32ec6a5c2f25a07b3c76fbc40fca69b05100fbd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
{
  config,
  lib,
  pkgs,
  ...
}: let
  cfg = config.soispha.programs.i3bar-river;

  toColor = color:
    if builtins.isString color
    then lib.trivial.fromHexString color
    else color;

  substractColor = color_a: color_b: let
    saturatingSub = a: b:
      if a < b
      then 0
      else a - b;
  in {
    red = saturatingSub color_a.red color_b.red;
    green = saturatingSub color_a.green color_b.green;
    blue = saturatingSub color_a.blue color_b.blue;
    alpha = saturatingSub color_a.alpha color_b.alpha;
    inherit (color_a) __toString;
  };

  colorOption = red: green: blue: alpha:
    lib.mkOption {
      type = lib.types.submodule {
        options = {
          red = lib.mkOption {
            type = lib.types.ints.between 0 255;
            description = "The amount of red in this color";
            default = toColor red;
          };
          green = lib.mkOption {
            type = lib.types.ints.between 0 255;
            description = "The amount of green in this color";
            default = toColor green;
          };
          blue = lib.mkOption {
            type = lib.types.ints.between 0 255;
            description = "The amount of blue in this color";
            default = toColor blue;
          };
          alpha = lib.mkOption {
            type = lib.types.ints.between 0 255;
            description = "The amount of alpha in this color";
            default = toColor alpha;
          };

          __toString = lib.mkOption {
            internal = true;

            default = self: let
              tH = num: let
                converted = lib.trivial.toHexString num;
              in
                if builtins.stringLength converted == 1
                then "0${converted}"
                else assert (builtins.stringLength converted) == 2; converted;

              output = "#${tH self.red}${tH self.green}${tH self.blue}${tH self.alpha}";
            in
              output;

            description = "Convert this type to a string before use";
          };
        };
      };

      default = {
        red = toColor red;
        green = toColor green;
        blue = toColor blue;
        alpha = toColor alpha;
      };

      description = "The specific color to use for this name.";
    };
in {
  options.soispha.programs.i3bar-river = {
    enable = lib.mkEnableOption "i3bar-river";

    package = lib.mkPackageOption pkgs "i3bar-river-patched" {};

    colors = {
      none = colorOption 00 00 00 00;

      white = colorOption "ff" "ff" "ff" "ff";

      blue = colorOption "99" "d1" "db" "ff";
      green = colorOption "a6" "e3" "a1" "dd";
      lavendar = colorOption "b4" "be" "fe" "dd";
      mauve = colorOption "cb" "a6" "f7" "dd";
      normal = colorOption "c6" "ce" "ef" "ff";
      peach = colorOption "fa" "b3" "87" "dd";
      sapphire = colorOption "74" "c7" "ec" "dd";
      teal = colorOption "94" "e2" "d5" "dd";

      light_gray = colorOption "58" "5b" "70" "ff";
      gray = colorOption "45" "47" "5a" "ff";
      dark_gray = colorOption "30" "34" "46" "ff";
      bright_red = colorOption "e7" "82" "84" "ff";

      vivid_burgundy = colorOption "9f" "1d" "35" "ff";

      unfocused_offset = colorOption "33" "33" "33" "00";
    };
  };

  config = lib.mkIf cfg.enable {
    soispha.programs.river.init.backgroundStart = [cfg.package];

    home-manager.users.soispha = {
      programs.i3bar-river = {
        enable = true;
        inherit (cfg) package;

        settings = {
          theme = {
            palette = {
              # Colors
              background = toString cfg.colors.none;
              color = toString cfg.colors.white; # Only used, if blocks do not specify one
              separator = toString cfg.colors.vivid_burgundy;

              # Tag is set (but not focused or urgent)
              tag_fg = toString cfg.colors.white;
              tag_bg = toString cfg.colors.light_gray;

              tag_urgent_fg = toString cfg.colors.white;
              tag_urgent_bg = toString cfg.colors.bright_red;

              tag_focused_fg = toString cfg.colors.white;
              tag_focused_bg = toString cfg.colors.teal;

              tag_inactive_fg = toString cfg.colors.white;
              tag_inactive_bg = toString cfg.colors.none;

              # Shop options
              blend = true; # whether tags/blocks colors should blend with bar's background
              hide_inactive_tags = false;
              show_layout_name = false;
              show_mode = true;
              show_tags = true;
            };

            unfocused_palette = {
              hide_inactive_tags = true;

              color = toString (substractColor cfg.colors.white cfg.colors.unfocused_offset);
              separator = toString (substractColor cfg.colors.vivid_burgundy cfg.colors.unfocused_offset);

              tag_fg = toString (substractColor cfg.colors.white cfg.colors.unfocused_offset);
              tag_bg = toString (substractColor cfg.colors.light_gray cfg.colors.unfocused_offset);

              tag_urgent_fg = toString (substractColor cfg.colors.white cfg.colors.unfocused_offset);
              tag_urgent_bg = toString (substractColor cfg.colors.bright_red cfg.colors.unfocused_offset);

              tag_focused_fg = toString (substractColor cfg.colors.white cfg.colors.unfocused_offset);
              tag_focused_bg = toString cfg.colors.vivid_burgundy;

              tag_inactive_fg = toString (substractColor cfg.colors.white cfg.colors.unfocused_offset);
              tag_inactive_bg = toString (substractColor cfg.colors.none cfg.colors.unfocused_offset);
            };
          };

          # The font and various sizes
          font = "SauceCodePro Nerd Font Mono:pixelsize=26";
          height = 24;
          margin_top = 10;
          margin_bottom = 0;
          margin_left = 0;
          margin_right = 0;
          separator_width = 0;
          tags_r = 10.0;
          tags_padding = 10.0;
          tags_margin = 5.0;
          blocks_r = 6.0;
          blocks_overlap = 0.0;

          # Misc
          position = "top"; # either "top" or "bottom"
          layer = "overlay"; # one of "top", "overlay", "bottom" or "background"
          invert_touchpad_scrolling = true;
          start_hidden = false; # whether the bar is initially in the 'hidden' state

          # WM-specific options
          wm.river = {
            max_tag = 9; # Show only the first nine tags
          };
        };
      };
    };
  };
}