Kieran's opinionated (and probably slightly dumb) nix config
1# Converted with regex from hyprland config
2# search: ^(\s*)(bind[rwelm]*) = (|\w+), (|\$?\w+), (.+)$ /gm
3# replace: $1$2."$3, $4" = "$5";
4
5{ config, pkgs, lib, ... }: {
6 # <https://wiki.hyprland.org/Configuring/Dispatchers/>
7 wayland.windowManager.hyprland.keyBinds = let
8 MOUSE_LMB = "mouse:272";
9 MOUSE_RMB = "mouse:273";
10 # MOUSE_MMB = "mouse:274";
11 MOUSE_EX1 = "mouse:275";
12 MOUSE_EX2 = "mouse:276";
13
14 # Collections of keybinds common across multiple submaps are collected into
15 # groups, which can be merged together granularly.
16 groups = {
17 # Exit the submap and restore normal binds.
18 submapReset = {
19 bind.", escape" = "submap, reset";
20 bind."CTRL, C" = "submap, reset";
21 };
22
23 # Self-explanatory.
24 launchPrograms = {
25 # Launch the program with a shortcut.
26 bind."SUPER, E" = "exec, dolphin";
27 bind."SUPER, Enter" = "exec, foot";
28 };
29
30 # Kill the active window.
31 killWindow = { bind."SUPER, Q" = "killactive,"; };
32
33 # Either window focus or window movement.
34 moveFocusOrWindow = with groups;
35 lib.mkMerge [ moveFocus moveWindow mouseMoveWindow ];
36
37 # Focus on another window, in the specified direction.
38 moveFocus = {
39 bind."SUPER, left" = "movefocus, l";
40 bind."SUPER, right" = "movefocus, r";
41 bind."SUPER, up" = "movefocus, u";
42 bind."SUPER, down" = "movefocus, d";
43 };
44
45 # Swap the active window with another, in the specified direction.
46 moveWindow = {
47 bind."SUPER_SHIFT, left" = "movewindow, l";
48 bind."SUPER_SHIFT, right" = "movewindow, r";
49 bind."SUPER_SHIFT, up" = "movewindow, u";
50 bind."SUPER_SHIFT, down" = "movewindow, d";
51 };
52
53 # Translate the dragged window by mouse movement.
54 mouseMoveWindow = {
55 bindm."SUPER, ${MOUSE_LMB}" = "movewindow";
56 bindm.", ${MOUSE_EX2}" = "movewindow";
57 };
58
59 # Toggle between vertical and horizontal split for
60 # the active window and an adjacent one.
61 toggleSplit = { bind."SUPER, tab" = "togglesplit,"; };
62
63 # Resize a window with the mouse.
64 mouseResizeWindow = {
65 bindm."SUPER, ${MOUSE_RMB}" = "resizewindow";
66 bindm.", ${MOUSE_EX1}" = "resizewindow";
67 };
68
69 # Switch to the next/previous tab in the active group.
70 changeGroupActive = {
71 bind."ALT, tab" = "changegroupactive, f";
72 bind."ALT, grave" = "changegroupactive, b";
73 };
74
75 # Switch to another workspace.
76 switchWorkspace = with groups;
77 lib.mkMerge [ switchWorkspaceAbsolute switchWorkspaceRelative ];
78
79 # Switch to a workspace by absolute identifier.
80 switchWorkspaceAbsolute = {
81 # Switch to a primary workspace by index.
82 bind."SUPER, 1" = "workspace, 1";
83 bind."SUPER, 2" = "workspace, 2";
84 bind."SUPER, 3" = "workspace, 3";
85 bind."SUPER, 4" = "workspace, 4";
86 bind."SUPER, 5" = "workspace, 5";
87 bind."SUPER, 6" = "workspace, 6";
88 bind."SUPER, 7" = "workspace, 7";
89 bind."SUPER, 8" = "workspace, 8";
90 bind."SUPER, 9" = "workspace, 9";
91 bind."SUPER, 0" = "workspace, 10";
92
93 # Switch to an alternate workspace by index.
94 bind."SUPER_ALT, 1" = "workspace, 11";
95 bind."SUPER_ALT, 2" = "workspace, 12";
96 bind."SUPER_ALT, 3" = "workspace, 13";
97 bind."SUPER_ALT, 4" = "workspace, 14";
98 bind."SUPER_ALT, 5" = "workspace, 15";
99 bind."SUPER_ALT, 6" = "workspace, 16";
100 bind."SUPER_ALT, 7" = "workspace, 17";
101 bind."SUPER_ALT, 8" = "workspace, 18";
102 bind."SUPER_ALT, 9" = "workspace, 19";
103 bind."SUPER_ALT, 0" = "workspace, 20";
104
105 # TODO Bind the special workspace to `XF86Favorites`.
106 # TODO Create a bind for "insert after current workspace".
107 };
108
109 # Switch to workspaces relative to the current one.
110 switchWorkspaceRelative = {
111 # Switch to the next/previous used workspace with page keys.
112 bind."SUPER, page_down" = "workspace, m+1";
113 bind."SUPER, page_up" = "workspace, m-1";
114
115 # Switch to the next/previous used workspace
116 # with the right and left square brackets,
117 # while holding super and shift.
118 bind."SUPER, bracketright " = "workspace, m+1";
119 bind."SUPER, bracketleft" = "workspace, m-1";
120
121 # Switch to the next/previous used workspace with the mouse wheel.
122 bind."SUPER, mouse_up" = "workspace, m+1";
123 bind."SUPER, mouse_down" = "workspace, m-1";
124 };
125
126 # Send a window to another workspace.
127 sendWindow = with groups;
128 lib.mkMerge [ sendWindowAbsolute sendWindowRelative ];
129
130 # Send a window to a workspace by absolute identifier.
131 sendWindowAbsolute = {
132 # Move the active window or group to a primary workspace by index.
133 bind."SUPER_SHIFT, 1" = "movetoworkspacesilent, 1";
134 bind."SUPER_SHIFT, 2" = "movetoworkspacesilent, 2";
135 bind."SUPER_SHIFT, 3" = "movetoworkspacesilent, 3";
136 bind."SUPER_SHIFT, 4" = "movetoworkspacesilent, 4";
137 bind."SUPER_SHIFT, 5" = "movetoworkspacesilent, 5";
138 bind."SUPER_SHIFT, 6" = "movetoworkspacesilent, 6";
139 bind."SUPER_SHIFT, 7" = "movetoworkspacesilent, 7";
140 bind."SUPER_SHIFT, 8" = "movetoworkspacesilent, 8";
141 bind."SUPER_SHIFT, 9" = "movetoworkspacesilent, 9";
142 bind."SUPER_SHIFT, 0" = "movetoworkspacesilent, 10";
143
144 # Move the active window or group to an alternate workspace by index.
145 bind."SUPER_ALT_SHIFT, 1" = "movetoworkspacesilent, 11";
146 bind."SUPER_ALT_SHIFT, 2" = "movetoworkspacesilent, 12";
147 bind."SUPER_ALT_SHIFT, 3" = "movetoworkspacesilent, 13";
148 bind."SUPER_ALT_SHIFT, 4" = "movetoworkspacesilent, 14";
149 bind."SUPER_ALT_SHIFT, 5" = "movetoworkspacesilent, 15";
150 bind."SUPER_ALT_SHIFT, 6" = "movetoworkspacesilent, 16";
151 bind."SUPER_ALT_SHIFT, 7" = "movetoworkspacesilent, 17";
152 bind."SUPER_ALT_SHIFT, 8" = "movetoworkspacesilent, 18";
153 bind."SUPER_ALT_SHIFT, 9" = "movetoworkspacesilent, 19";
154 bind."SUPER_ALT_SHIFT, 0" = "movetoworkspacesilent, 20";
155 };
156
157 # Send windows to other workspaces, relative to the current one.
158 sendWindowRelative = {
159 # Move the active window or group to the next/previous
160 # workspace with page keys, while holding super and shift.
161 bind."SUPER_SHIFT, page_down" = "movetoworkspace, r+1";
162 bind."SUPER_SHIFT, page_up" = "movetoworkspace, r-1";
163
164 # Move the active window or group to the next/previous
165 # workspace with the right and left square brackets,
166 # while holding super and shift.
167 bind."SUPER_SHIFT, bracketright" = "movetoworkspace, r+1";
168 bind."SUPER_SHIFT, bracketleft" = "movetoworkspace, r-1";
169
170 # Move the active window or group to the next/previous
171 # workspace with the mouse wheel while holding super and shift.
172 bind."SUPER_SHIFT, mouse_up" = "movetoworkspace, r+1";
173 bind."SUPER_SHIFT, mouse_down" = "movetoworkspace, r-1";
174 };
175 };
176 in lib.mkMerge [
177 ### ACTIVE WINDOW ACTIONS ###
178 groups.killWindow
179 {
180 # Toggle full-screen for the active window.
181 bind."SUPER_SHIFT, F" = "fullscreen, 0";
182
183 # Float/unfloat the active window.
184 bind."SUPER, F" = "togglefloating,";
185 }
186 ### MISCELLANEOUS ###
187 {
188 # Lock the session immediately.
189 bind."SUPER, l" = "exec, loginctl lock-session";
190
191 # Kill the window manager.
192 bind."SUPER_SHIFT, M" = "exit,";
193
194 # Forcefully kill a program after selecting its window with the mouse.
195 bind."SUPER_SHIFT, Q" = "exec, hyprctl kill";
196
197 # Select a region and take a screenshot, saving to the clipboard.
198 bind."SUPER_SHIFT, print" = "exec, prtsc -c -m r -D -b 00000066";
199
200 # Bypass all binds for the window manager and pass key combinations
201 # directly to the active window.
202 bind."SUPER_SHIFT, K" = "submap, passthru";
203 submap.passthru = { bind."SUPER_SHIFT, K" = "submap, reset"; };
204 }
205 ### PROGRAM LAUNCHING ###
206 groups.launchPrograms
207 {
208 # Open Rofi to launch a program.
209 bind."SUPER, Space" = "exec, rofi -show drun -show-icons";
210 # Open Rofi to run a command.
211 bind."SUPER, R" = "exec, rofi -show run";
212 }
213 ### WINDOW FOCUS & MOVEMENT ###
214 groups.moveFocusOrWindow
215 ### WINDOW RESIZING ###
216 groups.toggleSplit
217 groups.mouseResizeWindow
218
219 ### WORKSPACE SWITCHING ###
220 groups.switchWorkspace
221 ### WORKSPACE WINDOW MOVEMENT ###
222 groups.sendWindow
223 ];
224}