aboutsummaryrefslogtreecommitdiff
path: root/src/utils.rs
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2023-10-31 17:06:14 +0400
committerIvan Molodetskikh <yalterz@gmail.com>2023-10-31 17:06:14 +0400
commit15144220fa207cd909282ea9f91cf794a7762fd8 (patch)
tree83c2d999aae024c998bfacbb595c4aef3c55a847 /src/utils.rs
parentb0af1129c91a21e29da15f9c5ea6a6dd32c1d85d (diff)
downloadniri-15144220fa207cd909282ea9f91cf794a7762fd8.tar.gz
niri-15144220fa207cd909282ea9f91cf794a7762fd8.tar.bz2
niri-15144220fa207cd909282ea9f91cf794a7762fd8.zip
Show notification on screenshot
Diffstat (limited to 'src/utils.rs')
-rw-r--r--src/utils.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/utils.rs b/src/utils.rs
index 15917f85..a04b8e9b 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -112,3 +112,34 @@ pub fn write_png_rgba8(
let mut writer = encoder.write_header()?;
writer.write_image_data(pixels)
}
+
+#[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));
+
+ // Try to add the screenshot as an image if possible.
+ 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());
+ }
+ Err(err) => {
+ warn!("error converting screenshot path to file url: {err:?}");
+ }
+ },
+ Err(err) => {
+ warn!("error canonicalizing screenshot path: {err:?}");
+ }
+ }
+ }
+
+ if let Err(err) = notification.show() {
+ warn!("error showing screenshot notification: {err:?}");
+ }
+}