diff options
Diffstat (limited to 'accounts/gkleen@sif/niri/default.nix')
| -rw-r--r-- | accounts/gkleen@sif/niri/default.nix | 994 |
1 files changed, 0 insertions, 994 deletions
diff --git a/accounts/gkleen@sif/niri/default.nix b/accounts/gkleen@sif/niri/default.nix deleted file mode 100644 index caf66ab5..00000000 --- a/accounts/gkleen@sif/niri/default.nix +++ /dev/null | |||
| @@ -1,994 +0,0 @@ | |||
| 1 | { config, hostConfig, pkgs, lib, flakeInputs, ... }: | ||
| 2 | let | ||
| 3 | cfg = config.programs.niri; | ||
| 4 | |||
| 5 | kdl = flakeInputs.niri-flake.lib.kdl; | ||
| 6 | |||
| 7 | niri = cfg.package; | ||
| 8 | terminal = lib.getExe config.programs.kitty.package; | ||
| 9 | makoctl = lib.getExe' config.services.mako.package "makoctl"; | ||
| 10 | loginctl = lib.getExe' hostConfig.systemd.package "loginctl"; | ||
| 11 | systemctl = lib.getExe' hostConfig.systemd.package "systemctl"; | ||
| 12 | swayosd-client = lib.getExe' config.services.swayosd.package "swayosd-client"; | ||
| 13 | |||
| 14 | focus_or_spawn = pkgs.writeShellApplication { | ||
| 15 | name = "focus-or-spawn"; | ||
| 16 | runtimeInputs = [ niri pkgs.gojq pkgs.gnugrep pkgs.socat ]; | ||
| 17 | text = '' | ||
| 18 | window_select="$1" | ||
| 19 | shift | ||
| 20 | workspace_name="$1" | ||
| 21 | shift | ||
| 22 | |||
| 23 | workspaces_json="$(niri msg -j workspaces)" | ||
| 24 | workspace_output="$(jq -r --arg workspace_name "$workspace_name" '.[] | select(.name == $workspace_name) | .output' <<<"$workspaces_json")" | ||
| 25 | # active_workspace="$(jq -r --arg workspace_output "$workspace_output" '.[] | select(.output == $workspace_output and .is_active) | .id' <<<"$workspaces_json")" | ||
| 26 | active_output="$(jq -r '.[] | select(.is_focused) | .output' <<<"$workspaces_json")" | ||
| 27 | if [[ $workspace_output != "$active_output" ]]; then | ||
| 28 | niri msg action move-workspace-to-monitor --reference "$workspace_name" "$active_output" | ||
| 29 | # socat STDIO "$NIRI_SOCKET" <<<'{"Action":{"FocusWorkspace":{"reference":{"Id":'"''${active_workspace}"'}}}}' | ||
| 30 | # niri msg action move-workspace-to-index --reference "$workspace_name" 1 | ||
| 31 | fi | ||
| 32 | |||
| 33 | while IFS=$'\n' read -r window_json; do | ||
| 34 | if [[ -n $(jq -c "$window_select" <<<"$window_json") ]]; then | ||
| 35 | if jq -e '.is_focused' <<<"$window_json" >/dev/null; then | ||
| 36 | niri msg action focus-workspace-previous | ||
| 37 | else | ||
| 38 | if [[ $(jq -r --arg workspace_name "$workspace_name" 'map(select(.name == $workspace_name)) | .[0].is_focused' <<<"$workspaces_json") != "true" ]] && [[ $(jq -r --arg workspace_name "$workspace_name" 'map(select(.name == $workspace_name)) | .[0].id' <<<"$workspaces_json") = $(jq -r '.workspace_id' <<<"$window_json") ]]; then | ||
| 39 | niri msg action focus-workspace "$workspace_name" | ||
| 40 | else | ||
| 41 | niri msg action focus-window --id "$(jq -r '.id' <<<"$window_json")" | ||
| 42 | fi | ||
| 43 | fi | ||
| 44 | exit 0 | ||
| 45 | fi | ||
| 46 | done < <(niri msg -j windows | jq -c '.[]') | ||
| 47 | |||
| 48 | exec "$@" | ||
| 49 | ''; | ||
| 50 | }; | ||
| 51 | focus-or-spawn-action = config.lib.niri.actions.spawn (lib.getExe focus_or_spawn); | ||
| 52 | |||
| 53 | with_adjacent_workspace = pkgs.writeShellApplication { | ||
| 54 | name = "with-adjacent-workspace"; | ||
| 55 | runtimeInputs = [ niri pkgs.gojq pkgs.socat ]; | ||
| 56 | text = '' | ||
| 57 | blacklist="$1" | ||
| 58 | shift | ||
| 59 | direction="$1" | ||
| 60 | shift | ||
| 61 | action="$1" | ||
| 62 | shift | ||
| 63 | |||
| 64 | workspaces_json="$(niri msg -j workspaces)" | ||
| 65 | active_workspace="$(jq -r '.[] | select(.is_focused) | .id' <<<"$workspaces_json")" | ||
| 66 | workspace_output="$(jq -r --arg active_workspace "$active_workspace" '.[] | select(.id == ($active_workspace | tonumber)) | .output' <<<"$workspaces_json")" | ||
| 67 | workspace_idx="$(jq -r '.[] | select(.is_focused) | .idx' <<<"$workspaces_json")" | ||
| 68 | |||
| 69 | jq_script='map(select(' | ||
| 70 | case "$direction" in | ||
| 71 | down) | ||
| 72 | # shellcheck disable=SC2016 | ||
| 73 | jq_script=''${jq_script}'.idx > ($workspace_idx | tonumber)';; | ||
| 74 | up) | ||
| 75 | # shellcheck disable=SC2016 | ||
| 76 | jq_script=''${jq_script}'.idx < ($workspace_idx | tonumber)';; | ||
| 77 | esac | ||
| 78 | # shellcheck disable=SC2016 | ||
| 79 | jq_script=''${jq_script}' and .output == $workspace_output and ((.name == null) or (.name | test($blacklist) | not)))) | sort_by(.idx)' | ||
| 80 | [[ $direction == "up" ]] && jq_script=''${jq_script}' | reverse' | ||
| 81 | jq_script=''${jq_script}' | .[0]' | ||
| 82 | |||
| 83 | workspace_json=$(jq -c --arg blacklist "$blacklist" --arg workspace_output "$workspace_output" --arg workspace_idx "$workspace_idx" "$jq_script" <<<"$workspaces_json") | ||
| 84 | [[ -n $workspace_json && $workspace_json != null ]] || exit 0 | ||
| 85 | jq --arg active_workspace "$active_workspace" -c "$action" <<<"$workspace_json" | tee /dev/stderr | socat STDIO "$NIRI_SOCKET" | ||
| 86 | ''; | ||
| 87 | }; | ||
| 88 | with-adjacent-workspace-action = config.lib.niri.actions.spawn (lib.getExe with_adjacent_workspace) "^${lib.concatMapStringsSep "|" ({ name, ...}: name) cfg.scratchspaces}$"; | ||
| 89 | focus-adjacent-workspace = direction: with-adjacent-workspace-action direction ''{"Action":{"FocusWorkspace":{"reference":{"Id": .id}}}}''; | ||
| 90 | move-column-to-adjacent-workspace = direction: with-adjacent-workspace-action direction ''{"Action":{"MoveColumnToWorkspace":{"reference":{"Id": .id}, "focus": true}}}''; | ||
| 91 | |||
| 92 | with_unnamed_workspace = pkgs.writeShellApplication { | ||
| 93 | name = "with-unnamed-workspace"; | ||
| 94 | runtimeInputs = [ niri pkgs.gojq pkgs.socat ]; | ||
| 95 | text = '' | ||
| 96 | action="$1" | ||
| 97 | shift | ||
| 98 | |||
| 99 | workspaces_json="$(niri msg -j workspaces)" | ||
| 100 | active_output="$(jq -r '.[] | select(.is_focused) | .output' <<<"$workspaces_json")" | ||
| 101 | active_workspace="$(jq -r '.[] | select(.is_focused) | .id' <<<"$workspaces_json")" | ||
| 102 | |||
| 103 | history_json="$(socat STDIO UNIX-CONNECT:"$XDG_RUNTIME_DIR"/niri-workspace-history.sock)" | ||
| 104 | workspace_json="$(jq -c --arg active_output "$active_output" --argjson history "$history_json" 'map(select(.output == $active_output and .name == null)) | map({"value": ., "history_idx": ((. as $workspace | ($history[$active_output] | index($workspace | .id))) as $active_idx | if $active_idx then $active_idx else ($history[$active_output] | length) + 1 end)}) | sort_by(.history_idx, .value.idx) | map(.value) | .[0]' <<<"$workspaces_json")" | ||
| 105 | [[ -n $workspace_json && $workspace_json != null ]] || exit 0 | ||
| 106 | jq --arg active_workspace "$active_workspace" -c "$action" <<<"$workspace_json" | tee /dev/stderr | socat STDIO "$NIRI_SOCKET" | ||
| 107 | ''; | ||
| 108 | }; | ||
| 109 | with-unnamed-workspace-action = config.lib.niri.actions.spawn (lib.getExe with_unnamed_workspace); | ||
| 110 | |||
| 111 | with_empty_unnamed_workspace = pkgs.writeShellApplication { | ||
| 112 | name = "with-empty-unnamed-workspace"; | ||
| 113 | runtimeInputs = [ niri pkgs.gojq pkgs.socat ]; | ||
| 114 | text = '' | ||
| 115 | action="$1" | ||
| 116 | shift | ||
| 117 | |||
| 118 | workspaces_json="$(niri msg -j workspaces)" | ||
| 119 | active_output="$(jq '.[] | select(.is_focused) | .output' <<<"$workspaces_json")" | ||
| 120 | target_workspace_id="$(jq --argjson active_output "$active_output" 'map(select(.active_window_id == null and .name == null and .output == $active_output)) | sort_by(.idx) | .[0].id' <<<"$workspaces_json")" | ||
| 121 | jq --argjson workspace_id "$target_workspace_id" -nc "$action" | tee /dev/stderr | socat STDIO "$NIRI_SOCKET" | ||
| 122 | ''; | ||
| 123 | }; | ||
| 124 | with-empty-unnamed-workspace-action = config.lib.niri.actions.spawn (lib.getExe with_empty_unnamed_workspace); | ||
| 125 | |||
| 126 | with_select_window = pkgs.writeShellApplication { | ||
| 127 | name = "with-select-window"; | ||
| 128 | runtimeInputs = [ niri pkgs.gojq pkgs.socat config.programs.fuzzel.package pkgs.gawk ]; | ||
| 129 | text = '' | ||
| 130 | window_select="$1" | ||
| 131 | shift | ||
| 132 | action="$1" | ||
| 133 | shift | ||
| 134 | |||
| 135 | windows_json="$(niri msg -j windows)" | ||
| 136 | active_workspace="$(jq -r '.[] | select(.is_focused) | .workspace_id' <<<"$windows_json")" | ||
| 137 | window_ix="$(gojq -r --arg active_workspace "$active_workspace" '.[] | select('"$window_select"') | "\(.title)\u0000icon\u001f\(.app_id)"' <<<"$windows_json" | fuzzel --width=60 --log-level=warning --dmenu --index)" | ||
| 138 | # shellcheck disable=SC2016 | ||
| 139 | window_json="$(gojq -rc --arg active_workspace "$active_workspace" --arg window_ix "$window_ix" 'map(select('"$window_select"')) | .[($window_ix | tonumber)]' <<<"$windows_json")" | ||
| 140 | |||
| 141 | [[ -z "$window_json" ]] && exit 1 | ||
| 142 | |||
| 143 | jq -c "$action" <<<"$window_json" | socat STDIO "$NIRI_SOCKET" | ||
| 144 | ''; | ||
| 145 | }; | ||
| 146 | with-select-window-action = config.lib.niri.actions.spawn (lib.getExe with_select_window); | ||
| 147 | |||
| 148 | with_predicate_window = pred: pkgs.writeShellApplication { | ||
| 149 | name = "with-predicate-window"; | ||
| 150 | runtimeInputs = [ niri pkgs.gojq pkgs.socat ]; | ||
| 151 | text = '' | ||
| 152 | action="$1" | ||
| 153 | shift | ||
| 154 | |||
| 155 | windows_json="$(niri msg -j windows)" | ||
| 156 | window_json="$(gojq -rc 'map(select(${pred})) | .[0]' <<<"$windows_json")" | ||
| 157 | |||
| 158 | [[ -z "$window_json" || $window_json = "null" ]] && exit 1 | ||
| 159 | |||
| 160 | jq -c "$action" <<<"$window_json" | socat STDIO "$NIRI_SOCKET" | ||
| 161 | ''; | ||
| 162 | }; | ||
| 163 | |||
| 164 | with-urgent-window-action = config.lib.niri.actions.spawn (lib.getExe (with_predicate_window ".is_urgent")); | ||
| 165 | with-focused-window-action = config.lib.niri.actions.spawn (lib.getExe (with_predicate_window ".is_focused")); | ||
| 166 | in { | ||
| 167 | imports = [ | ||
| 168 | ./waybar.nix | ||
| 169 | ./mako.nix | ||
| 170 | ./swayosd.nix | ||
| 171 | ]; | ||
| 172 | |||
| 173 | options = { | ||
| 174 | programs.niri.scratchspaces = lib.mkOption { | ||
| 175 | type = lib.types.listOf (lib.types.submodule ({ config, ... }: { | ||
| 176 | options = { | ||
| 177 | name = lib.mkOption { | ||
| 178 | type = lib.types.str; | ||
| 179 | }; | ||
| 180 | match = lib.mkOption { | ||
| 181 | type = lib.types.listOf (lib.types.attrsOf kdl.types.kdl-args); | ||
| 182 | default = []; | ||
| 183 | }; | ||
| 184 | exclude = lib.mkOption { | ||
| 185 | type = lib.types.listOf (lib.types.attrsOf kdl.types.kdl-args); | ||
| 186 | default = []; | ||
| 187 | }; | ||
| 188 | windowRuleExtra = lib.mkOption { | ||
| 189 | type = kdl.types.kdl-nodes; | ||
| 190 | default = []; | ||
| 191 | }; | ||
| 192 | key = lib.mkOption { | ||
| 193 | type = lib.types.nullOr lib.types.str; | ||
| 194 | default = null; | ||
| 195 | }; | ||
| 196 | moveKey = lib.mkOption { | ||
| 197 | type = lib.types.nullOr lib.types.str; | ||
| 198 | default = let | ||
| 199 | keys = lib.splitString "+" config.key; | ||
| 200 | defMoveKey = lib.concatStringsSep "+" (lib.flatten [ | ||
| 201 | (lib.take (lib.length keys - 1) keys) | ||
| 202 | ["Shift"] | ||
| 203 | (lib.takeEnd 1 keys) | ||
| 204 | ]); | ||
| 205 | in if config.key == null then null else defMoveKey; | ||
| 206 | }; | ||
| 207 | spawn = lib.mkOption { | ||
| 208 | type = lib.types.nullOr (lib.types.listOf lib.types.str); | ||
| 209 | default = null; | ||
| 210 | }; | ||
| 211 | app-id = lib.mkOption { | ||
| 212 | type = lib.types.nullOr lib.types.str; | ||
| 213 | default = null; | ||
| 214 | }; | ||
| 215 | selector = lib.mkOption { | ||
| 216 | type = lib.types.nullOr lib.types.str; | ||
| 217 | default = null; | ||
| 218 | }; | ||
| 219 | }; | ||
| 220 | |||
| 221 | config = lib.mkMerge [ | ||
| 222 | (lib.mkIf (config.app-id != null) { | ||
| 223 | match = lib.mkDefault [ { app-id = "^${lib.escapeRegex config.app-id}$"; } ]; | ||
| 224 | selector = lib.mkDefault "select(.app_id == \"${config.app-id}\")"; | ||
| 225 | }) | ||
| 226 | ]; | ||
| 227 | })); | ||
| 228 | default = []; | ||
| 229 | }; | ||
| 230 | }; | ||
| 231 | |||
| 232 | config = { | ||
| 233 | systemd.user.services.xwayland-satellite = { | ||
| 234 | Unit = { | ||
| 235 | BindsTo = [ "graphical-session.target" ]; | ||
| 236 | PartOf = [ "graphical-session.target" ]; | ||
| 237 | After = [ "graphical-session.target" ]; | ||
| 238 | Requisite = [ "graphical-session.target" ]; | ||
| 239 | }; | ||
| 240 | Service = { | ||
| 241 | Type = "notify"; | ||
| 242 | NotifyAccess = "all"; | ||
| 243 | Environment = [ "DISPLAY=:0" ]; | ||
| 244 | ExecStart = ''${lib.getExe pkgs.xwayland-satellite-unstable} ''${DISPLAY}''; | ||
| 245 | ExecStartPre = "${systemctl} --user import-environment DISPLAY"; | ||
| 246 | StandardOutput = "journal"; | ||
| 247 | }; | ||
| 248 | Install = { | ||
| 249 | WantedBy = [ "graphical-session.target" ]; | ||
| 250 | }; | ||
| 251 | }; | ||
| 252 | |||
| 253 | services.swayidle = { | ||
| 254 | events = [ | ||
| 255 | { event = "after-resume"; command = "${lib.getExe niri} msg action power-on-monitors"; } | ||
| 256 | ]; | ||
| 257 | timeouts = [ | ||
| 258 | { timeout = 540; | ||
| 259 | command = "${lib.getExe niri} msg action power-off-monitors"; | ||
| 260 | } | ||
| 261 | ]; | ||
| 262 | }; | ||
| 263 | |||
| 264 | systemd.user.sockets.niri-workspace-history = { | ||
| 265 | Socket = { | ||
| 266 | ListenStream = "%t/niri-workspace-history.sock"; | ||
| 267 | SocketMode = "0600"; | ||
| 268 | }; | ||
| 269 | }; | ||
| 270 | systemd.user.services.niri-workspace-history = { | ||
| 271 | Unit = { | ||
| 272 | BindsTo = [ "niri.service" ]; | ||
| 273 | After = [ "niri.service" ]; | ||
| 274 | }; | ||
| 275 | Install = { | ||
| 276 | WantedBy = [ "niri.service" ]; | ||
| 277 | }; | ||
| 278 | Service = { | ||
| 279 | Type = "simple"; | ||
| 280 | Sockets = [ "niri-workspace-history.socket" ]; | ||
| 281 | ExecStart = pkgs.writers.writePython3 "niri-workspace-history" { flakeIgnore = ["E501"]; } '' | ||
| 282 | import os | ||
| 283 | import socket | ||
| 284 | import json | ||
| 285 | # import sys | ||
| 286 | from collections import defaultdict | ||
| 287 | from threading import Thread, Lock | ||
| 288 | from socketserver import StreamRequestHandler, ThreadingTCPServer | ||
| 289 | from contextlib import contextmanager | ||
| 290 | from io import TextIOWrapper | ||
| 291 | |||
| 292 | |||
| 293 | @contextmanager | ||
| 294 | def detaching(thing): | ||
| 295 | try: | ||
| 296 | yield thing | ||
| 297 | finally: | ||
| 298 | thing.detach() | ||
| 299 | |||
| 300 | |||
| 301 | workspace_history = defaultdict(list) | ||
| 302 | history_lock = Lock() | ||
| 303 | |||
| 304 | |||
| 305 | def monitor_niri(): | ||
| 306 | workspaces = list() | ||
| 307 | |||
| 308 | def focus_workspace(output, workspace): | ||
| 309 | with history_lock: | ||
| 310 | workspace_history[output] = [workspace] + [ws for ws in workspace_history[output] if ws != workspace] | ||
| 311 | # print(json.dumps(workspace_history), file=sys.stderr) | ||
| 312 | |||
| 313 | sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | ||
| 314 | sock.connect(os.environ["NIRI_SOCKET"]) | ||
| 315 | sock.send(b"\"EventStream\"\n") | ||
| 316 | for line in sock.makefile(buffering=1, encoding='utf-8'): | ||
| 317 | if line_json := json.loads(line): | ||
| 318 | if "WorkspacesChanged" in line_json: | ||
| 319 | workspaces = line_json["WorkspacesChanged"]["workspaces"] | ||
| 320 | for ws in workspaces: | ||
| 321 | if ws["is_focused"]: | ||
| 322 | focus_workspace(ws["output"], ws["id"]) | ||
| 323 | if "WorkspaceActivated" in line_json: | ||
| 324 | for ws in workspaces: | ||
| 325 | if ws["id"] != line_json["WorkspaceActivated"]["id"]: | ||
| 326 | continue | ||
| 327 | focus_workspace(ws["output"], ws["id"]) | ||
| 328 | break | ||
| 329 | |||
| 330 | |||
| 331 | class RequestHandler(StreamRequestHandler): | ||
| 332 | def handle(self): | ||
| 333 | with detaching(TextIOWrapper(self.wfile, encoding='utf-8', write_through=True)) as out: | ||
| 334 | with history_lock: | ||
| 335 | json.dump(workspace_history, out) | ||
| 336 | |||
| 337 | |||
| 338 | class Server(ThreadingTCPServer): | ||
| 339 | def __init__(self): | ||
| 340 | ThreadingTCPServer.__init__(self, ("", 8000), RequestHandler, bind_and_activate=False) | ||
| 341 | self.socket = socket.fromfd(3, self.address_family, self.socket_type) | ||
| 342 | |||
| 343 | |||
| 344 | def run_server(): | ||
| 345 | with Server() as server: | ||
| 346 | server.serve_forever() | ||
| 347 | |||
| 348 | |||
| 349 | niri = Thread(target=monitor_niri) | ||
| 350 | niri.daemon = True | ||
| 351 | niri.start() | ||
| 352 | |||
| 353 | server_thread = Thread(target=run_server) | ||
| 354 | server_thread.daemon = True | ||
| 355 | server_thread.start() | ||
| 356 | |||
| 357 | while True: | ||
| 358 | server_thread.join(timeout=0.5) | ||
| 359 | niri.join(timeout=0.5) | ||
| 360 | |||
| 361 | if not (niri.is_alive() and server_thread.is_alive()): | ||
| 362 | break | ||
| 363 | ''; | ||
| 364 | }; | ||
| 365 | }; | ||
| 366 | systemd.user.services.niri-workspace-sort = { | ||
| 367 | Unit = { | ||
| 368 | BindsTo = [ "niri.service" ]; | ||
| 369 | After = [ "niri.service" ]; | ||
| 370 | }; | ||
| 371 | Install = { | ||
| 372 | WantedBy = [ "niri.service" ]; | ||
| 373 | }; | ||
| 374 | Service = { | ||
| 375 | Type = "simple"; | ||
| 376 | ExecStart = pkgs.writers.writePython3 "niri-workspace-sort" { flakeIgnore = ["E501"]; } '' | ||
| 377 | import os | ||
| 378 | import sys | ||
| 379 | import socket | ||
| 380 | import json | ||
| 381 | |||
| 382 | outputs = None | ||
| 383 | only = {'HDMI-A-1': {'bmr'}, 'eDP-1': {'vid'}} | ||
| 384 | |||
| 385 | |||
| 386 | class Niri(socket.socket): | ||
| 387 | def __init__(self): | ||
| 388 | super().__init__(socket.AF_UNIX, socket.SOCK_STREAM) | ||
| 389 | super().connect(os.environ["NIRI_SOCKET"]) | ||
| 390 | self.fh = super().makefile(mode='rw', buffering=1, encoding='utf-8') | ||
| 391 | |||
| 392 | def cmd(self, obj): | ||
| 393 | print(json.dumps(obj, separators=(',', ':')), flush=True, file=self.fh) | ||
| 394 | |||
| 395 | def event_stream(self): | ||
| 396 | self.cmd("EventStream") | ||
| 397 | return self.fh | ||
| 398 | |||
| 399 | |||
| 400 | with Niri() as niri, Niri().event_stream() as niri_stream: | ||
| 401 | for line in niri_stream: | ||
| 402 | workspaces = None | ||
| 403 | if line_json := json.loads(line): | ||
| 404 | if "WorkspacesChanged" in line_json: | ||
| 405 | workspaces = line_json["WorkspacesChanged"]["workspaces"] | ||
| 406 | |||
| 407 | if workspaces is None: | ||
| 408 | continue | ||
| 409 | |||
| 410 | old_outputs = outputs | ||
| 411 | outputs = {ws["output"] for ws in workspaces} | ||
| 412 | if old_outputs is None: | ||
| 413 | print("Initial outputs: {}".format(outputs), file=sys.stderr) | ||
| 414 | continue | ||
| 415 | |||
| 416 | new_outputs = outputs - old_outputs | ||
| 417 | if not new_outputs: | ||
| 418 | continue | ||
| 419 | print("New outputs: {}".format(new_outputs), file=sys.stderr) | ||
| 420 | |||
| 421 | relevant_workspaces = list(filter(lambda ws: (ws["name"] is not None) or (ws["active_window_id"] is not None), workspaces)) | ||
| 422 | target_output = next(iter(outputs - set(only.keys()))) | ||
| 423 | if not target_output: | ||
| 424 | continue | ||
| 425 | for ws in relevant_workspaces: | ||
| 426 | ws_ident = ws["name"] if ws["name"] is not None else (ws["output"], ws["idx"]) | ||
| 427 | if ws["output"] not in set(only.keys()): | ||
| 428 | continue | ||
| 429 | if ws_ident in only[ws["output"]]: | ||
| 430 | continue | ||
| 431 | |||
| 432 | print("{} -> {}".format(ws_ident, target_output), file=sys.stderr) | ||
| 433 | niri.cmd({"Action": {"MoveWorkspaceToMonitor": {"reference": {"Id": ws["id"]}, "output": target_output}}}) | ||
| 434 | ''; | ||
| 435 | Restart = "on-failure"; | ||
| 436 | RestartSec = 10; | ||
| 437 | }; | ||
| 438 | }; | ||
| 439 | |||
| 440 | programs.niri.scratchspaces = [ | ||
| 441 | { name = "pwctl"; | ||
| 442 | key = "Mod+Control+A"; | ||
| 443 | spawn = ["pwvucontrol"]; | ||
| 444 | app-id = "com.saivert.pwvucontrol"; | ||
| 445 | } | ||
| 446 | { name = "kpxc"; | ||
| 447 | exclude = [ | ||
| 448 | { title = "^Unlock Database.*"; } | ||
| 449 | { title = "^Access Request.*"; } | ||
| 450 | { title = ".*Passkey credentials$"; } | ||
| 451 | ]; | ||
| 452 | windowRuleExtra = with kdl; [ | ||
| 453 | (kdl.leaf "open-focused" false) | ||
| 454 | ]; | ||
| 455 | key = "Mod+Control+P"; | ||
| 456 | app-id = "org.keepassxc.KeePassXC"; | ||
| 457 | spawn = [ "keepassxc" ]; | ||
| 458 | } | ||
| 459 | { name = "bmgr"; | ||
| 460 | key = "Mod+Control+B"; | ||
| 461 | app-id = ".blueman-manager-wrapped"; | ||
| 462 | spawn = [ "blueman-manager" ]; | ||
| 463 | } | ||
| 464 | { name = "term"; | ||
| 465 | key = "Mod+Control+Return"; | ||
| 466 | app-id = "kitty-scratch"; | ||
| 467 | spawn = [ "kitty" "--app-id" "kitty-scratch" ]; | ||
| 468 | } | ||
| 469 | { name = "edit"; | ||
| 470 | match = [ { title = "^scratch$"; app-id = "^emacs$"; } ]; | ||
| 471 | key = "Mod+Control+E"; | ||
| 472 | selector = "select(.app_id == \"emacs\" and .title == \"scratch\")"; | ||
| 473 | spawn = [ "emacsclient" "-c" "--frame-parameters=(quote (name . \"scratch\"))" ]; | ||
| 474 | } | ||
| 475 | { name = "eff"; | ||
| 476 | key = "Mod+Control+O"; | ||
| 477 | app-id = "com.github.wwmm.easyeffects"; | ||
| 478 | spawn = [ "easyeffects" ]; | ||
| 479 | } | ||
| 480 | { name = "time"; | ||
| 481 | key = "Mod+Control+K"; | ||
| 482 | app-id = "chrome-kimai.yggdrasil.li__-Default"; | ||
| 483 | spawn = [ (toString (pkgs.resholve.writeScript "kimai" { | ||
| 484 | interpreter = pkgs.runtimeShell; | ||
| 485 | inputs = [ pkgs.dex ]; | ||
| 486 | execer = [ "cannot:${lib.getExe pkgs.dex}" ]; | ||
| 487 | } '' | ||
| 488 | exec dex $HOME/.local/state/nix/profile/share/applications/kimai.desktop | ||
| 489 | '')) ]; | ||
| 490 | windowRuleExtra = with kdl; [ | ||
| 491 | (leaf "block-out-from" "screencast") | ||
| 492 | ]; | ||
| 493 | } | ||
| 494 | ]; | ||
| 495 | programs.niri.config = | ||
| 496 | let | ||
| 497 | inherit (kdl) node plain leaf flag; | ||
| 498 | optional-node = cond: v: | ||
| 499 | if cond | ||
| 500 | then v | ||
| 501 | else null; | ||
| 502 | opt-props = lib.filterAttrs (lib.const (value: value != null)); | ||
| 503 | in | ||
| 504 | [ (flag "prefer-no-csd") | ||
| 505 | |||
| 506 | (leaf "screenshot-path" "~/screenshots/%Y-%m-%dT%H:%M:%S.png") | ||
| 507 | |||
| 508 | (plain "hotkey-overlay" [ | ||
| 509 | (flag "skip-at-startup") | ||
| 510 | ]) | ||
| 511 | |||
| 512 | (plain "input" [ | ||
| 513 | (plain "keyboard" [ | ||
| 514 | (leaf "repeat-delay" 300) | ||
| 515 | (leaf "repeat-rate" 50) | ||
| 516 | |||
| 517 | (plain "xkb" [ | ||
| 518 | (leaf "layout" "us,us") | ||
| 519 | (leaf "variant" "dvp,") | ||
| 520 | (leaf "options" "compose:caps,grp:win_space_toggle") | ||
| 521 | ]) | ||
| 522 | ]) | ||
| 523 | |||
| 524 | (flag "workspace-auto-back-and-forth") | ||
| 525 | # (leaf "focus-follows-mouse" {}) | ||
| 526 | # (flag "warp-mouse-to-focus") | ||
| 527 | |||
| 528 | # (plain "touchpad" [ (flag "off") ]) | ||
| 529 | (plain "trackball" [ | ||
| 530 | (leaf "scroll-method" "on-button-down") | ||
| 531 | (leaf "scroll-button" 278) | ||
| 532 | ]) | ||
| 533 | (plain "touch" [ | ||
| 534 | (leaf "map-to-output" "eDP-1") | ||
| 535 | ]) | ||
| 536 | ]) | ||
| 537 | |||
| 538 | (plain "gestures" [ | ||
| 539 | (plain "hot-corners" [(flag "off")]) | ||
| 540 | ]) | ||
| 541 | |||
| 542 | (plain "environment" (lib.mapAttrsToList leaf { | ||
| 543 | NIXOS_OZONE_WL = "1"; | ||
| 544 | QT_QPA_PLATFORM = "wayland"; | ||
| 545 | QT_WAYLAND_DISABLE_WINDOWDECORATION = "1"; | ||
| 546 | GDK_BACKEND = "wayland"; | ||
| 547 | SDL_VIDEODRIVER = "wayland"; | ||
| 548 | DISPLAY = ":0"; | ||
| 549 | ELECTRON_OZONE_PLATFORM_HINT = "auto"; | ||
| 550 | SSH_ASKPASS_REQUIRE = "prefer"; | ||
| 551 | SSH_ASKPASS = lib.getExe pkgs.kdePackages.ksshaskpass; | ||
| 552 | SUDO_ASKPASS = lib.getExe pkgs.kdePackages.ksshaskpass; | ||
| 553 | })) | ||
| 554 | |||
| 555 | (node "output" "eDP-1" [ | ||
| 556 | (leaf "scale" 1.5) | ||
| 557 | (leaf "position" { x = 0; y = 0; }) | ||
| 558 | ]) | ||
| 559 | (node "output" "Ancor Communications Inc ASUS PB287Q 0x0000DD9B" [ | ||
| 560 | (leaf "scale" 1.5) | ||
| 561 | (leaf "position" { x = 2560; y = 0; }) | ||
| 562 | ]) | ||
| 563 | (node "output" "HP Inc. HP 727pu CN4417143K" [ | ||
| 564 | (leaf "mode" "2560x1440@119.998") | ||
| 565 | (leaf "scale" 1) | ||
| 566 | (leaf "position" { x = 2560; y = 0; }) | ||
| 567 | (flag "variable-refresh-rate") | ||
| 568 | ]) | ||
| 569 | |||
| 570 | (plain "debug" [ | ||
| 571 | (leaf "render-drm-device" "/dev/dri/by-path/pci-0000:00:02.0-render") | ||
| 572 | ]) | ||
| 573 | |||
| 574 | (plain "animations" [ | ||
| 575 | (leaf "slowdown" 0.5) | ||
| 576 | (plain "workspace-switch" [(flag "off")]) | ||
| 577 | ]) | ||
| 578 | |||
| 579 | (plain "layout" [ | ||
| 580 | (leaf "gaps" 8) | ||
| 581 | (plain "struts" [ | ||
| 582 | (leaf "left" 26) | ||
| 583 | (leaf "right" 26) | ||
| 584 | (leaf "top" 0) | ||
| 585 | (leaf "bottom" 0) | ||
| 586 | ]) | ||
| 587 | (plain "border" [ | ||
| 588 | (leaf "width" 2) | ||
| 589 | (leaf "active-gradient" { | ||
| 590 | from = "hsla(195 100% 45% 1)"; | ||
| 591 | to = "hsla(155 100% 37.5% 1)"; | ||
| 592 | angle = 29; | ||
| 593 | relative-to = "workspace-view"; | ||
| 594 | }) | ||
| 595 | (leaf "inactive-gradient" { | ||
| 596 | from = "hsla(0 0% 27.7% 1)"; | ||
| 597 | to = "hsla(0 0% 23% 1)"; | ||
| 598 | angle = 29; | ||
| 599 | relative-to = "workspace-view"; | ||
| 600 | }) | ||
| 601 | ]) | ||
| 602 | (plain "focus-ring" [ | ||
| 603 | (flag "off") | ||
| 604 | ]) | ||
| 605 | |||
| 606 | (plain "preset-column-widths" (map (prop: leaf "proportion" prop) [ | ||
| 607 | (1. / 4.) (1. / 3.) (1. / 2.) (2. / 3.) (3. / 4.) (1.) | ||
| 608 | ])) | ||
| 609 | (plain "default-column-width" [ (leaf "proportion" (1. / 2.)) ]) | ||
| 610 | (plain "preset-window-heights" (map (prop: leaf "proportion" prop) [ | ||
| 611 | (1. / 3.) (1. / 2.) (2. / 3.) (1.) | ||
| 612 | ])) | ||
| 613 | |||
| 614 | (flag "always-center-single-column") | ||
| 615 | |||
| 616 | (plain "tab-indicator" [ | ||
| 617 | (leaf "gap" 4) | ||
| 618 | (leaf "width" 8) | ||
| 619 | (leaf "gaps-between-tabs" 4) | ||
| 620 | (flag "place-within-column") | ||
| 621 | (leaf "length" { total-proportion = 1.; }) | ||
| 622 | (leaf "active-gradient" { | ||
| 623 | from = "hsla(195 100% 60% 0.75)"; | ||
| 624 | to = "hsla(155 100% 50% 0.75)"; | ||
| 625 | angle = 29; | ||
| 626 | relative-to = "workspace-view"; | ||
| 627 | }) | ||
| 628 | (leaf "inactive-gradient" { | ||
| 629 | from = "hsla(0 0% 42% 0.66)"; | ||
| 630 | to = "hsla(0 0% 35% 0.66)"; | ||
| 631 | angle = 29; | ||
| 632 | relative-to = "workspace-view"; | ||
| 633 | }) | ||
| 634 | ]) | ||
| 635 | ]) | ||
| 636 | |||
| 637 | (plain "cursor" [ | ||
| 638 | (flag "hide-when-typing") | ||
| 639 | ]) | ||
| 640 | |||
| 641 | (map (name: | ||
| 642 | (node "workspace" name [ | ||
| 643 | (leaf "open-on-output" "eDP-1") | ||
| 644 | ]) | ||
| 645 | ) (map ({name, ...}: name) cfg.scratchspaces)) | ||
| 646 | (map (name: | ||
| 647 | (leaf "workspace" name) | ||
| 648 | ) ["comm" "web" "vid" "bmr"]) | ||
| 649 | |||
| 650 | (plain "window-rule" [ | ||
| 651 | (leaf "clip-to-geometry" true) | ||
| 652 | ]) | ||
| 653 | |||
| 654 | (plain "window-rule" [ | ||
| 655 | (leaf "match" { is-floating = true; }) | ||
| 656 | (leaf "geometry-corner-radius" 8) | ||
| 657 | (plain "shadow" [ (flag "on") ]) | ||
| 658 | ]) | ||
| 659 | |||
| 660 | (plain "window-rule" [ | ||
| 661 | (leaf "match" { app-id = "^org\\.keepassxc\\.KeePassXC$"; }) | ||
| 662 | (leaf "block-out-from" "screencast") | ||
| 663 | ]) | ||
| 664 | (plain "window-rule" [ | ||
| 665 | (map (title: | ||
| 666 | (leaf "match" { app-id = "^org\\.keepassxc\\.KeePassXC$"; inherit title; }) | ||
| 667 | ) ["^Unlock Database.*" "^Access Request.*" ".*Passkey credentials$"]) | ||
| 668 | (leaf "open-focused" true) | ||
| 669 | (leaf "open-floating" true) | ||
| 670 | ]) | ||
| 671 | |||
| 672 | (map ({ name, match, exclude, windowRuleExtra, ... }: | ||
| 673 | (optional-node (match != []) (plain "window-rule" [ | ||
| 674 | (map (leaf "match") match) | ||
| 675 | (map (leaf "exclude") exclude) | ||
| 676 | (leaf "open-on-workspace" name) | ||
| 677 | (leaf "open-maximized" true) | ||
| 678 | windowRuleExtra | ||
| 679 | ])) | ||
| 680 | ) cfg.scratchspaces) | ||
| 681 | |||
| 682 | (plain "window-rule" [ | ||
| 683 | (leaf "match" { app-id = "^emacs$"; }) | ||
| 684 | (leaf "match" { app-id = "^firefox$"; }) | ||
| 685 | (plain "default-column-width" [(leaf "proportion" (2. / 3.))]) | ||
| 686 | ]) | ||
| 687 | (plain "window-rule" [ | ||
| 688 | (leaf "match" { app-id = "^kitty$"; }) | ||
| 689 | (leaf "match" { app-id = "^kitty-play$"; }) | ||
| 690 | (plain "default-column-width" [(leaf "proportion" (1. / 3.))]) | ||
| 691 | ]) | ||
| 692 | |||
| 693 | (plain "window-rule" [ | ||
| 694 | (leaf "match" { app-id = "^thunderbird$"; }) | ||
| 695 | (leaf "match" { app-id = "^Element$"; }) | ||
| 696 | (leaf "match" { app-id = "^chrome-web\.openrainbow\.com__-Default$"; }) | ||
| 697 | (leaf "open-on-workspace" "comm") | ||
| 698 | ]) | ||
| 699 | (plain "window-rule" [ | ||
| 700 | (leaf "match" { app-id = "^firefox$"; }) | ||
| 701 | (leaf "open-on-workspace" "web") | ||
| 702 | (leaf "open-maximized" true) | ||
| 703 | ]) | ||
| 704 | (plain "window-rule" [ | ||
| 705 | (leaf "match" { app-id = "^mpv$"; }) | ||
| 706 | (leaf "open-on-workspace" "vid") | ||
| 707 | (plain "default-column-width" [(leaf "proportion" 1.)]) | ||
| 708 | ]) | ||
| 709 | (plain "window-rule" [ | ||
| 710 | (leaf "match" { app-id = "^kitty-play$"; }) | ||
| 711 | (leaf "open-on-workspace" "vid") | ||
| 712 | (leaf "open-focused" false) | ||
| 713 | ]) | ||
| 714 | (plain "window-rule" [ | ||
| 715 | (leaf "match" { app-id = "^pdfpc$"; }) | ||
| 716 | (plain "default-column-width" [(leaf "proportion" 1.)]) | ||
| 717 | ]) | ||
| 718 | (plain "window-rule" [ | ||
| 719 | (leaf "match" { app-id = "^pdfpc$"; title = "^.*presentation.*$"; }) | ||
| 720 | (plain "default-column-width" [(leaf "proportion" 1.)]) | ||
| 721 | (leaf "open-fullscreen" true) | ||
| 722 | (leaf "open-on-workspace" "bmr") | ||
| 723 | (leaf "open-focused" false) | ||
| 724 | ]) | ||
| 725 | (plain "window-rule" [ | ||
| 726 | (map (leaf "match") [ | ||
| 727 | { app-id = "^Gimp-"; title = "^Quit GIMP$"; } | ||
| 728 | { app-id = "^org\\.kde\\.polkit-kde-authentication-agent-1$"; } | ||
| 729 | { app-id = "^xdg-desktop-portal-gtk$"; } | ||
| 730 | ]) | ||
| 731 | (leaf "open-floating" true) | ||
| 732 | ]) | ||
| 733 | (plain "window-rule" [ | ||
| 734 | (leaf "match" { app-id = "^org\\.pwmt\\.zathura$"; }) | ||
| 735 | (leaf "match" { app-id = "^evince$"; }) | ||
| 736 | (leaf "match" { app-id = "^org\\.gnome\\.Papers$"; }) | ||
| 737 | (leaf "default-column-display" "tabbed") | ||
| 738 | ]) | ||
| 739 | |||
| 740 | (plain "layer-rule" [ | ||
| 741 | (leaf "match" { namespace = "^notifications$"; }) | ||
| 742 | (leaf "match" { namespace = "^waybar$"; }) | ||
| 743 | (leaf "match" { namespace = "^launcher$"; }) | ||
| 744 | (leaf "block-out-from" "screencast") | ||
| 745 | ]) | ||
| 746 | |||
| 747 | (plain "binds" | ||
| 748 | (let | ||
| 749 | bind = name: cfg: node name (opt-props { | ||
| 750 | cooldown-ms = cfg.cooldown-ms or null; | ||
| 751 | } | ||
| 752 | // (lib.optionalAttrs (!(cfg.repeat or true)) { | ||
| 753 | repeat = false; | ||
| 754 | }) | ||
| 755 | // (lib.optionalAttrs (cfg.allow-when-locked or false) { | ||
| 756 | allow-when-locked = true; | ||
| 757 | })) (lib.mapAttrsToList leaf (lib.removeAttrs cfg.action ["__functor"])); | ||
| 758 | in | ||
| 759 | [ | ||
| 760 | (lib.mapAttrsToList bind (with config.lib.niri.actions; { | ||
| 761 | "Mod+Slash".action = show-hotkey-overlay; | ||
| 762 | |||
| 763 | "Mod+Return".action = spawn terminal; | ||
| 764 | "Mod+Shift+Return".action = | ||
| 765 | let | ||
| 766 | nushellKitty = pkgs.symlinkJoin { | ||
| 767 | name = "nushell-kitty"; | ||
| 768 | paths = [ config.programs.kitty.package ]; | ||
| 769 | buildInputs = [ pkgs.makeWrapper ]; | ||
| 770 | postBuild = '' | ||
| 771 | wrapProgram $out/bin/kitty \ | ||
| 772 | --add-flags "--config ${pkgs.writeText "kitty.conf" '' | ||
| 773 | include $HOME/${config.xdg.configFile."kitty/kitty.conf".target} | ||
| 774 | shell ${lib.getExe config.programs.nushell.package} | ||
| 775 | ''}" | ||
| 776 | ''; | ||
| 777 | }; | ||
| 778 | in spawn (lib.getExe' nushellKitty "kitty"); | ||
| 779 | "Mod+Q".action = close-window; | ||
| 780 | "Mod+O".action = spawn (lib.getExe config.programs.fuzzel.package); | ||
| 781 | "Mod+Shift+O".action = spawn (lib.getExe config.programs.fuzzel.package) "--list-executables-in-path"; | ||
| 782 | |||
| 783 | "Mod+Alt+E".action = spawn (lib.getExe' config.services.emacs.package "emacsclient") "-c"; | ||
| 784 | "Mod+Alt+Y".action = spawn (lib.getExe (pkgs.writeShellApplication { | ||
| 785 | name = "queue-yt-dlp"; | ||
| 786 | runtimeInputs = with pkgs; [ wl-clipboard-rs socat ]; | ||
| 787 | text = '' | ||
| 788 | socat STDIO UNIX-CONNECT:"$XDG_RUNTIME_DIR"/yt-dlp.sock <<<$'{ "urls": ["'"$(wl-paste)"$'"] }' | ||
| 789 | ''; | ||
| 790 | })); | ||
| 791 | "Mod+Alt+L".action = spawn (lib.getExe (pkgs.writeShellApplication { | ||
| 792 | name = "queue-yt-dlp"; | ||
| 793 | runtimeInputs = with pkgs; [ wl-clipboard-rs config.programs.kitty.package ]; | ||
| 794 | text = '' | ||
| 795 | exec -- kitty --app-id kitty-play --directory "$HOME"/media mpv "$(wl-paste)" | ||
| 796 | ''; | ||
| 797 | })); | ||
| 798 | "Mod+Alt+M".action = spawn (lib.getExe' pkgs.screen-message "sm") "-n" "Fira Mono" "-a" "1" "-f" "#fff" "-b" "#000"; | ||
| 799 | |||
| 800 | "Mod+U".action = spawn (lib.getExe (pkgs.writeShellApplication { | ||
| 801 | name = "qalc-fuzzel"; | ||
| 802 | runtimeInputs = with pkgs; [ wl-clipboard-rs libqalculate config.programs.fuzzel.package coreutils findutils libnotify gnugrep ]; | ||
| 803 | text = '' | ||
| 804 | RESULTS_DIR="$HOME/.cache/qalc-fuzzel" | ||
| 805 | prev() { | ||
| 806 | FOUND=false | ||
| 807 | while IFS= read -r line; do | ||
| 808 | [[ -n "$line" ]] || continue | ||
| 809 | FOUND=true | ||
| 810 | echo "$line" | ||
| 811 | done < <(export LC_ALL=C.UTF-8; echo; find "$RESULTS_DIR" -type f -printf $'%T@ %p\n' | sort -n | cut -d' ' -f2- | xargs -r cat) | ||
| 812 | $FOUND || echo | ||
| 813 | } | ||
| 814 | FUZZEL_RES=$(prev | fuzzel --dmenu --prompt "qalc> " --width=60) || exit $? | ||
| 815 | if [[ "$FUZZEL_RES" =~ .*\ =\ .* ]]; then | ||
| 816 | QALC_RES="$FUZZEL_RES" | ||
| 817 | QALC_RET=0 | ||
| 818 | else | ||
| 819 | QALC_RES=$(qalc -set "autocalc off" "$FUZZEL_RES" 2>&1) | ||
| 820 | QALC_RET=$? | ||
| 821 | fi | ||
| 822 | [[ -n "$QALC_RES" ]] || exit 1 | ||
| 823 | EXISTING=false | ||
| 824 | set +o pipefail | ||
| 825 | grep -Fxrl "$QALC_RES" "$RESULTS_DIR" | xargs -r touch | ||
| 826 | [[ ''${PIPESTATUS[0]} -eq 0 ]] && EXISTING=true | ||
| 827 | set -o pipefail | ||
| 828 | if [[ $QALC_RET -eq 0 ]] && ! $EXISTING; then | ||
| 829 | set +o pipefail | ||
| 830 | RES_FILE="$RESULTS_DIR"/$(date -uIs).$(tr -Cd 'a-zA-Z0-9' </dev/random | head -c 10) | ||
| 831 | set -o pipefail | ||
| 832 | cat >"$RES_FILE" <<<"$QALC_RES" | ||
| 833 | fi | ||
| 834 | [[ "$QALC_RES" =~ .*\ =\ (.*) ]] && QALC_RES="''${BASH_REMATCH[1]}" | ||
| 835 | [[ $QALC_RET -eq 0 ]] && wl-copy "$QALC_RES" | ||
| 836 | notify-send "$QALC_RES" | ||
| 837 | ''; | ||
| 838 | })); | ||
| 839 | "Mod+E".action = spawn (lib.getExe (pkgs.writeShellApplication { | ||
| 840 | name = "emoji-fuzzel"; | ||
| 841 | runtimeInputs = with pkgs; [ config.programs.fuzzel.package wtype wl-clipboard-rs ]; | ||
| 842 | text = '' | ||
| 843 | FUZZEL_RES=$(fuzzel --dmenu --prompt "emoji> " --cache "$HOME"/.cache/fuzzel-emoji --width=60 <"$HOME"/.local/share/emoji-data/list.txt) || exit $? | ||
| 844 | [[ -n "$FUZZEL_RES" ]] || exit 1 | ||
| 845 | wl-copy "$(cut -d ':' -f 1 <<<"$FUZZEL_RES" | tr -d '\n')" && wtype -k XF86Paste | ||
| 846 | ''; | ||
| 847 | })); | ||
| 848 | "Print".action = screenshot; | ||
| 849 | "Control+Print".action = screenshot-window; | ||
| 850 | "Shift+Print".action = kdl.magic-leaf "screenshot-screen"; | ||
| 851 | "Mod+B".action = with-select-window-action ".workspace_id == ($active_workspace | tonumber)" "{\"Action\":{\"FocusWindow\":{\"id\": .id}}}"; | ||
| 852 | "Mod+Shift+B".action = with-select-window-action "true" "{\"Action\":{\"FocusWindow\":{\"id\": .id}}}"; | ||
| 853 | |||
| 854 | "Mod+Escape" = { | ||
| 855 | allow-inhibiting = false; | ||
| 856 | action = toggle-keyboard-shortcuts-inhibit; | ||
| 857 | }; | ||
| 858 | |||
| 859 | "Mod+H".action = focus-column-left; | ||
| 860 | "Mod+T".action = focus-window-down; | ||
| 861 | "Mod+N".action = focus-window-up; | ||
| 862 | "Mod+S".action = focus-column-right; | ||
| 863 | |||
| 864 | "Mod+Shift+H".action = move-column-left; | ||
| 865 | "Mod+Shift+T".action = move-window-down; | ||
| 866 | "Mod+Shift+N".action = move-window-up; | ||
| 867 | "Mod+Shift+S".action = move-column-right; | ||
| 868 | |||
| 869 | "Mod+Control+H".action = focus-monitor-left; | ||
| 870 | "Mod+Control+T".action = focus-monitor-down; | ||
| 871 | "Mod+Control+N".action = focus-monitor-up; | ||
| 872 | "Mod+Control+S".action = focus-monitor-right; | ||
| 873 | |||
| 874 | "Mod+Shift+Control+H".action = move-workspace-to-monitor-left; | ||
| 875 | "Mod+Shift+Control+T".action = move-workspace-to-monitor-down; | ||
| 876 | "Mod+Shift+Control+N".action = move-workspace-to-monitor-up; | ||
| 877 | "Mod+Shift+Control+S".action = move-workspace-to-monitor-right; | ||
| 878 | |||
| 879 | "Mod+G".action = focus-adjacent-workspace "down"; | ||
| 880 | "Mod+C".action = focus-adjacent-workspace "up"; | ||
| 881 | |||
| 882 | "Mod+Shift+G".action = move-column-to-adjacent-workspace "down"; | ||
| 883 | "Mod+Shift+C".action = move-column-to-adjacent-workspace "up"; | ||
| 884 | |||
| 885 | "Mod+Shift+Control+G".action = move-workspace-down; | ||
| 886 | "Mod+Shift+Control+C".action = move-workspace-up; | ||
| 887 | |||
| 888 | "Mod+ParenLeft".action = focus-workspace "comm"; | ||
| 889 | "Mod+Shift+ParenLeft".action = kdl.magic-leaf "move-column-to-workspace" "comm"; | ||
| 890 | |||
| 891 | "Mod+ParenRight".action = focus-workspace "web"; | ||
| 892 | "Mod+Shift+ParenRight".action = kdl.magic-leaf "move-column-to-workspace" "web"; | ||
| 893 | |||
| 894 | "Mod+BraceRight".action = focus-workspace "read"; | ||
| 895 | "Mod+Shift+BraceRight".action = kdl.magic-leaf "move-column-to-workspace" "read"; | ||
| 896 | |||
| 897 | "Mod+BraceLeft".action = focus-workspace "mon"; | ||
| 898 | "Mod+Shift+BraceLeft".action = kdl.magic-leaf "move-column-to-workspace" "mon"; | ||
| 899 | |||
| 900 | "Mod+Asterisk".action = focus-workspace "vid"; | ||
| 901 | "Mod+Shift+Asterisk".action = kdl.magic-leaf "move-column-to-workspace" "vid"; | ||
| 902 | |||
| 903 | "Mod+Plus".action = with-unnamed-workspace-action ''{"Action":{"FocusWorkspace":{"reference":{"Id": .id}}}}''; | ||
| 904 | "Mod+Shift+Plus".action = with-unnamed-workspace-action ''{"Action":{"MoveColumnToWorkspace":{"reference":{"Id": .id}, "focus": true}}}''; | ||
| 905 | |||
| 906 | "Mod+M".action = consume-or-expel-window-left; | ||
| 907 | "Mod+W".action = consume-or-expel-window-right; | ||
| 908 | |||
| 909 | "Mod+Shift+M".action = toggle-column-tabbed-display; | ||
| 910 | |||
| 911 | "Mod+R".action = switch-preset-column-width; | ||
| 912 | "Mod+Shift+R".action = maximize-column; | ||
| 913 | "Mod+Shift+Ctrl+R".action = switch-preset-window-height; | ||
| 914 | "Mod+F".action = center-column; | ||
| 915 | "Mod+Shift+F".action = toggle-windowed-fullscreen; | ||
| 916 | "Mod+Ctrl+Shift+F".action = fullscreen-window; | ||
| 917 | |||
| 918 | "Mod+V".action = switch-focus-between-floating-and-tiling; | ||
| 919 | "Mod+Shift+V".action = toggle-window-floating; | ||
| 920 | |||
| 921 | "Mod+Left".action = set-column-width "-10%"; | ||
| 922 | "Mod+Down".action = set-window-height "-10%"; | ||
| 923 | "Mod+Up".action = set-window-height "+10%"; | ||
| 924 | "Mod+Right".action = set-column-width "+10%"; | ||
| 925 | |||
| 926 | "Mod+Shift+Z" = { | ||
| 927 | action = spawn (lib.getExe niri) "msg" "action" "power-off-monitors"; | ||
| 928 | allow-when-locked = true; | ||
| 929 | }; | ||
| 930 | "Mod+Shift+L".action = spawn loginctl "lock-session"; | ||
| 931 | "Mod+Shift+E".action = quit; | ||
| 932 | "Mod+Shift+Minus" = { | ||
| 933 | action = spawn systemctl "suspend"; | ||
| 934 | allow-when-locked = true; | ||
| 935 | }; | ||
| 936 | "Mod+Shift+Control+Minus" = { | ||
| 937 | action = spawn systemctl "hibernate"; | ||
| 938 | allow-when-locked = true; | ||
| 939 | }; | ||
| 940 | "Mod+Shift+P" = { | ||
| 941 | action = spawn (lib.getExe pkgs.playerctl) "-a" "pause"; | ||
| 942 | allow-when-locked = true; | ||
| 943 | }; | ||
| 944 | |||
| 945 | "XF86MonBrightnessUp" = { | ||
| 946 | action = spawn swayosd-client "--brightness" "raise"; | ||
| 947 | allow-when-locked = true; | ||
| 948 | }; | ||
| 949 | "XF86MonBrightnessDown" = { | ||
| 950 | action = spawn swayosd-client "--brightness" "lower"; | ||
| 951 | allow-when-locked = true; | ||
| 952 | }; | ||
| 953 | "XF86AudioRaiseVolume" = { | ||
| 954 | action = spawn swayosd-client "--output-volume" "raise"; | ||
| 955 | allow-when-locked = true; | ||
| 956 | }; | ||
| 957 | "XF86AudioLowerVolume" = { | ||
| 958 | action = spawn swayosd-client "--output-volume" "lower"; | ||
| 959 | allow-when-locked = true; | ||
| 960 | }; | ||
| 961 | "XF86AudioMute" = { | ||
| 962 | action = spawn swayosd-client "--output-volume" "mute-toggle"; | ||
| 963 | allow-when-locked = true; | ||
| 964 | }; | ||
| 965 | "XF86AudioMicMute" = { | ||
| 966 | action = spawn swayosd-client "--input-volume" "mute-toggle"; | ||
| 967 | allow-when-locked = true; | ||
| 968 | }; | ||
| 969 | |||
| 970 | "Mod+Semicolon".action = spawn makoctl "dismiss" "--group"; | ||
| 971 | "Mod+Shift+Semicolon".action = spawn makoctl "dismiss" "--all"; | ||
| 972 | "Mod+Period".action = spawn makoctl "menu" "--" (lib.getExe config.programs.fuzzel.package) "--dmenu"; | ||
| 973 | "Mod+Comma".action = spawn makoctl "restore"; | ||
| 974 | |||
| 975 | "Mod+Control+W".action = with-empty-unnamed-workspace-action "{\"Action\":{\"FocusWorkspace\":{\"reference\":{\"Id\": $workspace_id}}}}"; | ||
| 976 | "Mod+Control+Shift+W".action = with-empty-unnamed-workspace-action "{\"Action\":{\"MoveColumnToWorkspace\":{\"reference\":{\"Id\": $workspace_id}, \"focus\": true}}}"; | ||
| 977 | |||
| 978 | "Mod+X".action = set-dynamic-cast-window; | ||
| 979 | "Mod+Shift+X".action = set-dynamic-cast-monitor; | ||
| 980 | "Mod+Control+Shift+X".action = clear-dynamic-cast-target; | ||
| 981 | |||
| 982 | "Mod+D".action = with-urgent-window-action "{\"Action\":{\"FocusWindow\":{\"id\": .id}}}"; | ||
| 983 | "Mod+Shift+D".action = with-focused-window-action "{\"Action\":{\"UnsetUrgent\":{\"id\": .id}}}"; | ||
| 984 | |||
| 985 | "Mod+K".action = spawn (lib.getExe' pkgs.worktime "worktime-ui"); | ||
| 986 | "Mod+Shift+K".action = spawn (lib.getExe' pkgs.worktime "worktime-stop"); | ||
| 987 | })) | ||
| 988 | (map ({ name, selector, spawn, key, ...}: if key != null && selector != null && spawn != null then bind key { action = focus-or-spawn-action selector name spawn; } else null) cfg.scratchspaces) | ||
| 989 | (map ({ name, moveKey, ...}: if moveKey != null then bind moveKey { action = kdl.magic-leaf "move-column-to-workspace" name; } else null) cfg.scratchspaces) | ||
| 990 | ] | ||
| 991 | )) | ||
| 992 | ]; | ||
| 993 | }; | ||
| 994 | } | ||
