Skip to content

Commit

Permalink
block[notify]: swaync add support for inhibited status
Browse files Browse the repository at this point in the history
  • Loading branch information
bim9262 committed Sep 13, 2024
1 parent e18835c commit 74b003c
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/blocks/notify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
//! [^dunst_version_note]: when using `notification_count` with the `dunst` driver use dunst > 1.9.0

use super::prelude::*;
use tokio::try_join;
use tokio::{join, try_join};
use zbus::PropertyStream;

const ICON_ON: &str = "bell";
Expand Down Expand Up @@ -195,6 +195,7 @@ impl Driver for DunstDriver {
default_service = "org.freedesktop.Notifications",
default_path = "/org/freedesktop/Notifications"
)]

trait DunstDbus {
#[zbus(property, name = "paused")]
fn paused(&self) -> zbus::Result<bool>;
Expand Down Expand Up @@ -235,14 +236,20 @@ impl SwayNCDriver {
#[async_trait]
impl Driver for SwayNCDriver {
async fn is_paused(&self) -> Result<bool> {
self.proxy.get_dnd().await.error("Failed to call 'GetDnd'")
let (is_dnd, is_inhibited) = join!(self.proxy.get_dnd(), self.proxy.is_inhibited());

is_dnd
.error("Failed to call 'GetDnd'")
.map(|is_dnd| is_dnd || is_inhibited.unwrap_or_default())
}

async fn set_paused(&self, paused: bool) -> Result<()> {
self.proxy
.set_dnd(paused)
.await
.error("Failed to call 'SetDnd'")
if paused {
self.proxy.set_dnd(paused).await
} else {
join!(self.proxy.set_dnd(paused), self.proxy.clear_inhibitors()).0
}
.error("Failed to call 'SetDnd'")
}

async fn notification_show(&self) -> Result<()> {
Expand Down Expand Up @@ -280,6 +287,11 @@ trait SwayNCDbus {
fn notification_count(&self) -> zbus::Result<u32>;
#[zbus(signal)]
fn subscribe(&self, count: u32, dnd: bool, cc_open: bool) -> zbus::Result<()>;

// inhibitors were introduced in v0.8.0
fn is_inhibited(&self) -> zbus::Result<bool>;
fn clear_inhibitors(&self) -> zbus::Result<bool>;
// subscribe_v2 replaced subscribe in v0.8.0
#[zbus(signal)]
fn subscribe_v2(
&self,
Expand Down

0 comments on commit 74b003c

Please sign in to comment.