summaryrefslogtreecommitdiff
path: root/accounts/gkleen@sif/niri/waybar.nix
diff options
context:
space:
mode:
Diffstat (limited to 'accounts/gkleen@sif/niri/waybar.nix')
-rw-r--r--accounts/gkleen@sif/niri/waybar.nix358
1 files changed, 358 insertions, 0 deletions
diff --git a/accounts/gkleen@sif/niri/waybar.nix b/accounts/gkleen@sif/niri/waybar.nix
new file mode 100644
index 00000000..c02a9a76
--- /dev/null
+++ b/accounts/gkleen@sif/niri/waybar.nix
@@ -0,0 +1,358 @@
1{ lib, config, pkgs, ... }:
2let
3 swayosd-client = lib.getExe' config.services.swayosd.package "swayosd-client";
4in {
5 config = {
6 programs.waybar = {
7 enable = true;
8 systemd = {
9 enable = true;
10 target = "graphical-session.target";
11 };
12 settings = let
13 windowRewrites = {
14 "(.*) — Mozilla Firefox" = "$1";
15 "(.*) - Mozilla Thunderbird" = "$1";
16 "(.*) - mpv" = "$1";
17 };
18 iconSize = 11;
19 in [
20 {
21 layer = "top";
22 position = "top";
23 height = 21;
24 output = [ "eDP-1" "DP-2" "DP-3" ];
25 modules-left = [ "niri/workspaces" ];
26 modules-center = [ "niri/window" ];
27 modules-right = [ "custom/worktime" "custom/worktime-today"
28 "custom/weather"
29 "custom/keymap"
30 "privacy" "tray" "wireplumber" "backlight" "battery" "idle_inhibitor" "custom/mako" "custom/lid_inhibitor" "clock" ];
31
32 "custom/lid_inhibitor" = {
33 format = "{}";
34 return-type = "json";
35 exec = lib.getExe pkgs.waybar-systemd-inhibit;
36 on-click = lib.getExe' pkgs.waybar-systemd-inhibit "waybar-systemd-inhibit-toggle";
37 };
38 "custom/mako" = {
39 format = "{}";
40 return-type = "json";
41 exec = pkgs.writers.writePython3 "mako-silent" { libraries = [ pkgs.python3Packages.dbus-next ]; } ''
42 from dbus_next.aio import MessageBus
43
44 import asyncio
45
46 import json
47
48
49 loop = asyncio.new_event_loop()
50 asyncio.set_event_loop(loop)
51
52
53 async def main():
54 bus = await MessageBus().connect()
55 # the introspection xml would normally be included in your project, but
56 # this is convenient for development
57 introspection = await bus.introspect('org.freedesktop.Notifications', '/fr/emersion/Mako') # noqa: E501
58
59 obj = bus.get_proxy_object('org.freedesktop.Notifications', '/fr/emersion/Mako', introspection) # noqa: E501
60 mako = obj.get_interface('fr.emersion.Mako')
61 properties = obj.get_interface('org.freedesktop.DBus.Properties')
62
63 async def print_mode():
64 modes = await mako.get_modes()
65 is_silent = "silent" in modes
66 icon = "󰂛" if is_silent else "󰂚"
67 text = f"<span font=\"Symbols Nerd Font Mono\" size=\"90%\">{icon}</span>" # noqa: E501
68 if is_silent:
69 text = f"<span color=\"#ffffff\">{text}</span>"
70 print(json.dumps({'text': text, 'tooltip': ', '.join(modes)}, separators=(',', ':')), flush=True) # noqa: E501
71
72 async def on_properties_changed(interface_name, changed_properties, invalidated_properties): # noqa: E501
73 if "Modes" not in invalidated_properties:
74 return
75
76 await print_mode()
77
78 properties.on_properties_changed(on_properties_changed)
79 await print_mode()
80
81 await loop.create_future()
82
83
84 loop.run_until_complete(main())
85 '';
86 on-click = "makoctl mode -t silent";
87 };
88 "custom/weather" = {
89 format = "{}";
90 tooltip = true;
91 interval = 3600;
92 exec = "${lib.getExe pkgs.wttrbar} --hide-conditions --nerd --custom-indicator \"<span font=\\\"Symbols Nerd Font Mono\\\" size=\\\"100%\\\">{ICON}</span> {FeelsLikeC}°\"";
93 return-type = "json";
94 };
95 "custom/keymap" = {
96 format = "{}";
97 tooltip = true;
98 return-type = "json";
99 exec = pkgs.writers.writePython3 "keymap" {} ''
100 import os
101 import socket
102 import json
103
104
105 def output(keymap):
106 short = keymap
107 if keymap == "English (programmer Dvorak)":
108 short = "dvp"
109 elif keymap == "English (US)":
110 short = "<span color=\"#ffffff\">us</span>"
111 print(json.dumps({'text': short, 'tooltip': keymap}, separators=(',', ':')), flush=True) # noqa: E501
112
113
114 keyboard_layouts = []
115
116 sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
117 sock.connect(os.environ["NIRI_SOCKET"])
118 sock.send(b"\"EventStream\"\n")
119 for line in sock.makefile(buffering=1, encoding='utf-8'):
120 if line_json := json.loads(line):
121 if "KeyboardLayoutsChanged" in line_json:
122 keyboard_layouts = line_json["KeyboardLayoutsChanged"]["keyboard_layouts"]["names"] # noqa: E501
123 output(keyboard_layouts[line_json["KeyboardLayoutsChanged"]["keyboard_layouts"]["current_idx"]]) # noqa: E501
124 if "KeyboardLayoutSwitched" in line_json:
125 output(keyboard_layouts[line_json["KeyboardLayoutSwitched"]["idx"]]) # noqa: E501
126 '';
127 on-click = "niri msg action switch-layout next";
128 };
129 "custom/worktime" = {
130 interval = 60;
131 exec = "${lib.getExe pkgs.worktime} time --waybar";
132 return-type = "json";
133 };
134 "custom/worktime-today" = {
135 interval = 60;
136 exec = "${lib.getExe pkgs.worktime} today --waybar";
137 return-type = "json";
138 };
139 "niri/workspaces" = {
140 ignore = map ({ name, ... }: name) config.programs.niri.scratchspaces;
141 };
142 "niri/window" = {
143 separate-outputs = true;
144 icon = true;
145 icon-size = 14;
146 rewrite = windowRewrites;
147 };
148 clock = {
149 interval = 1;
150 # timezone = "Europe/Berlin";
151 format = "W{:%V-%u %F %H:%M:%S%Ez}";
152 tooltip-format = "<tt><small>{calendar}</small></tt>";
153 calendar = {
154 mode = "year";
155 mode-mon-col = 3;
156 weeks-pos = "left";
157 on-scroll = 1;
158 format = {
159 months = "<span color='#ffead3'><b>{}</b></span>";
160 days = "{}";
161 weeks = "<span color='#99ffdd'><b>{}</b></span>";
162 weekdays = "<span color='#ffcc66'><b>{}</b></span>";
163 today = "<span color='#ff6699'><b>{}</b></span>";
164 };
165 };
166 };
167 battery = {
168 format = "<span font=\"Symbols Nerd Font Mono\" size=\"90%\">{icon}</span>";
169 icon-size = iconSize - 2;
170 states = { warning = 30; critical = 15; };
171 format-icons = ["&#xf008e;" "&#xf007a;" "&#xf007b;" "&#xf007c;" "&#xf007d;" "&#xf007e;" "&#xf007f;" "&#xf0080;" "&#xf0081;" "&#xf0082;" "&#xf0079;" ];
172 format-charging = "&#xf0084;";
173 format-plugged = "&#xf06a5;";
174 tooltip-format = "{capacity}% {timeTo}";
175 interval = 20;
176 };
177 tray = {
178 icon-size = 16;
179 # show-passive-items = true;
180 spacing = 1;
181 };
182 privacy = {
183 icon-spacing = 7;
184 icon-size = iconSize;
185 modules = [
186 { type = "screenshare"; }
187 { type = "audio-in"; }
188 ];
189 };
190 idle_inhibitor = {
191 format = "<span font=\"Symbols Nerd Font Mono\" size=\"90%\">{icon}</span>";
192 icon-size = iconSize;
193 format-icons = { activated = "&#xf0208;"; deactivated = "&#xf0209;"; };
194 timeout = 120;
195 };
196 backlight = {
197 format = "<span font=\"Symbols Nerd Font Mono\" size=\"90%\">{icon}</span>";
198 icon-size = iconSize;
199 tooltip-format = "{percent}%";
200 format-icons = ["&#xf00da;" "&#xf00db;" "&#xf00dc;" "&#xf00dd;" "&#xf00de;" "&#xf00df;" "&#xf00e0;"];
201 on-scroll-up = "${swayosd-client} --brightness raise";
202 on-scroll-down = "${swayosd-client} --brightness lower";
203 };
204 wireplumber = {
205 format = "<span font=\"Symbols Nerd Font Mono\" size=\"90%\">{icon}</span>";
206 icon-size = iconSize;
207 tooltip-format = "{volume}% {node_name}";
208 format-icons = ["&#xf057f;" "&#xf0580;" "&#xf057e;"];
209 format-muted = "<span font=\"Symbols Nerd Font Mono\" size=\"90%\">&#xf075f;</span>";
210 # ignored-sinks = ["Easy Effects Sink"];
211 on-scroll-up = "${swayosd-client} --output-volume raise";
212 on-scroll-down = "${swayosd-client} --output-volume lower";
213 on-click = "${swayosd-client} --output-volume mute-toggle";
214 };
215 }
216 {
217 layer = "top";
218 position = "top";
219 height = 14;
220 output = [ "!eDP-1" "!DP-2" "!DP-3" "*" ];
221 modules-left = [ "niri/workspaces" ];
222 modules-center = [ "niri/window" ];
223 modules-right = [ "clock" ];
224
225 "niri/workspaces" = {
226 ignore = map ({ name, ... }: name) config.programs.niri.scratchspaces;
227 };
228 "niri/window" = {
229 separate-outputs = true;
230 icon = true;
231 icon-size = 14;
232 rewrite = windowRewrites;
233 };
234 clock = {
235 interval = 1;
236 # timezone = "Europe/Berlin";
237 format = "{:%H:%M}";
238 tooltip-format = "W{:%V-%u %F %H:%M:%S%Ez}";
239 };
240 }
241 ];
242 style = ''
243 @define-color white #ffffff;
244 @define-color grey #555555;
245 @define-color blue #1a8fff;
246 @define-color green #23fd00;
247 @define-color orange #f28a21;
248 @define-color red #f2201f;
249
250 * {
251 border: none;
252 font-family: "Fira Sans";
253 font-size: 10pt;
254 min-height: 0;
255 }
256
257 window#waybar {
258 background-color: rgba(0, 0, 0, 0.66);
259 color: @white;
260 }
261
262 .modules-left {
263 margin-left: 38px;
264 }
265 .modules-right {
266 margin-right: 38px;
267 }
268
269 .module {
270 margin: 0 5px;
271 }
272
273 #workspaces button {
274 color: @white;
275 padding: 2px 5px;
276 }
277 #workspaces button.empty {
278 color: @grey;
279 }
280 #workspaces button.active {
281 color: @green;
282 }
283 #workspaces button.urgent {
284 color: @red;
285 }
286
287 #custom-weather, #custom-keymap, #custom-worktime, #custom-worktime-today {
288 color: @grey;
289 margin: 0 5px;
290 }
291 #custom-weather {
292 margin-right: 3px;
293 }
294 #custom-keymap {
295 margin-left: 3px;
296 margin-right: 3px;
297 }
298
299 #tray {
300 margin: 0;
301 }
302 #battery, #idle_inhibitor, #backlight, #wireplumber, #custom-mako, #custom-lid_inhibitor {
303 color: @grey;
304 margin: 0 5px 0 2px;
305 }
306 #idle_inhibitor {
307 margin-right: 4px;
308 margin-left: 6px;
309 }
310 #custom-mako {
311 margin-right: 4px;
312 margin-left: 3px;
313 }
314 #custom-lid_inhibitor {
315 margin-right: 3px;
316 margin-left: 3px;
317 }
318 #battery {
319 margin-right: 3px;
320 }
321 #battery.discharging {
322 color: @white;
323 }
324 #battery.warning {
325 color: @orange;
326 }
327 #battery.critical {
328 color: @red;
329 }
330 #battery.charging {
331 color: @white;
332 }
333 #idle_inhibitor.activated {
334 color: @white;
335 }
336 #custom-worktime.running, #custom-worktime-today.running {
337 color: @white;
338 }
339 #custom-worktime.over, #custom-worktime-today.over {
340 color: @orange;
341 }
342
343 #idle_inhibitor, #custom-lid_inhibitor {
344 padding-top: 1px;
345 }
346
347 #privacy {
348 color: @red;
349 margin: -1px 4px 0px 3px;
350 }
351 #clock {
352 /* margin-right: 5px; */
353 font-feature-settings: "tnum";
354 }
355 '';
356 };
357 };
358}