diff options
Diffstat (limited to 'accounts/gkleen@sif/niri/mako.nix')
-rw-r--r-- | accounts/gkleen@sif/niri/mako.nix | 113 |
1 files changed, 113 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..eba26caa --- /dev/null +++ b/accounts/gkleen@sif/niri/mako.nix | |||
@@ -0,0 +1,113 @@ | |||
1 | { config, lib, pkgs, ... }: | ||
2 | { | ||
3 | config = { | ||
4 | services.mako = { | ||
5 | enable = true; | ||
6 | settings = { | ||
7 | font = "Fira Sans 10"; | ||
8 | format = "<i>%s</i>\\n%b"; | ||
9 | margin = "2"; | ||
10 | max-visible = -1; | ||
11 | background-color = "#000000dd"; | ||
12 | progress-color = "source #223544ff"; | ||
13 | width = 384; | ||
14 | outer-margin = 1; | ||
15 | max-history = 100; | ||
16 | max-icon-size = 48; | ||
17 | }; | ||
18 | criteria = { | ||
19 | grouped.format = "<b>(%g)</b> <i>%s</i>\\n%b"; | ||
20 | "urgency=low".text-color = "#999999ff"; | ||
21 | "urgency=critical".background-color = "#900000dd"; | ||
22 | "app-name=Element".group-by = "summary"; | ||
23 | "app-name=poweralertd" = { | ||
24 | history = false; | ||
25 | ignore-timeout = true; | ||
26 | default-timeout = 2000; | ||
27 | }; | ||
28 | "app-name=worktime".history = false; | ||
29 | "mode=silent".invisible = true; | ||
30 | }; | ||
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 | }; | ||
39 | }; | ||
40 | systemd.user.services.mako = { | ||
41 | Unit = { | ||
42 | Description = "Mako notification daemon"; | ||
43 | PartOf = [ "graphical-session.target" ]; | ||
44 | }; | ||
45 | Install = { | ||
46 | WantedBy = [ "graphical-session.target" ]; | ||
47 | }; | ||
48 | Service = { | ||
49 | Type = "dbus"; | ||
50 | BusName = "org.freedesktop.Notifications"; | ||
51 | ExecStart = lib.getExe config.services.mako.package; | ||
52 | RestartSec = 5; | ||
53 | Restart = "always"; | ||
54 | }; | ||
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 | }; | ||
112 | }; | ||
113 | } | ||