mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-22 02:01:55 +07:00
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:
+19
-3
@@ -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(())
|
||||
|
||||
Reference in New Issue
Block a user