summary refs log tree commit diff
path: root/mixins/sway.nix
blob: 42604b317436bcede1c323c49f15ecedd074a66b (plain)
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
{
  config,
  pkgs,
  lib,
  ...
}: let
  menuscript =
    pkgs.writeShellScript "menu"
    ''
      #!/bin/sh -eu

      in_pipe="$XDG_RUNTIME_DIR/menu-in.$$.pipe"
      out_pipe="$XDG_RUNTIME_DIR/menu-out.$$.pipe"

      mkfifo "$in_pipe" "$out_pipe"
      trap "rm -f $in_pipe $out_pipe" EXIT

      app_id=menu
      chooser="${pkgs.fzf}/bin/fzf <$in_pipe >$out_pipe"
      ${pkgs.foot}/bin/foot -W40x40 --app-id "$app_id" -- sh -c "$chooser" &
      cat >"$in_pipe"
      cat <"$out_pipe"
    '';
in {
  config = {
    security.pam.services.swaylock = {};
    home-manager.users.tzlil = {
      xdg.configFile."i3status-rust/config.toml".text = ''
        [icons]
        icons = "awesome6"

        [theme]
        theme = "semi-native"
        [theme.overrides]
        separator = ""

        [[block]]
        block = "music"
        [[block.click]]
        action = "play_pause"
        button = "left"

        [[block]]
        block = "net"
        format = " $icon {$ssid |}$ip "
        [[block]]
        block = "memory"
        format = " $icon $mem_total_used_percents.eng(w:2) "

        [[block]]
        block = "cpu"

        [[block]]
        block = "load"

        [[block]]
        block = "battery"
        interval = 10
        #format = "$percentage $time"

        [[block]]
        block = "sound"
        headphones_indicator=true
        [[block.click]]
        cmd = "${pkgs.pavucontrol}/bin/pavucontrol"
        button = "left"

        [[block]]
        block = "time"
        interval = 60
        format = "$icon $timestamp.datetime(f:'%a %Y-%m-%d %H:%M')"
      '';
      services.mako.enable = true;
      home.packages = with pkgs; [
        wf-recorder
        font-awesome_6
        waypipe
        foot
        alsa-utils
      ];

      services.swayidle = let
        pgrep = "${pkgs.procps}/bin/pgrep";
        dpms_check = s:
          pkgs.writeShellScript "dpms_check_${s}" ''
            set -x
            if ${pgrep} swaylock; then ${pkgs.sway}/bin/swaymsg 'output * dpms ${s}'; fi
          '';
        dpms_set = s:
          pkgs.writeShellScript "dpms_set_${s}" ''
            set -x
            "${pkgs.sway}/bin/swaymsg" 'output * dpms ${s}'
          '';
        fadelock = pkgs.writeShellScript "fadelock.sh" ''
          set -x
          exec "${pkgs.swaylock}/bin/swaylock"
        '';
      in {
        enable = false;
        systemdTarget = "graphical-session.target";
        timeouts = [
          # auto-lock after 30 seconds
          {
            timeout = 30;
            command = fadelock.outPath;
          }
        ];
        events = [
          {
            event = "before-sleep";
            command = fadelock.outPath;
          }
        ];
        extraArgs = [
          "idlehint 30"
        ];
      };

      wayland.windowManager.sway = rec {
        enable = true;
        wrapperFeatures.gtk = true;
        config = rec {
          fonts = {
            names = ["Iosevka"];
            style = "Regular";
            size = 11.0;
          };
          output = {
            "DP-1" = {
              resolution = "1920x1080@166Hz";
            };
          };
          bars = [
            {
              fonts = {
                names = ["Iosevka" "FontAwesome"];
                style = "Regular";
                size = 11.0;
              };
              position = "top";
              statusCommand = "${pkgs.i3status-rust}/bin/i3status-rs";
              colors = {
                statusline = "#ffffff";
                background = "#323232";
                inactiveWorkspace = {
                  background = "#323232";
                  border = "#323232";
                  text = "#5c5c5c";
                };
              };
            }
          ];

          modifier = "Mod4";
          left = "h";
          down = "n";
          up = "e";
          right = "i";
          keybindings = {
            "${modifier}+Return" = "exec $term";
            "${modifier}+q" = "kill";
            "${modifier}+d" = "exec ${pkgs.dmenu}/bin/dmenu_path | ${menuscript} | xargs swaymsg exec --";
            "${modifier}+Shift+c" = "reload";
            "${modifier}+Shift+q" = "exec swaynag -t warning -m 'you sure?' -B 'yes' 'swaymsg exit'";
            "${modifier}+Shift+p" = "exec systemctl poweroff";
            "${modifier}+Shift+s" = "exec systemctl suspend";
            "${modifier}+${left}" = "focus left";
            "${modifier}+${down}" = "focus down";
            "${modifier}+${up}" = "focus up";
            "${modifier}+${right}" = "focus right";
            "${modifier}+Left" = "focus left";
            "${modifier}+Down" = "focus down";
            "${modifier}+Up" = "focus up";
            "${modifier}+Right" = "focus right";
            "${modifier}+Shift+${left}" = "move left";
            "${modifier}+Shift+${down}" = "move down";
            "${modifier}+Shift+${up}" = "move up";
            "${modifier}+Shift+${right}" = "move right";
            "${modifier}+Shift+Left" = "move left";
            "${modifier}+Shift+Down" = "move down";
            "${modifier}+Shift+Up" = "move up";
            "${modifier}+Shift+Right" = "move right";
            "${modifier}+1" = "workspace number 1";
            "${modifier}+2" = "workspace number 2";
            "${modifier}+3" = "workspace number 3";
            "${modifier}+4" = "workspace number 4";
            "${modifier}+5" = "workspace number 5";
            "${modifier}+6" = "workspace number 6";
            "${modifier}+7" = "workspace number 7";
            "${modifier}+8" = "workspace number 8";
            "${modifier}+9" = "workspace number 9";
            "${modifier}+0" = "workspace number 10";
            "${modifier}+Tab" = "workspace back_and_forth";
            "${modifier}+Shift+1" = "move container to workspace number 1";
            "${modifier}+Shift+2" = "move container to workspace number 2";
            "${modifier}+Shift+3" = "move container to workspace number 3";
            "${modifier}+Shift+4" = "move container to workspace number 4";
            "${modifier}+Shift+5" = "move container to workspace number 5";
            "${modifier}+Shift+6" = "move container to workspace number 6";
            "${modifier}+Shift+7" = "move container to workspace number 7";
            "${modifier}+Shift+8" = "move container to workspace number 8";
            "${modifier}+Shift+9" = "move container to workspace number 9";
            "${modifier}+Shift+0" = "move container to workspace number 10";
            "${modifier}+b" = "splith";
            "${modifier}+v" = "splitv";
            "${modifier}+s" = "layout stacking";
            "${modifier}+w" = "layout tabbed";
            "${modifier}+k" = "layout toggle split";
            "${modifier}+f" = "fullscreen";
            "${modifier}+Shift+space" = "floating toggle";
            "${modifier}+t" = "focus mode_toggle";
            "${modifier}+a" = "focus parent";
            "${modifier}+shift+a" = "focus child";
            "${modifier}+Shift+minus" = "move scratchpad";
            "${modifier}+minus" = "scratchpad show";
            "${modifier}+m" = "mode notifications";

            "${modifier}+l" = "exec ${pkgs.swaylock}/bin/swaylock -c 070D0D";
            "Print" = "exec ${pkgs.sway-contrib.grimshot}/bin/grimshot copy area";
            "Shift+Print" = "exec ${pkgs.sway-contrib.grimshot}/bin/grimshot copy active";
            "Ctrl+Print" = "exec ${pkgs.sway-contrib.grimshot}/bin/grimshot copy output";
          };
          input = {
            "type:keyboard" = {
              xkb_layout = "us";
              # xkb_variant = "colemak_dh";
              xkb_options = "caps:backspace";
            };
            "type:touchpad" = {
              tap = "enabled";
            };
          };
        };
        extraConfig = ''
          exec dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=sway
          # exec ${pkgs.swayidle}/bin/swayidle -w \
          # 	timeout 300 '${pkgs.swaylock}/bin/swaylock -f -c 000000' \
          # 	timeout 600 'swaymsg "output * dpms off"' \
          # 	resume 'swaymsg "output * dpms on"' \
          # 	before-sleep '${pkgs.swaylock}/bin/swaylock -f -c 000000'
          # exec ${pkgs.polkit_gnome}/polkit-gnome/polkit-gnome-authentication-agent-1

          #set $mod Alt
          set $mod Mod4
          set $left h
          set $down n
          set $up e
          set $right i
          set $term ${pkgs.foot}/bin/foot

          default_border pixel
          hide_edge_borders smart
          smart_borders on

          # if want to use in the future use fetchurl
          # output * bg ~/tmp/graveyard.png fill



          floating_modifier $mod normal
          mode notifications {
            bindsym Escape mode default
            bindsym Return exec ${pkgs.mako}/bin/makoctl invoke; exec ${pkgs.mako}/bin/makoctl dismiss; mode default
            bindsym d exec ${pkgs.mako}/bin/makoctl dismiss; mode default
            bindsym Shift+d exec ${pkgs.mako}/bin/makoctl dismiss -a; mode default
          }


          font Iosevka 10

          bindsym $mod+p exec passmenu $menu_args
          bindsym --locked XF86AudioMute exec ${pkgs.pulseaudio}/bin/playerctl set-sink-mute @DEFAULT_SINK@ toggle
          bindsym --locked XF86AudioLowerVolume exec ${pkgs.pulseaudio}/bin/playerctl set-sink-volume @DEFAULT_SINK@ -5%
          bindsym --locked XF86AudioRaiseVolume exec ${pkgs.pulseaudio}/bin/playerctl set-sink-volume @DEFAULT_SINK@ +5%
          bindsym --locked XF86AudioMicMute exec ${pkgs.pulseaudio}/bin/playerctl set-source-mute @DEFAULT_SOURCE@ toggle

          bindsym --locked XF86AudioNext exec ${pkgs.playerctl}/bin/playerctl next
          bindsym --locked XF86AudioPlay exec ${pkgs.playerctl}/bin/playerctl play-pause
          bindsym --locked XF86AudioPrev exec ${pkgs.playerctl}/bin/playerctl previous
          bindsym --locked XF86AudioStop exec ${pkgs.playerctl}/bin/playerctl stop

          for_window [app_id="^menu$"] floating enable, border none
          #for_window [app_id="mpv"] sticky enable
          #for_window [floating] border csd
          #for_window [app_id="firefox" title="Picture-in-Picture"] floating enable, sticky enable, border none
          #for_window [app_id="imv"] floating enable
          #for_window [app_id="imv"] floating enable
          #for_window [class="PacketTracer"] floating enable

          bindsym XF86MonBrightnessUp exec ${pkgs.brightnessctl}/bin/brightnessctl s +5%
          bindsym XF86MonBrightnessDown exec ${pkgs.brightnessctl}/bin/brightnessctl s 5%-

          exec ${pkgs.mako}/bin/mako >/tmp/mako.log 2>&1
          exec_always ${pkgs.kanshi}/bin/kanshi >/tmp/kanshi.log 2>&1


          default_border pixel 2
          gaps outer 0
          gaps inner 0
          include /etc/sway/config.d/*
        '';
      };
    };
  };
}