diff options
| author | Gregor Kleen <gkleen@yggdrasil.li> | 2025-01-24 13:03:27 +0100 |
|---|---|---|
| committer | Gregor Kleen <gkleen@yggdrasil.li> | 2025-01-24 13:03:27 +0100 |
| commit | 8507fad62ca2f06e40f4e849bb8edaa6456c87ef (patch) | |
| tree | a707ffa594e37edeb1eb0f2f46daec2079b3b2e7 /accounts | |
| parent | cb21d812938fadb6f3eb7571cd3f7d783d85297e (diff) | |
| download | nixos-8507fad62ca2f06e40f4e849bb8edaa6456c87ef.tar nixos-8507fad62ca2f06e40f4e849bb8edaa6456c87ef.tar.gz nixos-8507fad62ca2f06e40f4e849bb8edaa6456c87ef.tar.bz2 nixos-8507fad62ca2f06e40f4e849bb8edaa6456c87ef.tar.xz nixos-8507fad62ca2f06e40f4e849bb8edaa6456c87ef.zip | |
...
Diffstat (limited to 'accounts')
| -rw-r--r-- | accounts/gkleen@sif/niri/mako.nix | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/accounts/gkleen@sif/niri/mako.nix b/accounts/gkleen@sif/niri/mako.nix index 901ed022..e06d3b3a 100644 --- a/accounts/gkleen@sif/niri/mako.nix +++ b/accounts/gkleen@sif/niri/mako.nix | |||
| @@ -47,5 +47,61 @@ | |||
| 47 | Restart = "always"; | 47 | Restart = "always"; |
| 48 | }; | 48 | }; |
| 49 | }; | 49 | }; |
| 50 | |||
| 51 | systemd.user.services.mako-follows-focus = { | ||
| 52 | Unit = { | ||
| 53 | BindsTo = [ "niri.service" "mako.service" ]; | ||
| 54 | After = [ "niri.service" "mako.service" ]; | ||
| 55 | }; | ||
| 56 | Service = { | ||
| 57 | Type = "simple"; | ||
| 58 | Restart = "always"; | ||
| 59 | ExecStart = pkgs.writers.writePython3 "mako-follows-focus" { | ||
| 60 | libraries = with pkgs.python3Packages; []; | ||
| 61 | } '' | ||
| 62 | import os | ||
| 63 | import socket | ||
| 64 | import json | ||
| 65 | import subprocess | ||
| 66 | |||
| 67 | |||
| 68 | current_output = None | ||
| 69 | workspaces = [] | ||
| 70 | |||
| 71 | |||
| 72 | def output_changed(new_output): | ||
| 73 | global current_output | ||
| 74 | |||
| 75 | if current_output == new_output: | ||
| 76 | return | ||
| 77 | |||
| 78 | current_output = new_output | ||
| 79 | subprocess.run(["makoctl", "reload"]) | ||
| 80 | |||
| 81 | |||
| 82 | sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | ||
| 83 | sock.connect(os.environ["NIRI_SOCKET"]) | ||
| 84 | sock.send(b"\"EventStream\"\n") | ||
| 85 | for line in sock.makefile(buffering=1, encoding='utf-8'): | ||
| 86 | if line_json := json.loads(line): | ||
| 87 | if "WorkspacesChanged" in line_json: | ||
| 88 | workspaces = line_json["WorkspacesChanged"]["workspaces"] | ||
| 89 | for workspace in workspaces: | ||
| 90 | if not workspace["is_focused"]: | ||
| 91 | continue | ||
| 92 | output_changed(workspace["output"]) | ||
| 93 | break | ||
| 94 | if "WorkspaceActivated" in line_json and line_json["WorkspaceActivated"]["focused"]: # noqa: E501 | ||
| 95 | for workspace in workspaces: | ||
| 96 | if not workspace["id"] == line_json["WorkspaceActivated"]["id"]: # noqa: E501 | ||
| 97 | continue | ||
| 98 | output_changed(workspace["output"]) | ||
| 99 | break | ||
| 100 | ''; | ||
| 101 | }; | ||
| 102 | Install = { | ||
| 103 | WantedBy = [ "mako.service" ]; | ||
| 104 | }; | ||
| 105 | }; | ||
| 50 | }; | 106 | }; |
| 51 | } | 107 | } |
