about summary refs log tree commit diff
path: root/users/aspen/system/home/modules/i3.nix
blob: 58ec3d281460ed19997a4d241b8accf9181bf310 (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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
{ config, lib, pkgs, ... }:
let
  mod = "Mod4";
  solarized = import ../common/solarized.nix;
  # TODO pull this out into lib
  emacsclient = eval: pkgs.writeShellScript "emacsclient-eval" ''
    msg=$(emacsclient --eval '${eval}' 2>&1)
    echo "''${msg:1:-1}"
  '';
  screenlayout = {
    home = pkgs.writeShellScript "screenlayout_home.sh" ''
      xrandr \
        --output eDP-1 --mode 1920x1200 --pos 0x960 --rotate normal \
        --output DP-3 --primary --mode 3840x2160 --pos 1920x0 --rotate normal \
        --output DP-1 --off \
        --output DP-2 --off \
        --output DP-4 --off
    '';
  };

  inherit (builtins) map;
  inherit (lib) mkMerge range;
in
{
  options = with lib; {
    system.machine = {
      wirelessInterface = mkOption {
        description = ''
          Name of the primary wireless interface. Used by i3status, etc.
        '';
        default = "wlp3s0";
        type = types.str;
      };

      i3FontSize = mkOption {
        description = "Font size to use in i3 window decorations etc.";
        default = 6;
        type = types.int;
      };

      battery = mkOption {
        description = "Battery index for this system's battery";
        default = 0;
        type = types.nullOr types.int;
      };
    };
  };

  config =
    let
      fontName = "MesloLGSDZ";
      fontSize = config.system.machine.i3FontSize;
      fonts = {
        names = [ fontName ];
        size = fontSize * 1.0;
      };
      decorationFont = "${fontName} ${toString fontSize}";
    in
    {
      home.packages = with pkgs; [
        rofi
        rofi-pass
        python3Packages.py3status
        i3lock
        i3status
        dconf # for gtk

        # Screenshots
        maim

        # GIFs
        picom
        peek

        (pkgs.writeShellScriptBin "lock" ''
          playerctl pause
          ${pkgs.i3lock}/bin/i3lock -c 222222
        '')
      ];

      xsession.scriptPath = ".xsession";

      xsession.windowManager.i3 = {
        enable = true;
        config = {
          modifier = mod;
          keybindings =
            mkMerge (
              (map
                (n: {
                  "${mod}+${toString n}" =
                    "workspace ${toString n}";
                  "${mod}+Shift+${toString n}" =
                    "move container to workspace ${toString n}";
                })
                (range 0 9))
              ++ [
                (rec {
                  "${mod}+h" = "focus left";
                  "${mod}+j" = "focus down";
                  "${mod}+k" = "focus up";
                  "${mod}+l" = "focus right";
                  "${mod}+semicolon" = "focus parent";

                  "${mod}+Shift+h" = "move left";
                  "${mod}+Shift+j" = "move down";
                  "${mod}+Shift+k" = "move up";
                  "${mod}+Shift+l" = "move right";

                  "${mod}+Shift+x" = "kill";

                  "${mod}+Return" = "exec alacritty";

                  "${mod}+Shift+s" = "split h";
                  "${mod}+Shift+v" = "split v";
                  "${mod}+e" = "layout toggle split";
                  "${mod}+w" = "layout tabbed";
                  "${mod}+s" = "layout stacking";

                  "${mod}+f" = "fullscreen";

                  "${mod}+Shift+r" = "restart";

                  "${mod}+r" = "mode resize";

                  # Marks
                  "${mod}+Shift+m" = ''exec i3-input -F "mark %s" -l 1 -P 'Mark: ' '';
                  "${mod}+m" = ''exec i3-input -F '[con_mark="%s"] focus' -l 1 -P 'Go to: ' '';

                  # Screenshots
                  "${mod}+q" = "exec \"maim | xclip -selection clipboard -t image/png\"";
                  "${mod}+Shift+q" = "exec \"maim -s | xclip -selection clipboard -t image/png\"";
                  "${mod}+Ctrl+q" = "exec ${pkgs.writeShellScript "peek.sh" ''
              ${pkgs.picom}/bin/picom &
              picom_pid=$!
              ${pkgs.peek}/bin/peek || true
              kill -SIGINT $picom_pid
            ''}";

                  # Launching applications
                  "${mod}+u" = "exec ${pkgs.writeShellScript "rofi" ''
              rofi \
                -modi 'combi' \
                -combi-modi "window,drun,ssh,run" \
                -font '${decorationFont}' \
                -show combi
            ''}";

                  # Passwords
                  "${mod}+p" = "exec rofi-pass -font '${decorationFont}'";

                  # Edit current buffer
                  "${mod}+v" = "exec edit-input";

                  # Media
                  "XF86AudioPlay" = "exec playerctl -p spotify play-pause";
                  "XF86AudioNext" = "exec playerctl -p spotify next";
                  "XF86AudioPrev" = "exec playerctl -p spotify previous";
                  "XF86AudioRaiseVolume" = "exec pulseaudio-ctl up";
                  "XF86AudioLowerVolume" = "exec pulseaudio-ctl down";
                  "XF86AudioMute" = "exec pulseaudio-ctl mute";

                  # Lock
                  Pause = "exec lock";

                  # Brightness
                  "XF86MonBrightnessDown" = "exec ${pkgs.brightnessctl}/bin/brightnessctl -q s 5%-";
                  "XF86MonBrightnessUp" = "exec ${pkgs.brightnessctl}/bin/brightnessctl -q s 5%+";

                  # Sleep/hibernate
                  # "${mod}+Escape" = "exec systemctl suspend";
                  # "${mod}+Shift+Escape" = "exec systemctl hibernate";

                  # Scratch buffer
                  "${mod}+minus" = "scratchpad show";
                  "${mod}+Shift+minus" = "move scratchpad";
                  "${mod}+space" = "focus mode_toggle";
                  "${mod}+Shift+space" = "floating toggle";

                  # Screen Layout
                  "${mod}+Shift+t" = "exec xrandr --auto";
                  "${mod}+t" = "exec ${screenlayout.home}";
                  "${mod}+Ctrl+t" = "exec ${pkgs.writeShellScript "fix_term.sh" ''
              xrandr --output eDP-1 --off && ${screenlayout.home}
            ''}";

                  # Notifications
                  "${mod}+Shift+n" = "exec killall -SIGUSR1 .dunst-wrapped";
                  "${mod}+n" = "exec killall -SIGUSR2 .dunst-wrapped";
                  "Control+space" = "exec ${pkgs.dunst}/bin/dunstctl close";
                  "Control+Shift+space" = "exec ${pkgs.dunst}/bin/dunstctl close-all";
                  "Control+grave" = "exec ${pkgs.dunst}/bin/dunstctl history-pop";
                  "Control+Shift+period" = "exec ${pkgs.dunst}/bin/dunstctl action";
                })
              ]
            );

          inherit fonts;

          colors = with solarized; rec {
            focused = {
              border = base01;
              background = base01;
              text = base3;
              indicator = red;
              childBorder = base02;
            };
            focusedInactive = focused // {
              border = base03;
              background = base03;
              # text = base1;
            };
            unfocused = focusedInactive;
            background = base03;
          };

          modes.resize = {
            l = "resize shrink width 5 px or 5 ppt";
            k = "resize grow height 5 px or 5 ppt";
            j = "resize shrink height 5 px or 5 ppt";
            h = "resize grow width 5 px or 5 ppt";

            Return = "mode \"default\"";
          };

          bars = [{
            statusCommand =
              let
                i3status-conf = pkgs.writeText "i3status.conf" ''
                  general {
                      output_format = i3bar
                      colors = true
                      color_good = "#859900"

                      interval = 1
                  }

                  order += "external_script current_task"
                  order += "external_script inbox"
                  order += "spotify"
                  order += "volume_status"
                  order += "wireless ${config.system.machine.wirelessInterface}"
                  # order += "ethernet enp3s0f0"
                  order += "cpu_usage"
                  ${lib.optionalString (!isNull config.system.machine.battery) ''
                    order += "battery ${toString config.system.machine.battery}"
                  ''}
                  # order += "volume master"
                  order += "time"
                  order += "tztime utc"

                  mpd {
                      format = "%artist - %album - %title"
                  }

                  wireless ${config.system.machine.wirelessInterface} {
                      format_up = "W: (%quality - %essid - %bitrate) %ip"
                      format_down = "W: -"
                  }

                  ethernet enp3s0f0 {
                      format_up = "E: %ip"
                      format_down = "E: -"
                  }

                  battery ${toString config.system.machine.battery} {
                      format = "%status %percentage"
                      path = "/sys/class/power_supply/BAT%d/uevent"
                      low_threshold = 10
                  }

                  cpu_usage {
                      format = "CPU: %usage"
                  }

                  load {
                      format = "%5min"
                  }

                  time {
                      format = "    %a %h %d ⌚   %I:%M     "
                  }

                  spotify {
                      color_playing = "#fdf6e3"
                      color_paused = "#93a1a1"
                      format_stopped = ""
                      format_down = ""
                      format = "{title} - {artist} ({album})"
                  }

                  external_script inbox {
                      script_path = '${emacsclient "(aspen/num-inbox-items-message)"}'
                      format = 'Inbox: {output}'
                      cache_timeout = 120
                      color = "#93a1a1"
                  }

                  external_script current_task {
                      script_path = '${emacsclient "(aspen/org-current-clocked-in-task-message)"}'
                      # format = '{output}'
                      cache_timeout = 60
                      color = "#93a1a1"
                  }

                  tztime utc {
                      timezone = "UTC"
                      format = "    %H·%M    "
                  }

                  volume_status {
                      format = "☊ {percentage}"
                      format_muted = "☊ X"
                      # device = "default"
                      # mixer_idx = 0
                  }
                '';
              in
              "py3status -c ${i3status-conf}";
            inherit fonts;
            position = "top";
            colors = with solarized; rec {
              background = base03;
              statusline = base3;
              separator = base1;
              activeWorkspace = {
                border = base03;
                background = base1;
                text = base3;
              };
              focusedWorkspace = activeWorkspace;
              inactiveWorkspace = activeWorkspace // {
                background = base01;
              };
              urgentWorkspace = activeWorkspace // {
                background = red;
              };
            };
          }];

          window.titlebar = true;
        };
      };

      services.dunst = {
        enable = true;
        settings = with solarized; {
          global = {
            font = "MesloLGSDZ ${toString (config.system.machine.i3FontSize * 1.5)}";
            allow_markup = true;
            format = "<b>%s</b>\n%b";
            sort = true;
            alignment = "left";
            geometry = "600x15-40+40";
            idle_threshold = 120;
            separator_color = "frame";
            separator_height = 1;
            word_wrap = true;
            padding = 8;
            horizontal_padding = 8;
            max_icon_size = 45;
          };

          frame = {
            width = 0;
            color = "#aaaaaa";
          };

          urgency_low = {
            background = base03;
            foreground = base3;
            timeout = 5;
          };

          urgency_normal = {
            background = base02;
            foreground = base3;
            timeout = 7;
          };

          urgency_critical = {
            background = red;
            foreground = base3;
            timeout = 0;
          };
        };
      };

      gtk = {
        enable = true;
        iconTheme.name = "Adwaita";
        theme.name = "Adwaita";
      };
    };
}