diff options
Diffstat (limited to 'accounts/gkleen@sif/niri/mako.nix')
-rw-r--r-- | accounts/gkleen@sif/niri/mako.nix | 117 |
1 files changed, 90 insertions, 27 deletions
diff --git a/accounts/gkleen@sif/niri/mako.nix b/accounts/gkleen@sif/niri/mako.nix index 8abf14d8..eba26caa 100644 --- a/accounts/gkleen@sif/niri/mako.nix +++ b/accounts/gkleen@sif/niri/mako.nix | |||
@@ -1,34 +1,41 @@ | |||
1 | { config, lib, ... }: | 1 | { config, lib, pkgs, ... }: |
2 | { | 2 | { |
3 | config = { | 3 | config = { |
4 | services.mako = { | 4 | services.mako = { |
5 | enable = true; | 5 | enable = true; |
6 | font = "Fira Sans 10"; | 6 | settings = { |
7 | format = "<i>%s</i>\\n%b"; | 7 | font = "Fira Sans 10"; |
8 | margin = "2"; | 8 | format = "<i>%s</i>\\n%b"; |
9 | maxVisible = -1; | 9 | margin = "2"; |
10 | backgroundColor = "#000000dd"; | 10 | max-visible = -1; |
11 | progressColor = "source #223544ff"; | 11 | background-color = "#000000dd"; |
12 | width = 384; | 12 | progress-color = "source #223544ff"; |
13 | extraConfig = '' | 13 | width = 384; |
14 | outer-margin=1 | 14 | outer-margin = 1; |
15 | max-history=100 | 15 | max-history = 100; |
16 | 16 | max-icon-size = 48; | |
17 | [grouped] | 17 | }; |
18 | format=<b>(%g)</b> <i>%s</i>\n%b | 18 | criteria = { |
19 | 19 | grouped.format = "<b>(%g)</b> <i>%s</i>\\n%b"; | |
20 | [urgency=low] | 20 | "urgency=low".text-color = "#999999ff"; |
21 | text-color=#999999ff | 21 | "urgency=critical".background-color = "#900000dd"; |
22 | 22 | "app-name=Element".group-by = "summary"; | |
23 | [urgency=critical] | 23 | "app-name=poweralertd" = { |
24 | background-color=#900000dd | 24 | history = false; |
25 | 25 | ignore-timeout = true; | |
26 | [app-name=Element] | 26 | default-timeout = 2000; |
27 | group-by=summary | 27 | }; |
28 | 28 | "app-name=worktime".history = false; | |
29 | [mode=silent] | 29 | "mode=silent".invisible = true; |
30 | invisible=1 | 30 | }; |
31 | ''; | 31 | package = pkgs.symlinkJoin { |
32 | name = "${pkgs.mako.name}-wrapped"; | ||
33 | paths = with pkgs; [ mako ]; | ||
34 | inherit (pkgs.mako) meta; | ||
35 | postBuild = '' | ||
36 | rm -r $out/share/dbus-1 | ||
37 | ''; | ||
38 | }; | ||
32 | }; | 39 | }; |
33 | systemd.user.services.mako = { | 40 | systemd.user.services.mako = { |
34 | Unit = { | 41 | Unit = { |
@@ -46,5 +53,61 @@ | |||
46 | Restart = "always"; | 53 | Restart = "always"; |
47 | }; | 54 | }; |
48 | }; | 55 | }; |
56 | |||
57 | systemd.user.services.mako-follows-focus = { | ||
58 | Unit = { | ||
59 | BindsTo = [ "niri.service" "mako.service" ]; | ||
60 | After = [ "niri.service" "mako.service" ]; | ||
61 | }; | ||
62 | Service = { | ||
63 | Type = "simple"; | ||
64 | Restart = "always"; | ||
65 | ExecStart = pkgs.writers.writePython3 "mako-follows-focus" { | ||
66 | libraries = with pkgs.python3Packages; []; | ||
67 | } '' | ||
68 | import os | ||
69 | import socket | ||
70 | import json | ||
71 | import subprocess | ||
72 | |||
73 | |||
74 | current_output = None | ||
75 | workspaces = [] | ||
76 | |||
77 | |||
78 | def output_changed(new_output): | ||
79 | global current_output | ||
80 | |||
81 | if current_output == new_output: | ||
82 | return | ||
83 | |||
84 | current_output = new_output | ||
85 | subprocess.run(["makoctl", "reload"]) | ||
86 | |||
87 | |||
88 | sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | ||
89 | sock.connect(os.environ["NIRI_SOCKET"]) | ||
90 | sock.send(b"\"EventStream\"\n") | ||
91 | for line in sock.makefile(buffering=1, encoding='utf-8'): | ||
92 | if line_json := json.loads(line): | ||
93 | if "WorkspacesChanged" in line_json: | ||
94 | workspaces = line_json["WorkspacesChanged"]["workspaces"] | ||
95 | for workspace in workspaces: | ||
96 | if not workspace["is_focused"]: | ||
97 | continue | ||
98 | output_changed(workspace["output"]) | ||
99 | break | ||
100 | if "WorkspaceActivated" in line_json and line_json["WorkspaceActivated"]["focused"]: # noqa: E501 | ||
101 | for workspace in workspaces: | ||
102 | if not workspace["id"] == line_json["WorkspaceActivated"]["id"]: # noqa: E501 | ||
103 | continue | ||
104 | output_changed(workspace["output"]) | ||
105 | break | ||
106 | ''; | ||
107 | }; | ||
108 | Install = { | ||
109 | WantedBy = [ "mako.service" ]; | ||
110 | }; | ||
111 | }; | ||
49 | }; | 112 | }; |
50 | } | 113 | } |