forge
Explore
Log in

Don't you dare go Hollow

Show notification on screenshot

Browse files at this commit

15144220fa207cd909282ea9f91cf794a7762fd8Ivan MolodetskikhParent: b0af112
Cargo.lockmodified+216 -1
@@ -348,6 +348,12 @@ version = "2.4.1"
348 source = "registry+https://github.com/rust-lang/crates.io-index"348 source = "registry+https://github.com/rust-lang/crates.io-index"
349 checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"349 checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
350 350
351+[[package]]
352+name = "block"
353+version = "0.1.6"
354+source = "registry+https://github.com/rust-lang/crates.io-index"
355+checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a"
356+
351 [[package]]357 [[package]]
352 name = "block-buffer"358 name = "block-buffer"
353 version = "0.10.4"359 version = "0.10.4"
@@ -696,6 +702,15 @@ version = "1.0.0"
696 source = "registry+https://github.com/rust-lang/crates.io-index"702 source = "registry+https://github.com/rust-lang/crates.io-index"
697 checksum = "740bb192a8e2d1350119916954f4409ee7f62f149b536911eeb78ba5a20526bf"703 checksum = "740bb192a8e2d1350119916954f4409ee7f62f149b536911eeb78ba5a20526bf"
698 704
705+[[package]]
706+name = "deranged"
707+version = "0.3.9"
708+source = "registry+https://github.com/rust-lang/crates.io-index"
709+checksum = "0f32d04922c60427da6f9fef14d042d9edddef64cb9d4ce0d64d0685fbeb1fd3"
710+dependencies = [
711+ "powerfmt",
712+]
713+
699 [[package]]714 [[package]]
700 name = "derivative"715 name = "derivative"
701 version = "2.2.0"716 version = "2.2.0"
@@ -726,6 +741,16 @@ dependencies = [
726 "dirs-sys",741 "dirs-sys",
727 ]742 ]
728 743
744+[[package]]
745+name = "dirs-next"
746+version = "2.0.0"
747+source = "registry+https://github.com/rust-lang/crates.io-index"
748+checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1"
749+dependencies = [
750+ "cfg-if",
751+ "dirs-sys-next",
752+]
753+
729 [[package]]754 [[package]]
730 name = "dirs-sys"755 name = "dirs-sys"
731 version = "0.4.1"756 version = "0.4.1"
@@ -738,6 +763,17 @@ dependencies = [
738 "windows-sys 0.48.0",763 "windows-sys 0.48.0",
739 ]764 ]
740 765
766+[[package]]
767+name = "dirs-sys-next"
768+version = "0.1.2"
769+source = "registry+https://github.com/rust-lang/crates.io-index"
770+checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d"
771+dependencies = [
772+ "libc",
773+ "redox_users",
774+ "winapi",
775+]
776+
741 [[package]]777 [[package]]
742 name = "dispatch"778 name = "dispatch"
743 version = "0.2.0"779 version = "0.2.0"
@@ -921,6 +957,15 @@ version = "0.3.1"
921 source = "registry+https://github.com/rust-lang/crates.io-index"957 source = "registry+https://github.com/rust-lang/crates.io-index"
922 checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b"958 checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b"
923 959
960+[[package]]
961+name = "form_urlencoded"
962+version = "1.2.0"
963+source = "registry+https://github.com/rust-lang/crates.io-index"
964+checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652"
965+dependencies = [
966+ "percent-encoding",
967+]
968+
924 [[package]]969 [[package]]
925 name = "futures-core"970 name = "futures-core"
926 version = "0.3.28"971 version = "0.3.28"
@@ -1010,7 +1055,7 @@ dependencies = [
1010 "libc",1055 "libc",
1011 "log",1056 "log",
1012 "rustversion",1057 "rustversion",
1013- "windows",1058+ "windows 0.48.0",
1014 ]1059 ]
1015 1060
1016 [[package]]1061 [[package]]
@@ -1103,6 +1148,16 @@ dependencies = [
1103 "objc2",1148 "objc2",
1104 ]1149 ]
1105 1150
1151+[[package]]
1152+name = "idna"
1153+version = "0.4.0"
1154+source = "registry+https://github.com/rust-lang/crates.io-index"
1155+checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c"
1156+dependencies = [
1157+ "unicode-bidi",
1158+ "unicode-normalization",
1159+]
1160+
1106 [[package]]1161 [[package]]
1107 name = "indexmap"1162 name = "indexmap"
1108 version = "2.0.2"1163 version = "2.0.2"
@@ -1386,6 +1441,28 @@ dependencies = [
1386 "tracing-subscriber",1441 "tracing-subscriber",
1387 ]1442 ]
1388 1443
1444+[[package]]
1445+name = "mac-notification-sys"
1446+version = "0.6.1"
1447+source = "registry+https://github.com/rust-lang/crates.io-index"
1448+checksum = "51fca4d74ff9dbaac16a01b924bc3693fa2bba0862c2c633abc73f9a8ea21f64"
1449+dependencies = [
1450+ "cc",
1451+ "dirs-next",
1452+ "objc-foundation",
1453+ "objc_id",
1454+ "time",
1455+]
1456+
1457+[[package]]
1458+name = "malloc_buf"
1459+version = "0.0.6"
1460+source = "registry+https://github.com/rust-lang/crates.io-index"
1461+checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb"
1462+dependencies = [
1463+ "libc",
1464+]
1465+
1389 [[package]]1466 [[package]]
1390 name = "matchers"1467 name = "matchers"
1391 version = "0.1.0"1468 version = "0.1.0"
@@ -1523,6 +1600,7 @@ dependencies = [
1523 "log",1600 "log",
1524 "logind-zbus",1601 "logind-zbus",
1525 "miette",1602 "miette",
1603+ "notify-rust",
1526 "pipewire",1604 "pipewire",
1527 "png",1605 "png",
1528 "portable-atomic",1606 "portable-atomic",
@@ -1536,6 +1614,7 @@ dependencies = [
1536 "tracing",1614 "tracing",
1537 "tracing-subscriber",1615 "tracing-subscriber",
1538 "tracy-client",1616 "tracy-client",
1617+ "url",
1539 "xcursor",1618 "xcursor",
1540 "zbus",1619 "zbus",
1541 ]1620 ]
@@ -1574,6 +1653,19 @@ dependencies = [
1574 "minimal-lexical",1653 "minimal-lexical",
1575 ]1654 ]
1576 1655
1656+[[package]]
1657+name = "notify-rust"
1658+version = "4.9.0"
1659+source = "registry+https://github.com/rust-lang/crates.io-index"
1660+checksum = "6d7b75c8958cb2eab3451538b32db8a7b74006abc33eb2e6a9a56d21e4775c2b"
1661+dependencies = [
1662+ "log",
1663+ "mac-notification-sys",
1664+ "serde",
1665+ "tauri-winrt-notification",
1666+ "zbus",
1667+]
1668+
1577 [[package]]1669 [[package]]
1578 name = "nu-ansi-term"1670 name = "nu-ansi-term"
1579 version = "0.46.0"1671 version = "0.46.0"
@@ -1615,6 +1707,26 @@ dependencies = [
1615 "syn 2.0.38",1707 "syn 2.0.38",
1616 ]1708 ]
1617 1709
1710+[[package]]
1711+name = "objc"
1712+version = "0.2.7"
1713+source = "registry+https://github.com/rust-lang/crates.io-index"
1714+checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1"
1715+dependencies = [
1716+ "malloc_buf",
1717+]
1718+
1719+[[package]]
1720+name = "objc-foundation"
1721+version = "0.1.1"
1722+source = "registry+https://github.com/rust-lang/crates.io-index"
1723+checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9"
1724+dependencies = [
1725+ "block",
1726+ "objc",
1727+ "objc_id",
1728+]
1729+
1618 [[package]]1730 [[package]]
1619 name = "objc-sys"1731 name = "objc-sys"
1620 version = "0.3.1"1732 version = "0.3.1"
@@ -1637,6 +1749,15 @@ version = "3.0.0"
1637 source = "registry+https://github.com/rust-lang/crates.io-index"1749 source = "registry+https://github.com/rust-lang/crates.io-index"
1638 checksum = "d079845b37af429bfe5dfa76e6d087d788031045b25cfc6fd898486fd9847666"1750 checksum = "d079845b37af429bfe5dfa76e6d087d788031045b25cfc6fd898486fd9847666"
1639 1751
1752+[[package]]
1753+name = "objc_id"
1754+version = "0.1.1"
1755+source = "registry+https://github.com/rust-lang/crates.io-index"
1756+checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b"
1757+dependencies = [
1758+ "objc",
1759+]
1760+
1640 [[package]]1761 [[package]]
1641 name = "once_cell"1762 name = "once_cell"
1642 version = "1.18.0"1763 version = "1.18.0"
@@ -1798,6 +1919,12 @@ version = "1.5.0"
1798 source = "registry+https://github.com/rust-lang/crates.io-index"1919 source = "registry+https://github.com/rust-lang/crates.io-index"
1799 checksum = "b559898e0b4931ed2d3b959ab0c2da4d99cc644c4b0b1a35b4d344027f474023"1920 checksum = "b559898e0b4931ed2d3b959ab0c2da4d99cc644c4b0b1a35b4d344027f474023"
1800 1921
1922+[[package]]
1923+name = "powerfmt"
1924+version = "0.2.0"
1925+source = "registry+https://github.com/rust-lang/crates.io-index"
1926+checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
1927+
1801 [[package]]1928 [[package]]
1802 name = "ppv-lite86"1929 name = "ppv-lite86"
1803 version = "0.2.17"1930 version = "0.2.17"
@@ -2373,6 +2500,16 @@ version = "0.12.12"
2373 source = "registry+https://github.com/rust-lang/crates.io-index"2500 source = "registry+https://github.com/rust-lang/crates.io-index"
2374 checksum = "14c39fd04924ca3a864207c66fc2cd7d22d7c016007f9ce846cbb9326331930a"2501 checksum = "14c39fd04924ca3a864207c66fc2cd7d22d7c016007f9ce846cbb9326331930a"
2375 2502
2503+[[package]]
2504+name = "tauri-winrt-notification"
2505+version = "0.1.3"
2506+source = "registry+https://github.com/rust-lang/crates.io-index"
2507+checksum = "006851c9ccefa3c38a7646b8cec804bb429def3da10497bfa977179869c3e8e2"
2508+dependencies = [
2509+ "quick-xml",
2510+ "windows 0.51.1",
2511+]
2512+
2376 [[package]]2513 [[package]]
2377 name = "tempfile"2514 name = "tempfile"
2378 version = "3.8.0"2515 version = "3.8.0"
@@ -2416,6 +2553,39 @@ dependencies = [
2416 "once_cell",2553 "once_cell",
2417 ]2554 ]
2418 2555
2556+[[package]]
2557+name = "time"
2558+version = "0.3.30"
2559+source = "registry+https://github.com/rust-lang/crates.io-index"
2560+checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5"
2561+dependencies = [
2562+ "deranged",
2563+ "powerfmt",
2564+ "serde",
2565+ "time-core",
2566+]
2567+
2568+[[package]]
2569+name = "time-core"
2570+version = "0.1.2"
2571+source = "registry+https://github.com/rust-lang/crates.io-index"
2572+checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3"
2573+
2574+[[package]]
2575+name = "tinyvec"
2576+version = "1.6.0"
2577+source = "registry+https://github.com/rust-lang/crates.io-index"
2578+checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50"
2579+dependencies = [
2580+ "tinyvec_macros",
2581+]
2582+
2583+[[package]]
2584+name = "tinyvec_macros"
2585+version = "0.1.1"
2586+source = "registry+https://github.com/rust-lang/crates.io-index"
2587+checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
2588+
2419 [[package]]2589 [[package]]
2420 name = "toml"2590 name = "toml"
2421 version = "0.8.4"2591 version = "0.8.4"
@@ -2587,12 +2757,27 @@ version = "0.1.4"
2587 source = "registry+https://github.com/rust-lang/crates.io-index"2757 source = "registry+https://github.com/rust-lang/crates.io-index"
2588 checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94"2758 checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94"
2589 2759
2760+[[package]]
2761+name = "unicode-bidi"
2762+version = "0.3.13"
2763+source = "registry+https://github.com/rust-lang/crates.io-index"
2764+checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460"
2765+
2590 [[package]]2766 [[package]]
2591 name = "unicode-ident"2767 name = "unicode-ident"
2592 version = "1.0.12"2768 version = "1.0.12"
2593 source = "registry+https://github.com/rust-lang/crates.io-index"2769 source = "registry+https://github.com/rust-lang/crates.io-index"
2594 checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"2770 checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
2595 2771
2772+[[package]]
2773+name = "unicode-normalization"
2774+version = "0.1.22"
2775+source = "registry+https://github.com/rust-lang/crates.io-index"
2776+checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921"
2777+dependencies = [
2778+ "tinyvec",
2779+]
2780+
2596 [[package]]2781 [[package]]
2597 name = "unicode-segmentation"2782 name = "unicode-segmentation"
2598 version = "1.10.1"2783 version = "1.10.1"
@@ -2605,6 +2790,17 @@ version = "0.1.11"
2605 source = "registry+https://github.com/rust-lang/crates.io-index"2790 source = "registry+https://github.com/rust-lang/crates.io-index"
2606 checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85"2791 checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85"
2607 2792
2793+[[package]]
2794+name = "url"
2795+version = "2.4.1"
2796+source = "registry+https://github.com/rust-lang/crates.io-index"
2797+checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5"
2798+dependencies = [
2799+ "form_urlencoded",
2800+ "idna",
2801+ "percent-encoding",
2802+]
2803+
2608 [[package]]2804 [[package]]
2609 name = "utf8parse"2805 name = "utf8parse"
2610 version = "0.2.1"2806 version = "0.2.1"
@@ -2945,6 +3141,25 @@ dependencies = [
2945 "windows-targets 0.48.5",3141 "windows-targets 0.48.5",
2946 ]3142 ]
2947 3143
3144+[[package]]
3145+name = "windows"
3146+version = "0.51.1"
3147+source = "registry+https://github.com/rust-lang/crates.io-index"
3148+checksum = "ca229916c5ee38c2f2bc1e9d8f04df975b4bd93f9955dc69fabb5d91270045c9"
3149+dependencies = [
3150+ "windows-core",
3151+ "windows-targets 0.48.5",
3152+]
3153+
3154+[[package]]
3155+name = "windows-core"
3156+version = "0.51.1"
3157+source = "registry+https://github.com/rust-lang/crates.io-index"
3158+checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64"
3159+dependencies = [
3160+ "windows-targets 0.48.5",
3161+]
3162+
2948 [[package]]3163 [[package]]
2949 name = "windows-sys"3164 name = "windows-sys"
2950 version = "0.45.0"3165 version = "0.45.0"
Cargo.tomlmodified+3 -1
@@ -20,6 +20,7 @@ libc = "0.2.149"
20 logind-zbus = { version = "3.1.2", optional = true }20 logind-zbus = { version = "3.1.2", optional = true }
21 log = { version = "0.4.20", features = ["max_level_trace", "release_max_level_debug"] }21 log = { version = "0.4.20", features = ["max_level_trace", "release_max_level_debug"] }
22 miette = "5.10.0"22 miette = "5.10.0"
23+notify-rust = { version = "4.9.0", optional = true }
23 pipewire = { version = "0.7.2", optional = true }24 pipewire = { version = "0.7.2", optional = true }
24 png = "0.17.10"25 png = "0.17.10"
25 portable-atomic = { version = "1.5.0", default-features = false, features = ["float"] }26 portable-atomic = { version = "1.5.0", default-features = false, features = ["float"] }
@@ -29,6 +30,7 @@ serde = { version = "1.0.189", features = ["derive"] }
29 tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }30 tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
30 tracing = { version = "0.1.40", features = ["max_level_trace", "release_max_level_debug"] }31 tracing = { version = "0.1.40", features = ["max_level_trace", "release_max_level_debug"] }
31 tracy-client = { version = "0.16.3", default-features = false }32 tracy-client = { version = "0.16.3", default-features = false }
33+url = { version = "2.4.1", optional = true }
32 xcursor = "0.3.4"34 xcursor = "0.3.4"
33 zbus = { version = "3.14.1", optional = true }35 zbus = { version = "3.14.1", optional = true }
34 36
@@ -63,7 +65,7 @@ proptest-derive = "0.4.0"
63 [features]65 [features]
64 default = ["dbus", "xdp-gnome-screencast"]66 default = ["dbus", "xdp-gnome-screencast"]
65 # Enables DBus support (required for xdp-gnome and power button inhibiting).67 # Enables DBus support (required for xdp-gnome and power button inhibiting).
66-dbus = ["zbus", "logind-zbus", "async-channel", "async-io"]68+dbus = ["zbus", "logind-zbus", "async-channel", "async-io", "notify-rust", "url"]
67 # Enables screencasting support through xdg-desktop-portal-gnome.69 # Enables screencasting support through xdg-desktop-portal-gnome.
68 xdp-gnome-screencast = ["dbus", "pipewire"]70 xdp-gnome-screencast = ["dbus", "pipewire"]
69 # Enables the Tracy profiler instrumentation.71 # Enables the Tracy profiler instrumentation.
src/niri.rsmodified+13 -2
@@ -2053,14 +2053,25 @@ impl Niri {
2053 let buf: Arc<[u8]> = Arc::from(buf.into_boxed_slice());2053 let buf: Arc<[u8]> = Arc::from(buf.into_boxed_slice());
2054 let _ = tx.send(buf.clone());2054 let _ = tx.send(buf.clone());
2055 2055
2056+ let mut image_path = None;
2057+
2056 if let Some(path) = path {2058 if let Some(path) = path {
2057 debug!("saving screenshot to {path:?}");2059 debug!("saving screenshot to {path:?}");
2058- if let Err(err) = std::fs::write(path, buf) {2060+
2059- warn!("error saving screenshot image: {err:?}");2061+ match std::fs::write(&path, buf) {
2062+ Ok(()) => image_path = Some(path),
2063+ Err(err) => {
2064+ warn!("error saving screenshot image: {err:?}");
2065+ }
2060 }2066 }
2061 } else {2067 } else {
2062 debug!("not saving screenshot to disk");2068 debug!("not saving screenshot to disk");
2063 }2069 }
2070+
2071+ #[cfg(feature = "dbus")]
2072+ crate::utils::show_screenshot_notification(image_path);
2073+ #[cfg(not(feature = "dbus"))]
2074+ drop(image_path);
2064 });2075 });
2065 2076
2066 Ok(())2077 Ok(())
src/utils.rsmodified+31 -0
@@ -112,3 +112,34 @@ pub fn write_png_rgba8(
112 let mut writer = encoder.write_header()?;112 let mut writer = encoder.write_header()?;
113 writer.write_image_data(pixels)113 writer.write_image_data(pixels)
114 }114 }
115+
116+#[cfg(feature = "dbus")]
117+pub fn show_screenshot_notification(image_path: Option<PathBuf>) {
118+ let mut notification = notify_rust::Notification::new();
119+ notification
120+ .summary("Screenshot captured")
121+ .body("You can paste the image from the clipboard.")
122+ .urgency(notify_rust::Urgency::Normal)
123+ .hint(notify_rust::Hint::Transient(true));
124+
125+ // Try to add the screenshot as an image if possible.
126+ if let Some(path) = image_path {
127+ match path.canonicalize() {
128+ Ok(path) => match url::Url::from_file_path(path) {
129+ Ok(url) => {
130+ notification.image_path(url.as_str());
131+ }
132+ Err(err) => {
133+ warn!("error converting screenshot path to file url: {err:?}");
134+ }
135+ },
136+ Err(err) => {
137+ warn!("error canonicalizing screenshot path: {err:?}");
138+ }
139+ }
140+ }
141+
142+ if let Err(err) = notification.show() {
143+ warn!("error showing screenshot notification: {err:?}");
144+ }
145+}