diff options
Diffstat (limited to 'accounts/gkleen@sif/niri/mako.nix')
-rw-r--r-- | accounts/gkleen@sif/niri/mako.nix | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/accounts/gkleen@sif/niri/mako.nix b/accounts/gkleen@sif/niri/mako.nix new file mode 100644 index 00000000..8fbc81c1 --- /dev/null +++ b/accounts/gkleen@sif/niri/mako.nix | |||
@@ -0,0 +1,107 @@ | |||
1 | { config, lib, pkgs, ... }: | ||
2 | { | ||
3 | config = { | ||
4 | services.mako = { | ||
5 | enable = true; | ||
6 | font = "Fira Sans 10"; | ||
7 | format = "<i>%s</i>\\n%b"; | ||
8 | margin = "2"; | ||
9 | maxVisible = -1; | ||
10 | backgroundColor = "#000000dd"; | ||
11 | progressColor = "source #223544ff"; | ||
12 | width = 384; | ||
13 | extraConfig = '' | ||
14 | outer-margin=1 | ||
15 | max-history=100 | ||
16 | max-icon-size=48 | ||
17 | |||
18 | [grouped] | ||
19 | format=<b>(%g)</b> <i>%s</i>\n%b | ||
20 | |||
21 | [urgency=low] | ||
22 | text-color=#999999ff | ||
23 | |||
24 | [urgency=critical] | ||
25 | background-color=#900000dd | ||
26 | |||
27 | [app-name=Element] | ||
28 | group-by=summary | ||
29 | |||
30 | [mode=silent] | ||
31 | invisible=1 | ||
32 | ''; | ||
33 | }; | ||
34 | systemd.user.services.mako = { | ||
35 | Unit = { | ||
36 | Description = "Mako notification daemon"; | ||
37 | PartOf = [ "graphical-session.target" ]; | ||
38 | }; | ||
39 | Install = { | ||
40 | WantedBy = [ "graphical-session.target" ]; | ||
41 | }; | ||
42 | Service = { | ||
43 | Type = "dbus"; | ||
44 | BusName = "org.freedesktop.Notifications"; | ||
45 | ExecStart = lib.getExe config.services.mako.package; | ||
46 | RestartSec = 5; | ||
47 | Restart = "always"; | ||
48 | }; | ||
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 | }; | ||
106 | }; | ||
107 | } | ||