Skip to content

Commit 74b003c

Browse files
committed
block[notify]: swaync add support for inhibited status
1 parent e18835c commit 74b003c

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/blocks/notify.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
//! [^dunst_version_note]: when using `notification_count` with the `dunst` driver use dunst > 1.9.0
5858
5959
use super::prelude::*;
60-
use tokio::try_join;
60+
use tokio::{join, try_join};
6161
use zbus::PropertyStream;
6262

6363
const ICON_ON: &str = "bell";
@@ -195,6 +195,7 @@ impl Driver for DunstDriver {
195195
default_service = "org.freedesktop.Notifications",
196196
default_path = "/org/freedesktop/Notifications"
197197
)]
198+
198199
trait DunstDbus {
199200
#[zbus(property, name = "paused")]
200201
fn paused(&self) -> zbus::Result<bool>;
@@ -235,14 +236,20 @@ impl SwayNCDriver {
235236
#[async_trait]
236237
impl Driver for SwayNCDriver {
237238
async fn is_paused(&self) -> Result<bool> {
238-
self.proxy.get_dnd().await.error("Failed to call 'GetDnd'")
239+
let (is_dnd, is_inhibited) = join!(self.proxy.get_dnd(), self.proxy.is_inhibited());
240+
241+
is_dnd
242+
.error("Failed to call 'GetDnd'")
243+
.map(|is_dnd| is_dnd || is_inhibited.unwrap_or_default())
239244
}
240245

241246
async fn set_paused(&self, paused: bool) -> Result<()> {
242-
self.proxy
243-
.set_dnd(paused)
244-
.await
245-
.error("Failed to call 'SetDnd'")
247+
if paused {
248+
self.proxy.set_dnd(paused).await
249+
} else {
250+
join!(self.proxy.set_dnd(paused), self.proxy.clear_inhibitors()).0
251+
}
252+
.error("Failed to call 'SetDnd'")
246253
}
247254

248255
async fn notification_show(&self) -> Result<()> {
@@ -280,6 +287,11 @@ trait SwayNCDbus {
280287
fn notification_count(&self) -> zbus::Result<u32>;
281288
#[zbus(signal)]
282289
fn subscribe(&self, count: u32, dnd: bool, cc_open: bool) -> zbus::Result<()>;
290+
291+
// inhibitors were introduced in v0.8.0
292+
fn is_inhibited(&self) -> zbus::Result<bool>;
293+
fn clear_inhibitors(&self) -> zbus::Result<bool>;
294+
// subscribe_v2 replaced subscribe in v0.8.0
283295
#[zbus(signal)]
284296
fn subscribe_v2(
285297
&self,

0 commit comments

Comments
 (0)