feat: event-stream event for when a screenshot is taken (#2565)

* feat: event-stream event for when a screenshot is taken

* ScreenshotTaken --> ScreenshotCaptured

* review comments

* fix: screenshot completion event path serializatation

* fixes

---------

Co-authored-by: Ivan Molodetskikh <yalterz@gmail.com>
This commit is contained in:
Kainoa Kanter
2025-10-25 23:33:49 -07:00
committed by GitHub
parent 4310c20c32
commit e6f3c538da
5 changed files with 48 additions and 4 deletions
+19 -3
View File
@@ -5643,6 +5643,17 @@ impl Niri {
})
.unwrap();
// Prepare to send screenshot completion event back to main thread.
let (event_tx, event_rx) = calloop::channel::sync_channel::<Option<String>>(1);
self.event_loop
.insert_source(event_rx, move |event, _, state| match event {
calloop::channel::Event::Msg(path) => {
state.ipc_screenshot_taken(path);
}
calloop::channel::Event::Closed => (),
})
.unwrap();
// Encode and save the image in a thread as it's slow.
thread::spawn(move || {
let mut buf = vec![];
@@ -5685,11 +5696,16 @@ impl Niri {
}
#[cfg(feature = "dbus")]
if let Err(err) = crate::utils::show_screenshot_notification(image_path) {
if let Err(err) = crate::utils::show_screenshot_notification(image_path.as_deref()) {
warn!("error showing screenshot notification: {err:?}");
}
#[cfg(not(feature = "dbus"))]
drop(image_path);
// Send screenshot completion event.
let path_string = image_path
.as_ref()
.and_then(|p| p.to_str())
.map(|s| s.to_owned());
let _ = event_tx.send(path_string);
});
Ok(())