diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/niri.rs | 4 | ||||
| -rw-r--r-- | src/utils/mod.rs | 42 |
2 files changed, 34 insertions, 12 deletions
diff --git a/src/niri.rs b/src/niri.rs index a0819732..2c5cbe48 100644 --- a/src/niri.rs +++ b/src/niri.rs @@ -4545,7 +4545,9 @@ impl Niri { } #[cfg(feature = "dbus")] - crate::utils::show_screenshot_notification(image_path); + if let Err(err) = crate::utils::show_screenshot_notification(image_path) { + warn!("error showing screenshot notification: {err:?}"); + } #[cfg(not(feature = "dbus"))] drop(image_path); }); diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 28cebf2c..6507bee2 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -307,20 +307,20 @@ pub fn center_preferring_top_left_in_area( } #[cfg(feature = "dbus")] -pub fn show_screenshot_notification(image_path: Option<PathBuf>) { - let mut notification = notify_rust::Notification::new(); - notification - .summary("Screenshot captured") - .body("You can paste the image from the clipboard.") - .urgency(notify_rust::Urgency::Normal) - .hint(notify_rust::Hint::Transient(true)); +pub fn show_screenshot_notification(image_path: Option<PathBuf>) -> anyhow::Result<()> { + use std::collections::HashMap; + + use zbus::zvariant; + + let conn = zbus::blocking::Connection::session()?; // Try to add the screenshot as an image if possible. + let mut image_url = None; if let Some(path) = image_path { match path.canonicalize() { Ok(path) => match url::Url::from_file_path(path) { Ok(url) => { - notification.image_path(url.as_str()); + image_url = Some(url); } Err(err) => { warn!("error converting screenshot path to file url: {err:?}"); @@ -332,9 +332,29 @@ pub fn show_screenshot_notification(image_path: Option<PathBuf>) { } } - if let Err(err) = notification.show() { - warn!("error showing screenshot notification: {err:?}"); - } + let actions: &[&str] = &[]; + + conn.call_method( + Some("org.freedesktop.Notifications"), + "/org/freedesktop/Notifications", + Some("org.freedesktop.Notifications"), + "Notify", + &( + "niri", + 0u32, + image_url.as_ref().map(|url| url.as_str()).unwrap_or(""), + "Screenshot captured", + "You can paste the image from the clipboard.", + actions, + HashMap::from([ + ("transient", zvariant::Value::Bool(true)), + ("urgency", zvariant::Value::U8(1)), + ]), + -1, + ), + )?; + + Ok(()) } #[inline(never)] |
