diff --git a/bin/i3-companion b/bin/i3-companion index 1c8e447..f01120d 100755 --- a/bin/i3-companion +++ b/bin/i3-companion @@ -62,6 +62,8 @@ icons = { "wifi-medium": icon(2, ""), "wifi-high": icon(2, ""), "wired": icon(2, ""), + "notifications-enabled": icon(2, ""), + "notifications-disabled": icon(2, ""), } application_icons_nomatch = icon(2, "") application_icons_alone = {application_icons[k] for k in {"vbeterm"}} @@ -550,6 +552,46 @@ async def bluetooth_notifications( ) +@on( + DBusSignal( + system=False, + path="/org/freedesktop/Notifications", + interface="org.freedesktop.DBus.Properties", + member="PropertiesChanged", + signature="sa{sv}as", + ) +) +async def dunst_status_update( + i3, event, path, interface, changed, invalid +): + """Update notification status in polybar.""" + if interface != "org.dunstproject.cmd0": + return + if "paused" not in changed: + return + polybar( + "dunst", + icons[ + changed["paused"][1] + and "notifications-disabled" + or "notifications-enabled" + ], + ) + + +@on(StartEvent) +async def dunst_status_check(i3, event): + """Display notification status for polybar.""" + conn = i3.session_bus["org.freedesktop.Notifications"] + obj = conn["/org/freedesktop/Notifications"] + dunst = await obj.get_async_interface("org.dunstproject.cmd0") + paused = await dunst.paused + polybar( + "dunst", + icons[paused and "notifications-disabled" or "notifications-enabled"], + ) + + @on( DBusSignal( system=True, diff --git a/dotfiles/polybar.conf b/dotfiles/polybar.conf index ffa4321..10da524 100644 --- a/dotfiles/polybar.conf +++ b/dotfiles/polybar.conf @@ -34,11 +34,11 @@ modules-center = date [bar/alone] inherit = bar/common -modules-right = cpu memory brightness battery network disk pulseaudio +modules-right = cpu memory brightness battery network disk dunst pulseaudio [bar/primary] inherit = bar/common -modules-right = cpu memory brightness battery network disk pulseaudio +modules-right = cpu memory brightness battery network disk dunst pulseaudio [bar/secondary] inherit = bar/common @@ -106,6 +106,12 @@ type = custom/ipc hook-0 = cat $XDG_RUNTIME_DIR/i3/network.txt 2> /dev/null initial = 1 +[module/dunst] +type = custom/ipc +hook-0 = cat $XDG_RUNTIME_DIR/i3/dunst.txt 2> /dev/null +initial = 1 +click-left = dunstctl set-paused toggle + [module/date] type = internal/date interval = 2