diff options
Diffstat (limited to 'accounts/gkleen@sif/niri/waybar.nix')
-rw-r--r-- | accounts/gkleen@sif/niri/waybar.nix | 137 |
1 files changed, 101 insertions, 36 deletions
diff --git a/accounts/gkleen@sif/niri/waybar.nix b/accounts/gkleen@sif/niri/waybar.nix index 2d00c6d8..3f1f8119 100644 --- a/accounts/gkleen@sif/niri/waybar.nix +++ b/accounts/gkleen@sif/niri/waybar.nix | |||
@@ -1,5 +1,7 @@ | |||
1 | { lib, pkgs, ... }: | 1 | { lib, config, pkgs, ... }: |
2 | { | 2 | let |
3 | swayosd-client = lib.getExe' config.services.swayosd.package "swayosd-client"; | ||
4 | in { | ||
3 | config = { | 5 | config = { |
4 | programs.waybar = { | 6 | programs.waybar = { |
5 | enable = true; | 7 | enable = true; |
@@ -22,16 +24,66 @@ | |||
22 | output = [ "eDP-1" "DP-2" "DP-3" ]; | 24 | output = [ "eDP-1" "DP-2" "DP-3" ]; |
23 | modules-left = [ "niri/workspaces" ]; | 25 | modules-left = [ "niri/workspaces" ]; |
24 | modules-center = [ "niri/window" ]; | 26 | modules-center = [ "niri/window" ]; |
25 | modules-right = [ # "custom/worktime" "custom/worktime-today" | 27 | modules-right = [ "custom/worktime" "custom/worktime-today" |
26 | "custom/weather" | 28 | "custom/weather" |
27 | # "custom/keymap" | 29 | "custom/keymap" |
28 | "privacy" "tray" "wireplumber" "backlight" "battery" "idle_inhibitor" "clock" ]; | 30 | "privacy" "tray" "wireplumber" "backlight" "battery" "idle_inhibitor" "custom/mako" "clock" ]; |
29 | 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 | }; | ||
30 | "custom/weather" = { | 82 | "custom/weather" = { |
31 | format = "{}"; | 83 | format = "{}"; |
32 | tooltip = true; | 84 | tooltip = true; |
33 | interval = 3600; | 85 | interval = 3600; |
34 | exec = "${lib.getExe pkgs.wttrbar} --hide-conditions --nerd --custom-indicator \"<span font=\\\"Symbols Nerd Font Mono\\\" size=\\\"120%\\\">{ICON}</span> {FeelsLikeC}°\""; | 86 | exec = "${lib.getExe pkgs.wttrbar} --hide-conditions --nerd --custom-indicator \"<span font=\\\"Symbols Nerd Font Mono\\\" size=\\\"100%\\\">{ICON}</span> {FeelsLikeC}°\""; |
35 | return-type = "json"; | 87 | return-type = "json"; |
36 | }; | 88 | }; |
37 | "custom/keymap" = { | 89 | "custom/keymap" = { |
@@ -41,8 +93,6 @@ | |||
41 | exec = pkgs.writers.writePython3 "keymap" {} '' | 93 | exec = pkgs.writers.writePython3 "keymap" {} '' |
42 | import os | 94 | import os |
43 | import socket | 95 | import socket |
44 | import re | ||
45 | import subprocess | ||
46 | import json | 96 | import json |
47 | 97 | ||
48 | 98 | ||
@@ -55,32 +105,34 @@ | |||
55 | print(json.dumps({'text': short, 'tooltip': keymap}, separators=(',', ':')), flush=True) # noqa: E501 | 105 | print(json.dumps({'text': short, 'tooltip': keymap}, separators=(',', ':')), flush=True) # noqa: E501 |
56 | 106 | ||
57 | 107 | ||
58 | r = subprocess.run(["hyprctl", "devices", "-j"], check=True, stdout=subprocess.PIPE, text=True) # noqa: E501 | 108 | keyboard_layouts = [] |
59 | for keyboard in json.loads(r.stdout)['keyboards']: | ||
60 | if keyboard['name'] != "at-translated-set-2-keyboard": | ||
61 | continue | ||
62 | output(keyboard['active_keymap']) | ||
63 | 109 | ||
64 | sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | 110 | sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) |
65 | sock.connect(os.environ["XDG_RUNTIME_DIR"] + "/hypr/" + os.environ["HYPRLAND_INSTANCE_SIGNATURE"] + "/.socket2.sock") # noqa: E501 | 111 | sock.connect(os.environ["NIRI_SOCKET"]) |
66 | expected = re.compile(r'^activelayout>>at-translated-set-2-keyboard,(?P<keymap>.+)$') # noqa: E501 | 112 | sock.send(b"\"EventStream\"\n") |
67 | for line in sock.makefile(buffering=1, encoding='utf-8'): | 113 | for line in sock.makefile(buffering=1, encoding='utf-8'): |
68 | if match := expected.match(line): | 114 | if line_json := json.loads(line): |
69 | output(match.group("keymap")) | 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 | ||
70 | ''; | 120 | ''; |
71 | on-click = "hyprctl switchxkblayout at-translated-set-2-keyboard next"; | 121 | on-click = "niri msg action switch-layout next"; |
72 | }; | 122 | }; |
73 | "custom/worktime" = { | 123 | "custom/worktime" = { |
74 | interval = 60; | 124 | interval = 60; |
75 | exec = lib.getExe pkgs.worktime; | 125 | exec = "${lib.getExe pkgs.worktime} time --waybar"; |
76 | tooltip = false; | 126 | return-type = "json"; |
77 | }; | 127 | }; |
78 | "custom/worktime-today" = { | 128 | "custom/worktime-today" = { |
79 | interval = 60; | 129 | interval = 60; |
80 | exec = "${lib.getExe pkgs.worktime} today"; | 130 | exec = "${lib.getExe pkgs.worktime} today --waybar"; |
81 | tooltip = false; | 131 | return-type = "json"; |
132 | }; | ||
133 | "niri/workspaces" = { | ||
134 | ignore = ["eff" "pwctl" "kpxc" "bmgr" "edit" "term"]; | ||
82 | }; | 135 | }; |
83 | "niri/workspaces" = {}; | ||
84 | "niri/window" = { | 136 | "niri/window" = { |
85 | separate-outputs = true; | 137 | separate-outputs = true; |
86 | icon = true; | 138 | icon = true; |
@@ -140,8 +192,8 @@ | |||
140 | icon-size = iconSize; | 192 | icon-size = iconSize; |
141 | tooltip-format = "{percent}%"; | 193 | tooltip-format = "{percent}%"; |
142 | format-icons = ["󰃚" "󰃛" "󰃜" "󰃝" "󰃞" "󰃟" "󰃠"]; | 194 | format-icons = ["󰃚" "󰃛" "󰃜" "󰃝" "󰃞" "󰃟" "󰃠"]; |
143 | on-scroll-up = "lightctl -d -e4 -n1 up"; | 195 | on-scroll-up = "${swayosd-client} --brightness raise"; |
144 | on-scroll-down = "lightctl -d -e4 -n1 down"; | 196 | on-scroll-down = "${swayosd-client} --brightness lower"; |
145 | }; | 197 | }; |
146 | wireplumber = { | 198 | wireplumber = { |
147 | format = "<span font=\"Symbols Nerd Font Mono\" size=\"90%\">{icon}</span>"; | 199 | format = "<span font=\"Symbols Nerd Font Mono\" size=\"90%\">{icon}</span>"; |
@@ -150,9 +202,9 @@ | |||
150 | format-icons = ["󰕿" "󰖀" "󰕾"]; | 202 | format-icons = ["󰕿" "󰖀" "󰕾"]; |
151 | format-muted = "<span font=\"Symbols Nerd Font Mono\" size=\"90%\">󰝟</span>"; | 203 | format-muted = "<span font=\"Symbols Nerd Font Mono\" size=\"90%\">󰝟</span>"; |
152 | # ignored-sinks = ["Easy Effects Sink"]; | 204 | # ignored-sinks = ["Easy Effects Sink"]; |
153 | on-scroll-up = "volumectl -d -u up"; | 205 | on-scroll-up = "${swayosd-client} --output-volume raise"; |
154 | on-scroll-down = "volumectl -d -u down"; | 206 | on-scroll-down = "${swayosd-client} --output-volume lower"; |
155 | on-click = "volumectl -d toggle-mute"; | 207 | on-click = "${swayosd-client} --output-volume mute-toggle"; |
156 | }; | 208 | }; |
157 | } | 209 | } |
158 | { | 210 | { |
@@ -164,7 +216,9 @@ | |||
164 | modules-center = [ "niri/window" ]; | 216 | modules-center = [ "niri/window" ]; |
165 | modules-right = [ "clock" ]; | 217 | modules-right = [ "clock" ]; |
166 | 218 | ||
167 | "niri/workspaces" = {}; | 219 | "niri/workspaces" = { |
220 | ignore = ["pwctl" "kpxc" "bmgr" "edit" "term"]; | ||
221 | }; | ||
168 | "niri/window" = { | 222 | "niri/window" = { |
169 | separate-outputs = true; | 223 | separate-outputs = true; |
170 | icon = true; | 224 | icon = true; |
@@ -189,7 +243,7 @@ | |||
189 | 243 | ||
190 | * { | 244 | * { |
191 | border: none; | 245 | border: none; |
192 | font-family: "Fira Sans Nerd Font"; | 246 | font-family: "Fira Sans"; |
193 | font-size: 10pt; | 247 | font-size: 10pt; |
194 | min-height: 0; | 248 | min-height: 0; |
195 | } | 249 | } |
@@ -200,10 +254,10 @@ | |||
200 | } | 254 | } |
201 | 255 | ||
202 | .modules-left { | 256 | .modules-left { |
203 | margin-left: 9px; | 257 | margin-left: 12px; |
204 | } | 258 | } |
205 | .modules-right { | 259 | .modules-right { |
206 | margin-right: 9px; | 260 | margin-right: 12px; |
207 | } | 261 | } |
208 | 262 | ||
209 | .module { | 263 | .module { |
@@ -228,21 +282,26 @@ | |||
228 | color: @grey; | 282 | color: @grey; |
229 | margin: 0 5px; | 283 | margin: 0 5px; |
230 | } | 284 | } |
231 | #custom-weather, #custom-worktime-today { | 285 | #custom-weather { |
232 | margin-right: 3px; | 286 | margin-right: 3px; |
233 | } | 287 | } |
234 | #custom-keymap, #custom-weather { | 288 | #custom-keymap { |
235 | margin-left: 3px; | 289 | margin-left: 3px; |
290 | margin-right: 3px; | ||
236 | } | 291 | } |
237 | 292 | ||
238 | #tray { | 293 | #tray { |
239 | margin: 0; | 294 | margin: 0; |
240 | } | 295 | } |
241 | #battery, #idle_inhibitor, #backlight, #wireplumber { | 296 | #battery, #idle_inhibitor, #backlight, #wireplumber, #custom-mako { |
242 | color: @grey; | 297 | color: @grey; |
243 | margin: 0 5px 0 2px; | 298 | margin: 0 5px 0 2px; |
244 | } | 299 | } |
245 | #idle_inhibitor { | 300 | #idle_inhibitor { |
301 | margin-right: 4px; | ||
302 | margin-left: 6px; | ||
303 | } | ||
304 | #custom-mako { | ||
246 | margin-right: 2px; | 305 | margin-right: 2px; |
247 | margin-left: 3px; | 306 | margin-left: 3px; |
248 | } | 307 | } |
@@ -264,6 +323,12 @@ | |||
264 | #idle_inhibitor.activated { | 323 | #idle_inhibitor.activated { |
265 | color: @white; | 324 | color: @white; |
266 | } | 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 | } | ||
267 | 332 | ||
268 | #idle_inhibitor { | 333 | #idle_inhibitor { |
269 | padding-top: 1px; | 334 | padding-top: 1px; |
@@ -271,7 +336,7 @@ | |||
271 | 336 | ||
272 | #privacy { | 337 | #privacy { |
273 | color: @red; | 338 | color: @red; |
274 | margin: -1px 2px 0px 5px; | 339 | margin: -1px 4px 0px 3px; |
275 | } | 340 | } |
276 | #clock { | 341 | #clock { |
277 | /* margin-right: 5px; */ | 342 | /* margin-right: 5px; */ |