diff options
Diffstat (limited to 'accounts/gkleen@sif/niri/mako.nix')
-rw-r--r-- | accounts/gkleen@sif/niri/mako.nix | 115 |
1 files changed, 115 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..0a10555a --- /dev/null +++ b/accounts/gkleen@sif/niri/mako.nix | |||
@@ -0,0 +1,115 @@ | |||
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 | package = pkgs.symlinkJoin { | ||
34 | name = "${pkgs.mako.name}-wrapped"; | ||
35 | paths = with pkgs; [ mako ]; | ||
36 | inherit (pkgs.mako) meta; | ||
37 | postBuild = '' | ||
38 | rm -r $out/share/dbus-1 | ||
39 | ''; | ||
40 | }; | ||
41 | }; | ||
42 | systemd.user.services.mako = { | ||
43 | Unit = { | ||
44 | Description = "Mako notification daemon"; | ||
45 | PartOf = [ "graphical-session.target" ]; | ||
46 | }; | ||
47 | Install = { | ||
48 | WantedBy = [ "graphical-session.target" ]; | ||
49 | }; | ||
50 | Service = { | ||
51 | Type = "dbus"; | ||
52 | BusName = "org.freedesktop.Notifications"; | ||
53 | ExecStart = lib.getExe config.services.mako.package; | ||
54 | RestartSec = 5; | ||
55 | Restart = "always"; | ||
56 | }; | ||
57 | }; | ||
58 | |||
59 | systemd.user.services.mako-follows-focus = { | ||
60 | Unit = { | ||
61 | BindsTo = [ "niri.service" "mako.service" ]; | ||
62 | After = [ "niri.service" "mako.service" ]; | ||
63 | }; | ||
64 | Service = { | ||
65 | Type = "simple"; | ||
66 | Restart = "always"; | ||
67 | ExecStart = pkgs.writers.writePython3 "mako-follows-focus" { | ||
68 | libraries = with pkgs.python3Packages; []; | ||
69 | } '' | ||
70 | import os | ||
71 | import socket | ||
72 | import json | ||
73 | import subprocess | ||
74 | |||
75 | |||
76 | current_output = None | ||
77 | workspaces = [] | ||
78 | |||
79 | |||
80 | def output_changed(new_output): | ||
81 | global current_output | ||
82 | |||
83 | if current_output == new_output: | ||
84 | return | ||
85 | |||
86 | current_output = new_output | ||
87 | subprocess.run(["makoctl", "reload"]) | ||
88 | |||
89 | |||
90 | sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | ||
91 | sock.connect(os.environ["NIRI_SOCKET"]) | ||
92 | sock.send(b"\"EventStream\"\n") | ||
93 | for line in sock.makefile(buffering=1, encoding='utf-8'): | ||
94 | if line_json := json.loads(line): | ||
95 | if "WorkspacesChanged" in line_json: | ||
96 | workspaces = line_json["WorkspacesChanged"]["workspaces"] | ||
97 | for workspace in workspaces: | ||
98 | if not workspace["is_focused"]: | ||
99 | continue | ||
100 | output_changed(workspace["output"]) | ||
101 | break | ||
102 | if "WorkspaceActivated" in line_json and line_json["WorkspaceActivated"]["focused"]: # noqa: E501 | ||
103 | for workspace in workspaces: | ||
104 | if not workspace["id"] == line_json["WorkspaceActivated"]["id"]: # noqa: E501 | ||
105 | continue | ||
106 | output_changed(workspace["output"]) | ||
107 | break | ||
108 | ''; | ||
109 | }; | ||
110 | Install = { | ||
111 | WantedBy = [ "mako.service" ]; | ||
112 | }; | ||
113 | }; | ||
114 | }; | ||
115 | } | ||