summary refs log tree commit diff
path: root/mixins/sway.nix
blob: f1cf98de65944ef033f9b082407cdaa90673b643 (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
{
  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"
      foot -W40x40 --app-id "$app_id" -- sh -c "$chooser" &
      cat >"$in_pipe"
      cat <"$out_pipe"
    '';
  sel =
    pkgs.writeShellScript "sel"
    ''
      #!/bin/sh
      swaymsg -t get_tree | \
      ${pkgs.jq}/bin/jq -r '.. | select(.pid? and .visible?) | .rect | "\(.x),\(.y) \(.width)x\(.height)"' | \
      ${pkgs.slurp}/bin/slurp
    '';
in {
  # config.home-manager.users.tzlil.xdg.configFile."i3status-rust/config.toml".source = ./i3status-rs.toml;
  config.security.pam.services.swaylock = {};
  config.home-manager.users.tzlil.programs.mako.enable = true;
  config.home-manager.users.tzlil.home.packages = with pkgs; [
    grim
    slurp
    wf-recorder
    font-awesome_6
  ];
  config.home-manager.users.tzlil.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"
    ];
  };
  config.home-manager.users.tzlil.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}+space" = "exec ${pkgs.dmenu}/bin/dmenu_path | ${menuscript} | xargs swaymsg exec --";
        "${modifier}+Shift+c" = "reload";
        "${modifier}+Shift+q" = "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";
      };
      input = {
        "type:keyboard" = {
          xkb_layout = "us";
          xkb_variant = "colemak_dh";
          xkb_options = "altwin:swap_lalt_lwin,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

      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 pactl set-sink-mute @DEFAULT_SINK@ toggle
      bindsym --locked XF86AudioLowerVolume exec pactl set-sink-volume @DEFAULT_SINK@ -5%
      bindsym --locked XF86AudioRaiseVolume exec pactl set-sink-volume @DEFAULT_SINK@ +5%
      bindsym --locked XF86AudioMicMute exec pactl set-source-mute @DEFAULT_SOURCE@ toggle

      bindsym --locked XF86AudioNext exec playerctl next
      bindsym --locked XF86AudioPlay exec playerctl play-pause
      bindsym --locked XF86AudioPrev exec playerctl previous
      bindsym --locked XF86AudioStop exec 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 light -A 5
      bindsym XF86MonBrightnessDown exec light -U 5

      bindsym Print exec ${pkgs.grim}/bin/grim - | tee $(xdg-user-dir PICTURES)/$(date +'%s_grim.png') | wl-copy
      bindsym Shift+Print exec ${pkgs.grim}/bin/grim -g "$(${sel})" - | tee $(xdg-user-dir PICTURES)/$(date +'%s_grim.png') | wl-copy
      bindsym Ctrl+Print exec ${pkgs.grim}/bin/grim -g "$(swaymsg -t get_tree | jq -j '.. | select(.type?) | select(.focused).rect | "\(.x),\(.y) \(.width)x\(.height)"')" - |tee $(xdg-user-dir PICTURES)/$(date +'%s_grim.png') | wl-copy

      bindsym $mod+l exec ${pkgs.swaylock}/bin/swaylock -c 070D0D

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

      include /etc/sway/config.d/*
    '';
  };
}