diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2025-05-14 13:19:38 +0200 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2025-05-14 13:19:38 +0200 |
commit | f50a110e2120177d692b61493cb9c58f908cfff8 (patch) | |
tree | 71780c75ffda7b1ae5e3423f51a13d660d82178c | |
parent | 8daeb86bc142df356c3ab2a8591cb91fb4a113d3 (diff) | |
download | nixos-f50a110e2120177d692b61493cb9c58f908cfff8.tar nixos-f50a110e2120177d692b61493cb9c58f908cfff8.tar.gz nixos-f50a110e2120177d692b61493cb9c58f908cfff8.tar.bz2 nixos-f50a110e2120177d692b61493cb9c58f908cfff8.tar.xz nixos-f50a110e2120177d692b61493cb9c58f908cfff8.zip |
...
-rw-r--r-- | accounts/gkleen@sif/niri/default.nix | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/accounts/gkleen@sif/niri/default.nix b/accounts/gkleen@sif/niri/default.nix index 803b3a0d..7254b7ed 100644 --- a/accounts/gkleen@sif/niri/default.nix +++ b/accounts/gkleen@sif/niri/default.nix | |||
@@ -330,6 +330,69 @@ in { | |||
330 | ''; | 330 | ''; |
331 | }; | 331 | }; |
332 | }; | 332 | }; |
333 | systemd.user.services.niri-workspace-sort = { | ||
334 | Unit = { | ||
335 | BindsTo = [ "niri.service" ]; | ||
336 | After = [ "niri.service" ]; | ||
337 | }; | ||
338 | Install = { | ||
339 | WantedBy = [ "niri.service" ]; | ||
340 | }; | ||
341 | Service = { | ||
342 | Type = "simple"; | ||
343 | ExecStart = pkgs.writers.writePython3 "niri-workspace-sort" { flakeIgnore = ["E501"]; } '' | ||
344 | import os | ||
345 | import sys | ||
346 | import socket | ||
347 | import json | ||
348 | |||
349 | outputs = None | ||
350 | only = {'HDMI-A-1': {'bmr'}, 'eDP-1': {'vid'}} | ||
351 | |||
352 | with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as cmd_sock, socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock: | ||
353 | cmd_sock.connect(os.environ["NIRI_SOCKET"]) | ||
354 | with cmd_sock.makefile(mode='w', buffering=1, encoding='utf-8') as fh: | ||
355 | sock.connect(os.environ["NIRI_SOCKET"]) | ||
356 | sock.send(b"\"EventStream\"\n") | ||
357 | for line in sock.makefile(buffering=1, encoding='utf-8'): | ||
358 | workspaces = None | ||
359 | if line_json := json.loads(line): | ||
360 | if "WorkspacesChanged" in line_json: | ||
361 | workspaces = line_json["WorkspacesChanged"]["workspaces"] | ||
362 | |||
363 | if workspaces is None: | ||
364 | continue | ||
365 | |||
366 | old_outputs = outputs | ||
367 | outputs = {ws["output"] for ws in workspaces} | ||
368 | if old_outputs is None: | ||
369 | print("Initial outputs: {}".format(outputs), file=sys.stderr) | ||
370 | continue | ||
371 | |||
372 | new_outputs = outputs - old_outputs | ||
373 | if not new_outputs: | ||
374 | continue | ||
375 | print("New outputs: {}".format(new_outputs), file=sys.stderr) | ||
376 | |||
377 | relevant_workspaces = list(filter(lambda ws: (ws["name"] is not None) or (ws["active_window_id"] is not None), workspaces)) | ||
378 | target_output = next(iter(outputs - set(only.keys()))) | ||
379 | if not target_output: | ||
380 | continue | ||
381 | for ws in relevant_workspaces: | ||
382 | ws_ident = ws["name"] if ws["name"] is not None else (ws["output"], ws["idx"]) | ||
383 | if ws["output"] not in set(only.keys()): | ||
384 | continue | ||
385 | if ws_ident in only[ws["output"]]: | ||
386 | continue | ||
387 | |||
388 | print("{} -> {}".format(ws_ident, target_output), file=sys.stderr) | ||
389 | cmd = json.dumps({"Action": {"MoveWorkspaceToMonitor": {"reference": {"Id": ws["id"]}, "output": target_output}}}, separators=(',', ':')) | ||
390 | print(cmd, flush=True, file=fh) | ||
391 | ''; | ||
392 | Restart = "on-failure"; | ||
393 | RestartSec = 10; | ||
394 | }; | ||
395 | }; | ||
333 | 396 | ||
334 | programs.niri.scratchspaces = [ | 397 | programs.niri.scratchspaces = [ |
335 | { name = "pwctl"; | 398 | { name = "pwctl"; |