|
57 | 57 | //! [^dunst_version_note]: when using `notification_count` with the `dunst` driver use dunst > 1.9.0 |
58 | 58 |
|
59 | 59 | use super::prelude::*; |
60 | | -use tokio::try_join; |
| 60 | +use tokio::{join, try_join}; |
61 | 61 | use zbus::PropertyStream; |
62 | 62 |
|
63 | 63 | const ICON_ON: &str = "bell"; |
@@ -195,6 +195,7 @@ impl Driver for DunstDriver { |
195 | 195 | default_service = "org.freedesktop.Notifications", |
196 | 196 | default_path = "/org/freedesktop/Notifications" |
197 | 197 | )] |
| 198 | + |
198 | 199 | trait DunstDbus { |
199 | 200 | #[zbus(property, name = "paused")] |
200 | 201 | fn paused(&self) -> zbus::Result<bool>; |
@@ -235,14 +236,20 @@ impl SwayNCDriver { |
235 | 236 | #[async_trait] |
236 | 237 | impl Driver for SwayNCDriver { |
237 | 238 | 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()) |
239 | 244 | } |
240 | 245 |
|
241 | 246 | 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'") |
246 | 253 | } |
247 | 254 |
|
248 | 255 | async fn notification_show(&self) -> Result<()> { |
@@ -280,6 +287,11 @@ trait SwayNCDbus { |
280 | 287 | fn notification_count(&self) -> zbus::Result<u32>; |
281 | 288 | #[zbus(signal)] |
282 | 289 | 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 |
283 | 295 | #[zbus(signal)] |
284 | 296 | fn subscribe_v2( |
285 | 297 | &self, |
|
0 commit comments