aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKainoa Kanter <kainoa@t1c.dev>2025-10-25 23:33:49 -0700
committerGitHub <noreply@github.com>2025-10-26 06:33:49 +0000
commite6f3c538da0c646bda43fcde7ef7dc3b771e0c8b (patch)
tree935a519695fecc6998790bb628c85c1d6db52262 /src
parent4310c20c320d040f3df7a93de4064e452a1876ae (diff)
downloadniri-e6f3c538da0c646bda43fcde7ef7dc3b771e0c8b.tar.gz
niri-e6f3c538da0c646bda43fcde7ef7dc3b771e0c8b.tar.bz2
niri-e6f3c538da0c646bda43fcde7ef7dc3b771e0c8b.zip
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>
Diffstat (limited to 'src')
-rw-r--r--src/ipc/client.rs9
-rw-r--r--src/ipc/server.rs11
-rw-r--r--src/niri.rs22
-rw-r--r--src/utils/mod.rs2
4 files changed, 40 insertions, 4 deletions
diff --git a/src/ipc/client.rs b/src/ipc/client.rs
index 4c356355..3c7b27a9 100644
--- a/src/ipc/client.rs
+++ b/src/ipc/client.rs
@@ -481,6 +481,15 @@ pub fn handle_msg(mut msg: Msg, json: bool) -> anyhow::Result<()> {
};
println!("Config loaded {status}");
}
+ Event::ScreenshotCaptured { path } => {
+ let mut parts = vec![];
+ parts.push("copied to clipboard".to_string());
+ if let Some(path) = &path {
+ parts.push(format!("saved to {path}"));
+ }
+ let description = parts.join(" and ");
+ println!("Screenshot captured: {description}");
+ }
}
}
}
diff --git a/src/ipc/server.rs b/src/ipc/server.rs
index 354023b7..7fdc81f5 100644
--- a/src/ipc/server.rs
+++ b/src/ipc/server.rs
@@ -792,4 +792,15 @@ impl State {
state.apply(event.clone());
server.send_event(event);
}
+
+ pub fn ipc_screenshot_taken(&mut self, path: Option<String>) {
+ let Some(server) = &self.niri.ipc_server else {
+ return;
+ };
+ let mut state = server.event_stream_state.borrow_mut();
+
+ let event = Event::ScreenshotCaptured { path };
+ state.apply(event.clone());
+ server.send_event(event);
+ }
}
diff --git a/src/niri.rs b/src/niri.rs
index e341e964..5bc69c2e 100644
--- a/src/niri.rs
+++ b/src/niri.rs
@@ -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(())
diff --git a/src/utils/mod.rs b/src/utils/mod.rs
index 53537098..4a7b4b6f 100644
--- a/src/utils/mod.rs
+++ b/src/utils/mod.rs
@@ -461,7 +461,7 @@ pub fn baba_is_float_offset(now: Duration, view_height: f64) -> f64 {
}
#[cfg(feature = "dbus")]
-pub fn show_screenshot_notification(image_path: Option<PathBuf>) -> anyhow::Result<()> {
+pub fn show_screenshot_notification(image_path: Option<&Path>) -> anyhow::Result<()> {
use std::collections::HashMap;
use zbus::zvariant;