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