aboutsummaryrefslogtreecommitdiff
path: root/share/home/niri.nix
blob: eb5822d8eabb05bc305122385d78fec3641d3e26 (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
{
  pkgs,
  config,
  inputs,
  lib,
  ...
}:
let
  cfg = config.programs.niri;
  tomlFormat = pkgs.formats.toml { };
  inherit (lib) mkIf;
in
{
  imports = [
    inputs.niri-flake.homeModules.niri
  ];
  programs.waybar.enable = true;
  programs.tofi.enable = true;
  programs.kitty.enable = true;
  home.packages = [
    pkgs.wpaperd # for wpaperctl
  ];

  programs.niri.settings = {
    input = {
      keyboard.xkb = {
        layout = "us,hr";
        options = "grp:win_space_toggle";
      };
      touchpad = {
        enable = true;
        tap = true;
        natural-scroll = true;
      };
      mouse = {
        enable = true;
        accel-profile = "flat";
      };
    };

    outputs."eDP-1" = {
      enable = true;
      mode = {
        width = 1920;
        height = 1080;
      };
      scale = 2;
      # transform = "normal";
      # position = {
      #   # From the default config, no idea why
      #   x = 1280;
      #   y = 0;
      # };
    };

    layout = {
      gaps = 16;
      center-focused-column = "never";
      # You can customize the widths that "switch-preset-column-width" (Mod+R) toggles between.
      preset-column-widths = [
        { proportion = 1. / 3.; }
        { proportion = 1. / 2.; }
        { proportion = 2. / 3.; }
      ];
      default-column-width.proportion = 1. / 2.;
      focus-ring = {
        width = 4;
        active.color = "#7fc8ff";
        inactive.color = "#505050";
      };
    };

    spawn-at-startup = [
      { command = [ "${pkgs.xwayland-satellite}/bin/xwayland-satellite" ]; }
      { command = [ "${pkgs.mako}/bin/mako" ]; }
      { command = [ "${pkgs.wpaperd}/bin/wpaperd" ]; }
    ];

    environment = {
      QT_QPA_PLATFORM = "wayland";
      DISPLAY = ":0"; # for X11 to recognize xwayland-satellite correctly
    };

    screenshot-path = null; # clipboard only

    window-rules = [
      # Open the Firefox picture-in-picture player as floating by default.
      {
        matches = [ { title = "^Picture-in-Picture$"; } ];
        open-floating = true;
      }

      # Work around WezTerm's initial configure bug by setting an empty default-column-width.
      {
        matches = [ { app-id = ''^org\.wezfurlong\.wezterm$''; } ];
        default-column-width = null;
      }

      {
        matches = [
          { app-id = ''^org\.keepassxc\.KeePassXC$''; }
          { app-id = ''^org\.gnome\.World\.Secrets$''; }
          { app-id = ''^Bitwarden$''; }
        ];
        block-out-from = "screen-capture";
      }
    ];

    binds = with config.lib.niri.actions; {
      # Shows a list of important hotkeys
      "Mod+Shift+Slash".action = show-hotkey-overlay;

      "Mod+Shift+Return".action = spawn "kitty";
      "Mod+P".action = spawn "tofi-drun";
      "Mod+Shift+P".action = spawn "tofi-run";

      # Audio stuff
      "XF86AudioRaiseVolume" = {
        allow-when-locked = true;
        action = spawn "wpctl" "set-volume" "@DEFAULT_AUDIO_SINK@" "0.1+";
      };
      "XF86AudioLowerVolume" = {
        allow-when-locked = true;
        action = spawn "wpctl" "set-volume" "@DEFAULT_AUDIO_SINK@" "0.1-";
      };
      "XF86AudioMute" = {
        allow-when-locked = true;
        action = spawn "wpctl" "set-mute" "@DEFAULT_AUDIO_SINK@" "toggle";
      };
      "XF86AudioMicMute" = {
        allow-when-locked = true;
        action = spawn "wpctl" "set-mute" "@DEFAULT_AUDIO_SOURCE@" "toggle";
      };

      # general window management
      "Mod+Shift+C".action = close-window;
      "Mod+Left".action = focus-column-left;
      "Mod+Down".action = focus-window-down;
      "Mod+Up".action = focus-window-up;
      "Mod+Right".action = focus-column-right;
      "Mod+H".action = focus-column-left;
      "Mod+J".action = focus-window-down;
      "Mod+K".action = focus-window-up;
      "Mod+L".action = focus-column-right;

      "Mod+Shift+Left".action = move-column-left;
      "Mod+Shift+Down".action = move-window-down;
      "Mod+Shift+Up".action = move-window-up;
      "Mod+Shift+Right".action = move-column-right;
      "Mod+Shift+H".action = move-column-left;
      "Mod+Shift+J".action = move-window-down;
      "Mod+Shift+K".action = move-window-up;
      "Mod+Shift+L".action = move-column-right;

      "Mod+Home".action = focus-column-first;
      "Mod+End".action = focus-column-last;
      "Mod+Shift+Home".action = move-column-to-first;
      "Mod+Shift+End".action = move-column-to-last;

      "Mod+Page_Down".action = focus-workspace-down;
      "Mod+Page_Up".action = focus-workspace-up;
      "Mod+U".action = focus-workspace-down;
      "Mod+I".action = focus-workspace-up;
      "Mod+Shift+U".action = move-column-to-workspace-down;
      "Mod+Shift+I".action = move-column-to-workspace-up;

      "Mod+Shift+Page_Down".action = move-workspace-down;
      "Mod+Shift+Page_Up".action = move-workspace-up;

      "Mod+WheelScrollDown".action = focus-workspace-down;
      "Mod+WheelScrollUp".action = focus-workspace-up;
      "Mod+Ctrl+WheelScrollDown".action = move-column-to-workspace-down;
      "Mod+Ctrl+WheelScrollUp".action = move-column-to-workspace-up;

      "Mod+WheelScrollRight".action = focus-column-right;
      "Mod+WheelScrollLeft".action = focus-column-left;
      "Mod+Ctrl+WheelScrollRight".action = move-column-right;
      "Mod+Ctrl+WheelScrollLeft".action = move-column-left;

      "Mod+Shift+WheelScrollDown".action = focus-column-right;
      "Mod+Shift+WheelScrollUp".action = focus-column-left;
      "Mod+Ctrl+Shift+WheelScrollDown".action = move-column-right;
      "Mod+Ctrl+Shift+WheelScrollUp".action = move-column-left;

      "Mod+1".action = focus-workspace 1;
      "Mod+2".action = focus-workspace 2;
      "Mod+3".action = focus-workspace 3;
      "Mod+4".action = focus-workspace 4;
      "Mod+5".action = focus-workspace 5;
      "Mod+6".action = focus-workspace 6;
      "Mod+7".action = focus-workspace 7;
      "Mod+8".action = focus-workspace 8;
      "Mod+9".action = focus-workspace 9;
      "Mod+Shift+1".action.move-column-to-workspace = 1;
      "Mod+Shift+2".action.move-column-to-workspace = 2;
      "Mod+Shift+3".action.move-column-to-workspace = 3;
      "Mod+Shift+4".action.move-column-to-workspace = 4;
      "Mod+Shift+5".action.move-column-to-workspace = 5;
      "Mod+Shift+6".action.move-column-to-workspace = 6;
      "Mod+Shift+7".action.move-column-to-workspace = 7;
      "Mod+Shift+8".action.move-column-to-workspace = 8;
      "Mod+Shift+9".action.move-column-to-workspace = 9;

      "Mod+BracketLeft".action = consume-or-expel-window-left;
      "Mod+BracketRight".action = consume-or-expel-window-right;

      # Consume one window from the right to the bottom of the focused column.
      "Mod+Comma".action = consume-window-into-column;
      # Expel the bottom window from the focused column to the right.
      "Mod+Period".action = expel-window-from-column;

      "Mod+R".action = switch-preset-column-width;
      "Mod+Shift+R".action = switch-preset-window-height;
      "Mod+Ctrl+R".action = reset-window-height;
      "Mod+F".action = maximize-column;
      "Mod+Shift+F".action = fullscreen-window;

      # Expand the focused column to space not taken up by other fully visible columns.
      # Makes the column "fill the rest of the space".
      "Mod+Ctrl+F".action = expand-column-to-available-width;

      "Mod+C".action = center-column;

      "Mod+Minus".action = set-column-width "-10%";
      "Mod+Equal".action = set-column-width "+10%";
      "Mod+Shift+Minus".action = set-window-height "-10%";
      "Mod+Shift+Equal".action = set-window-height "+10%";

      "Mod+V".action = toggle-window-floating;
      "Mod+Shift+V".action = switch-focus-between-floating-and-tiling;

      "Mod+W".action = toggle-column-tabbed-display;

      "Print".action = screenshot;
      "Alt+Print".action = screenshot-window;

      "Mod+Escape" = {
        allow-inhibiting = false;
        action = toggle-keyboard-shortcuts-inhibit;
      };

      "Mod+Shift+E".action = quit;
      "Ctrl+Alt+Delete".action = quit;
    };
  };

  # wpaperd manual config
  #
  # Can't use the HM module since it doesn't expose the service target as a
  # config option. If I enabled it, wpaperd would be started for every DE, which
  # I don't want.
  xdg.configFile."wpaperd/wallpaper.toml" = {
    source = tomlFormat.generate "wpaperd-wallpaper" {
      default = {
        path = "${config.xdg.userDirs.pictures}/Wallpapers";
        duration = "10m";
        sorting = "random";
      };
    };
  };
}