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