From 37e55957fbf411b928184465acb2b1ecd5ca6852 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Fri, 17 Jan 2025 22:20:56 +0100 Subject: mako --- accounts/gkleen@sif/niri/waybar.nix | 58 +++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) (limited to 'accounts/gkleen@sif/niri/waybar.nix') diff --git a/accounts/gkleen@sif/niri/waybar.nix b/accounts/gkleen@sif/niri/waybar.nix index ff48ba83..26e76a1d 100644 --- a/accounts/gkleen@sif/niri/waybar.nix +++ b/accounts/gkleen@sif/niri/waybar.nix @@ -25,8 +25,58 @@ modules-right = [ # "custom/worktime" "custom/worktime-today" "custom/weather" "custom/keymap" - "privacy" "tray" "wireplumber" "backlight" "battery" "idle_inhibitor" "clock" ]; + "privacy" "tray" "wireplumber" "backlight" "battery" "idle_inhibitor" "custom/mako" "clock" ]; + "custom/mako" = { + format = "{}"; + return-type = "json"; + exec = pkgs.writers.writePython3 "mako-silent" { libraries = [ pkgs.python3Packages.dbus-next ]; } '' + from dbus_next.aio import MessageBus + + import asyncio + + import json + + + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + + + async def main(): + bus = await MessageBus().connect() + # the introspection xml would normally be included in your project, but + # this is convenient for development + introspection = await bus.introspect('org.freedesktop.Notifications', '/fr/emersion/Mako') # noqa: E501 + + obj = bus.get_proxy_object('org.freedesktop.Notifications', '/fr/emersion/Mako', introspection) # noqa: E501 + mako = obj.get_interface('fr.emersion.Mako') + properties = obj.get_interface('org.freedesktop.DBus.Properties') + + async def print_mode(): + modes = await mako.get_modes() + is_silent = "silent" in modes + icon = "󰂛" if is_silent else "󰂚" + text = f"{icon}" # noqa: E501 + if is_silent: + text = f"{text}" + print(json.dumps({'text': text}, separators=(',', ':')), flush=True) # noqa: E501 + + async def on_properties_changed(interface_name, changed_properties, invalidated_properties): # noqa: E501 + if "Modes" not in invalidated_properties: + return + + await print_mode() + + properties.on_properties_changed(on_properties_changed) + await print_mode() + + await loop.create_future() + + + loop.run_until_complete(main()) + ''; + on-click = "makoctl mode -t silent"; + }; "custom/weather" = { format = "{}"; tooltip = true; @@ -240,11 +290,15 @@ #tray { margin: 0; } - #battery, #idle_inhibitor, #backlight, #wireplumber { + #battery, #idle_inhibitor, #backlight, #wireplumber, #custom-mako { color: @grey; margin: 0 5px 0 2px; } #idle_inhibitor { + margin-right: 4px; + margin-left: 6px; + } + #custom-mako { margin-right: 2px; margin-left: 3px; } -- cgit v1.2.3