forge
Explore
Log in

Don't you dare go Hollow

Add --path argument for niri msg screenshot* commands (#2126)

Browse files at this commit

23cd5aa78a26ccf57c6a7993313e42a5c39d43d8UnverifiedLin Xianyi and Ivan MolodetskikhParent: 8c84479
* Check for empty screenshot parent before creating

Avoids a warning.

* Add --path argument for niri msg screenshot* commands

* fix

---------
niri-config/src/binds.rsmodified+26 -6
@@ -118,16 +118,27 @@ pub enum Action {
118 CancelScreenshot,118 CancelScreenshot,
119 #[knuffel(skip)]119 #[knuffel(skip)]
120 ScreenshotTogglePointer,120 ScreenshotTogglePointer,
121- Screenshot(#[knuffel(property(name = "show-pointer"), default = true)] bool),121+ Screenshot(
122+ #[knuffel(property(name = "show-pointer"), default = true)] bool,
123+ // Path; not settable from knuffel
124+ Option<String>,
125+ ),
122 ScreenshotScreen(126 ScreenshotScreen(
123 #[knuffel(property(name = "write-to-disk"), default = true)] bool,127 #[knuffel(property(name = "write-to-disk"), default = true)] bool,
124 #[knuffel(property(name = "show-pointer"), default = true)] bool,128 #[knuffel(property(name = "show-pointer"), default = true)] bool,
129+ // Path; not settable from knuffel
130+ Option<String>,
131+ ),
132+ ScreenshotWindow(
133+ #[knuffel(property(name = "write-to-disk"), default = true)] bool,
134+ // Path; not settable from knuffel
135+ Option<String>,
125 ),136 ),
126- ScreenshotWindow(#[knuffel(property(name = "write-to-disk"), default = true)] bool),
127 #[knuffel(skip)]137 #[knuffel(skip)]
128 ScreenshotWindowById {138 ScreenshotWindowById {
129 id: u64,139 id: u64,
130 write_to_disk: bool,140 write_to_disk: bool,
141+ path: Option<String>,
131 },142 },
132 ToggleKeyboardShortcutsInhibit,143 ToggleKeyboardShortcutsInhibit,
133 CloseWindow,144 CloseWindow,
@@ -364,19 +375,28 @@ impl From<niri_ipc::Action> for Action {
364 niri_ipc::Action::Spawn { command } => Self::Spawn(command),375 niri_ipc::Action::Spawn { command } => Self::Spawn(command),
365 niri_ipc::Action::SpawnSh { command } => Self::SpawnSh(command),376 niri_ipc::Action::SpawnSh { command } => Self::SpawnSh(command),
366 niri_ipc::Action::DoScreenTransition { delay_ms } => Self::DoScreenTransition(delay_ms),377 niri_ipc::Action::DoScreenTransition { delay_ms } => Self::DoScreenTransition(delay_ms),
367- niri_ipc::Action::Screenshot { show_pointer } => Self::Screenshot(show_pointer),378+ niri_ipc::Action::Screenshot { show_pointer, path } => {
379+ Self::Screenshot(show_pointer, path)
380+ }
368 niri_ipc::Action::ScreenshotScreen {381 niri_ipc::Action::ScreenshotScreen {
369 write_to_disk,382 write_to_disk,
370 show_pointer,383 show_pointer,
371- } => Self::ScreenshotScreen(write_to_disk, show_pointer),384+ path,
385+ } => Self::ScreenshotScreen(write_to_disk, show_pointer, path),
372 niri_ipc::Action::ScreenshotWindow {386 niri_ipc::Action::ScreenshotWindow {
373 id: None,387 id: None,
374 write_to_disk,388 write_to_disk,
375- } => Self::ScreenshotWindow(write_to_disk),389+ path,
390+ } => Self::ScreenshotWindow(write_to_disk, path),
376 niri_ipc::Action::ScreenshotWindow {391 niri_ipc::Action::ScreenshotWindow {
377 id: Some(id),392 id: Some(id),
378 write_to_disk,393 write_to_disk,
379- } => Self::ScreenshotWindowById { id, write_to_disk },394+ path,
395+ } => Self::ScreenshotWindowById {
396+ id,
397+ write_to_disk,
398+ path,
399+ },
380 niri_ipc::Action::ToggleKeyboardShortcutsInhibit {} => {400 niri_ipc::Action::ToggleKeyboardShortcutsInhibit {} => {
381 Self::ToggleKeyboardShortcutsInhibit401 Self::ToggleKeyboardShortcutsInhibit
382 }402 }
niri-ipc/src/lib.rsmodified+24 -0
@@ -220,6 +220,14 @@ pub enum Action {
220 /// Whether to show the mouse pointer by default in the screenshot UI.220 /// Whether to show the mouse pointer by default in the screenshot UI.
221 #[cfg_attr(feature = "clap", arg(short = 'p', long, action = clap::ArgAction::Set, default_value_t = true))]221 #[cfg_attr(feature = "clap", arg(short = 'p', long, action = clap::ArgAction::Set, default_value_t = true))]
222 show_pointer: bool,222 show_pointer: bool,
223+
224+ /// Path to save the screenshot to.
225+ ///
226+ /// The path must be absolute, otherwise an error is returned.
227+ ///
228+ /// If `None`, the screenshot is saved according to the `screenshot-path` config setting.
229+ #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set))]
230+ path: Option<String>,
223 },231 },
224 /// Screenshot the focused screen.232 /// Screenshot the focused screen.
225 ScreenshotScreen {233 ScreenshotScreen {
@@ -232,6 +240,14 @@ pub enum Action {
232 /// Whether to include the mouse pointer in the screenshot.240 /// Whether to include the mouse pointer in the screenshot.
233 #[cfg_attr(feature = "clap", arg(short = 'p', long, action = clap::ArgAction::Set, default_value_t = true))]241 #[cfg_attr(feature = "clap", arg(short = 'p', long, action = clap::ArgAction::Set, default_value_t = true))]
234 show_pointer: bool,242 show_pointer: bool,
243+
244+ /// Path to save the screenshot to.
245+ ///
246+ /// The path must be absolute, otherwise an error is returned.
247+ ///
248+ /// If `None`, the screenshot is saved according to the `screenshot-path` config setting.
249+ #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set))]
250+ path: Option<String>,
235 },251 },
236 /// Screenshot a window.252 /// Screenshot a window.
237 #[cfg_attr(feature = "clap", clap(about = "Screenshot the focused window"))]253 #[cfg_attr(feature = "clap", clap(about = "Screenshot the focused window"))]
@@ -246,6 +262,14 @@ pub enum Action {
246 /// The screenshot is saved according to the `screenshot-path` config setting.262 /// The screenshot is saved according to the `screenshot-path` config setting.
247 #[cfg_attr(feature = "clap", arg(short = 'd', long, action = clap::ArgAction::Set, default_value_t = true))]263 #[cfg_attr(feature = "clap", arg(short = 'd', long, action = clap::ArgAction::Set, default_value_t = true))]
248 write_to_disk: bool,264 write_to_disk: bool,
265+
266+ /// Path to save the screenshot to.
267+ ///
268+ /// The path must be absolute, otherwise an error is returned.
269+ ///
270+ /// If `None`, the screenshot is saved according to the `screenshot-path` config setting.
271+ #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set))]
272+ path: Option<String>,
249 },273 },
250 /// Enable or disable the keyboard shortcuts inhibitor (if any) for the focused surface.274 /// Enable or disable the keyboard shortcuts inhibitor (if any) for the focused surface.
251 ToggleKeyboardShortcutsInhibit {},275 ToggleKeyboardShortcutsInhibit {},
src/input/mod.rsmodified+30 -17
@@ -605,14 +605,17 @@ impl State {
605 self.niri.do_screen_transition(renderer, delay_ms);605 self.niri.do_screen_transition(renderer, delay_ms);
606 });606 });
607 }607 }
608- Action::ScreenshotScreen(write_to_disk, show_pointer) => {608+ Action::ScreenshotScreen(write_to_disk, show_pointer, path) => {
609 let active = self.niri.layout.active_output().cloned();609 let active = self.niri.layout.active_output().cloned();
610 if let Some(active) = active {610 if let Some(active) = active {
611 self.backend.with_primary_renderer(|renderer| {611 self.backend.with_primary_renderer(|renderer| {
612- if let Err(err) =612+ if let Err(err) = self.niri.screenshot(
613- self.niri613+ renderer,
614- .screenshot(renderer, &active, write_to_disk, show_pointer)614+ &active,
615- {615+ write_to_disk,
616+ show_pointer,
617+ path,
618+ ) {
616 warn!("error taking screenshot: {err:?}");619 warn!("error taking screenshot: {err:?}");
617 }620 }
618 });621 });
@@ -636,32 +639,42 @@ impl State {
636 self.niri.screenshot_ui.toggle_pointer();639 self.niri.screenshot_ui.toggle_pointer();
637 self.niri.queue_redraw_all();640 self.niri.queue_redraw_all();
638 }641 }
639- Action::Screenshot(show_cursor) => {642+ Action::Screenshot(show_cursor, path) => {
640- self.open_screenshot_ui(show_cursor);643+ self.open_screenshot_ui(show_cursor, path);
641 }644 }
642- Action::ScreenshotWindow(write_to_disk) => {645+ Action::ScreenshotWindow(write_to_disk, path) => {
643 let focus = self.niri.layout.focus_with_output();646 let focus = self.niri.layout.focus_with_output();
644 if let Some((mapped, output)) = focus {647 if let Some((mapped, output)) = focus {
645 self.backend.with_primary_renderer(|renderer| {648 self.backend.with_primary_renderer(|renderer| {
646- if let Err(err) =649+ if let Err(err) = self.niri.screenshot_window(
647- self.niri650+ renderer,
648- .screenshot_window(renderer, output, mapped, write_to_disk)651+ output,
649- {652+ mapped,
653+ write_to_disk,
654+ path,
655+ ) {
650 warn!("error taking screenshot: {err:?}");656 warn!("error taking screenshot: {err:?}");
651 }657 }
652 });658 });
653 }659 }
654 }660 }
655- Action::ScreenshotWindowById { id, write_to_disk } => {661+ Action::ScreenshotWindowById {
662+ id,
663+ write_to_disk,
664+ path,
665+ } => {
656 let mut windows = self.niri.layout.windows();666 let mut windows = self.niri.layout.windows();
657 let window = windows.find(|(_, m)| m.id().get() == id);667 let window = windows.find(|(_, m)| m.id().get() == id);
658 if let Some((Some(monitor), mapped)) = window {668 if let Some((Some(monitor), mapped)) = window {
659 let output = monitor.output();669 let output = monitor.output();
660 self.backend.with_primary_renderer(|renderer| {670 self.backend.with_primary_renderer(|renderer| {
661- if let Err(err) =671+ if let Err(err) = self.niri.screenshot_window(
662- self.niri672+ renderer,
663- .screenshot_window(renderer, output, mapped, write_to_disk)673+ output,
664- {674+ mapped,
675+ write_to_disk,
676+ path,
677+ ) {
665 warn!("error taking screenshot: {err:?}");678 warn!("error taking screenshot: {err:?}");
666 }679 }
667 });680 });
src/ipc/client.rsmodified+31 -4
@@ -1,20 +1,34 @@
1 use std::io::ErrorKind;1 use std::io::ErrorKind;
2 use std::iter::Peekable;2 use std::iter::Peekable;
3-use std::slice;3+use std::path::Path;
4+use std::{env, slice};
4 5
5 use anyhow::{anyhow, bail, Context};6 use anyhow::{anyhow, bail, Context};
6 use niri_config::OutputName;7 use niri_config::OutputName;
7 use niri_ipc::socket::Socket;8 use niri_ipc::socket::Socket;
8 use niri_ipc::{9 use niri_ipc::{
9- Event, KeyboardLayouts, LogicalOutput, Mode, Output, OutputConfigChanged, Overview, Request,10+ Action, Event, KeyboardLayouts, LogicalOutput, Mode, Output, OutputConfigChanged, Overview,
10- Response, Transform, Window, WindowLayout,11+ Request, Response, Transform, Window, WindowLayout,
11 };12 };
12 use serde_json::json;13 use serde_json::json;
13 14
14 use crate::cli::Msg;15 use crate::cli::Msg;
15 use crate::utils::version;16 use crate::utils::version;
16 17
17-pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> {18+pub fn handle_msg(mut msg: Msg, json: bool) -> anyhow::Result<()> {
19+ // For actions taking paths, prepend the niri CLI's working directory.
20+ if let Msg::Action {
21+ action:
22+ Action::Screenshot { path, .. }
23+ | Action::ScreenshotScreen { path, .. }
24+ | Action::ScreenshotWindow { path, .. },
25+ } = &mut msg
26+ {
27+ if let Some(path) = path {
28+ ensure_absolute_path(path).context("error making the path absolute")?;
29+ }
30+ }
31+
18 let request = match &msg {32 let request = match &msg {
19 Msg::Version => Request::Version,33 Msg::Version => Request::Version,
20 Msg::Outputs => Request::Outputs,34 Msg::Outputs => Request::Outputs,
@@ -668,6 +682,19 @@ fn fmt_rounded(x: f64) -> String {
668 }682 }
669 }683 }
670 684
685+fn ensure_absolute_path(path: &mut String) -> anyhow::Result<()> {
686+ let p = Path::new(path);
687+ if p.is_relative() {
688+ let mut cwd = env::current_dir().context("error getting current working directory")?;
689+ cwd.push(p);
690+ match cwd.into_os_string().into_string() {
691+ Ok(absolute) => *path = absolute,
692+ Err(cwd) => bail!("couldn't convert absolute path to string: {cwd:?}"),
693+ }
694+ }
695+ Ok(())
696+}
697+
671 #[cfg(test)]698 #[cfg(test)]
672 mod tests {699 mod tests {
673 use insta::assert_snapshot;700 use insta::assert_snapshot;
src/ipc/server.rsmodified+22 -3
@@ -2,7 +2,7 @@ use std::cell::RefCell;
2 use std::collections::HashSet;2 use std::collections::HashSet;
3 use std::ffi::OsStr;3 use std::ffi::OsStr;
4 use std::os::unix::net::{UnixListener, UnixStream};4 use std::os::unix::net::{UnixListener, UnixStream};
5-use std::path::PathBuf;5+use std::path::{Path, PathBuf};
6 use std::rc::Rc;6 use std::rc::Rc;
7 use std::sync::{Arc, Mutex};7 use std::sync::{Arc, Mutex};
8 use std::{env, io, process};8 use std::{env, io, process};
@@ -17,8 +17,8 @@ use futures_util::{select_biased, AsyncBufReadExt, AsyncWrite, AsyncWriteExt, Fu
17 use niri_config::OutputName;17 use niri_config::OutputName;
18 use niri_ipc::state::{EventStreamState, EventStreamStatePart as _};18 use niri_ipc::state::{EventStreamState, EventStreamStatePart as _};
19 use niri_ipc::{19 use niri_ipc::{
20- Event, KeyboardLayouts, OutputConfigChanged, Overview, Reply, Request, Response, WindowLayout,20+ Action, Event, KeyboardLayouts, OutputConfigChanged, Overview, Reply, Request, Response,
21- Workspace,21+ WindowLayout, Workspace,
22 };22 };
23 use smithay::desktop::layer_map_for_output;23 use smithay::desktop::layer_map_for_output;
24 use smithay::input::pointer::{24 use smithay::input::pointer::{
@@ -379,6 +379,8 @@ async fn process(ctx: &ClientCtx, request: Request) -> Reply {
379 Response::PickedColor(color)379 Response::PickedColor(color)
380 }380 }
381 Request::Action(action) => {381 Request::Action(action) => {
382+ validate_action(&action)?;
383+
382 let (tx, rx) = async_channel::bounded(1);384 let (tx, rx) = async_channel::bounded(1);
383 385
384 let action = niri_config::Action::from(action);386 let action = niri_config::Action::from(action);
@@ -451,6 +453,23 @@ async fn process(ctx: &ClientCtx, request: Request) -> Reply {
451 Ok(response)453 Ok(response)
452 }454 }
453 455
456+fn validate_action(action: &Action) -> Result<(), String> {
457+ if let Action::Screenshot { path, .. }
458+ | Action::ScreenshotScreen { path, .. }
459+ | Action::ScreenshotWindow { path, .. } = action
460+ {
461+ if let Some(path) = path {
462+ // Relative paths are resolved against the niri compositor's working directory, which
463+ // is almost certainly not what you want.
464+ if !Path::new(path).is_absolute() {
465+ return Err(format!("path must be absolute: {path}"));
466+ }
467+ }
468+ }
469+
470+ Ok(())
471+}
472+
454 async fn handle_event_stream_client(client: EventStreamClient) -> anyhow::Result<()> {473 async fn handle_event_stream_client(client: EventStreamClient) -> anyhow::Result<()> {
455 let EventStreamClient {474 let EventStreamClient {
456 events,475 events,
src/niri.rsmodified+32 -18
@@ -1835,7 +1835,7 @@ impl State {
1835 self.niri.output_management_state.notify_changes(new_config);1835 self.niri.output_management_state.notify_changes(new_config);
1836 }1836 }
1837 1837
1838- pub fn open_screenshot_ui(&mut self, show_pointer: bool) {1838+ pub fn open_screenshot_ui(&mut self, show_pointer: bool, path: Option<String>) {
1839 if self.niri.is_locked() || self.niri.screenshot_ui.is_open() {1839 if self.niri.is_locked() || self.niri.screenshot_ui.is_open() {
1840 return;1840 return;
1841 }1841 }
@@ -1876,7 +1876,7 @@ impl State {
1876 self.backend.with_primary_renderer(|renderer| {1876 self.backend.with_primary_renderer(|renderer| {
1877 self.niri1877 self.niri
1878 .screenshot_ui1878 .screenshot_ui
1879- .open(renderer, screenshots, default_output, show_pointer)1879+ .open(renderer, screenshots, default_output, show_pointer, path)
1880 });1880 });
1881 1881
1882 self.niri1882 self.niri
@@ -1902,14 +1902,15 @@ impl State {
1902 }1902 }
1903 1903
1904 pub fn confirm_screenshot(&mut self, write_to_disk: bool) {1904 pub fn confirm_screenshot(&mut self, write_to_disk: bool) {
1905- if !self.niri.screenshot_ui.is_open() {1905+ let ScreenshotUi::Open { path, .. } = &mut self.niri.screenshot_ui else {
1906 return;1906 return;
1907- }1907+ };
1908+ let path = path.take();
1908 1909
1909 self.backend.with_primary_renderer(|renderer| {1910 self.backend.with_primary_renderer(|renderer| {
1910 match self.niri.screenshot_ui.capture(renderer) {1911 match self.niri.screenshot_ui.capture(renderer) {
1911 Ok((size, pixels)) => {1912 Ok((size, pixels)) => {
1912- if let Err(err) = self.niri.save_screenshot(size, pixels, write_to_disk) {1913+ if let Err(err) = self.niri.save_screenshot(size, pixels, write_to_disk, path) {
1913 warn!("error saving screenshot: {err:?}");1914 warn!("error saving screenshot: {err:?}");
1914 }1915 }
1915 }1916 }
@@ -5533,6 +5534,7 @@ impl Niri {
5533 output: &Output,5534 output: &Output,
5534 write_to_disk: bool,5535 write_to_disk: bool,
5535 include_pointer: bool,5536 include_pointer: bool,
5537+ path: Option<String>,
5536 ) -> anyhow::Result<()> {5538 ) -> anyhow::Result<()> {
5537 let _span = tracy_client::span!("Niri::screenshot");5539 let _span = tracy_client::span!("Niri::screenshot");
5538 5540
@@ -5559,7 +5561,7 @@ impl Niri {
5559 elements,5561 elements,
5560 )?;5562 )?;
5561 5563
5562- self.save_screenshot(size, pixels, write_to_disk)5564+ self.save_screenshot(size, pixels, write_to_disk, path)
5563 .context("error saving screenshot")5565 .context("error saving screenshot")
5564 }5566 }
5565 5567
@@ -5569,6 +5571,7 @@ impl Niri {
5569 output: &Output,5571 output: &Output,
5570 mapped: &Mapped,5572 mapped: &Mapped,
5571 write_to_disk: bool,5573 write_to_disk: bool,
5574+ path: Option<String>,
5572 ) -> anyhow::Result<()> {5575 ) -> anyhow::Result<()> {
5573 let _span = tracy_client::span!("Niri::screenshot_window");5576 let _span = tracy_client::span!("Niri::screenshot_window");
5574 5577
@@ -5600,7 +5603,7 @@ impl Niri {
5600 elements,5603 elements,
5601 )?;5604 )?;
5602 5605
5603- self.save_screenshot(geo.size, pixels, write_to_disk)5606+ self.save_screenshot(geo.size, pixels, write_to_disk, path)
5604 .context("error saving screenshot")5607 .context("error saving screenshot")
5605 }5608 }
5606 5609
@@ -5609,14 +5612,20 @@ impl Niri {
5609 size: Size<i32, Physical>,5612 size: Size<i32, Physical>,
5610 pixels: Vec<u8>,5613 pixels: Vec<u8>,
5611 write_to_disk: bool,5614 write_to_disk: bool,
5615+ path_arg: Option<String>,
5612 ) -> anyhow::Result<()> {5616 ) -> anyhow::Result<()> {
5613 let path = write_to_disk5617 let path = write_to_disk
5614- .then(|| match make_screenshot_path(&self.config.borrow()) {5618+ .then(|| {
5615- Ok(path) => path,5619+ // When given an explicit path, don't try to strftime it or create parents.
5616- Err(err) => {5620+ path_arg.map(|p| (PathBuf::from(p), false)).or_else(|| {
5617- warn!("error making screenshot path: {err:?}");5621+ match make_screenshot_path(&self.config.borrow()) {
5618- None5622+ Ok(path) => path.map(|p| (p, true)),
5619- }5623+ Err(err) => {
5624+ warn!("error making screenshot path: {err:?}");
5625+ None
5626+ }
5627+ }
5628+ })
5620 })5629 })
5621 .flatten();5630 .flatten();
5622 5631
@@ -5652,13 +5661,18 @@ impl Niri {
5652 5661
5653 let mut image_path = None;5662 let mut image_path = None;
5654 5663
5655- if let Some(path) = path {5664+ if let Some((path, create_parent)) = path {
5656 debug!("saving screenshot to {path:?}");5665 debug!("saving screenshot to {path:?}");
5657 5666
5658- if let Some(parent) = path.parent() {5667+ if create_parent {
5659- if let Err(err) = std::fs::create_dir(parent) {5668+ if let Some(parent) = path.parent() {
5660- if err.kind() != std::io::ErrorKind::AlreadyExists {5669+ // Relative paths with one component, i.e. "test.png", have Some("") parent.
5661- warn!("error creating screenshot directory: {err:?}");5670+ if !parent.as_os_str().is_empty() {
5671+ if let Err(err) = std::fs::create_dir(parent) {
5672+ if err.kind() != std::io::ErrorKind::AlreadyExists {
5673+ warn!("error creating screenshot directory: {err:?}");
5674+ }
5675+ }
5662 }5676 }
5663 }5677 }
5664 }5678 }
src/ui/hotkey_overlay.rsmodified+10 -10
@@ -263,7 +263,7 @@ fn collect_actions(config: &Config) -> Vec<&Action> {
263 // Screenshot is not as important, can omit if not bound.263 // Screenshot is not as important, can omit if not bound.
264 if let Some(bind) = binds264 if let Some(bind) = binds
265 .iter()265 .iter()
266- .find(|bind| matches!(bind.action, Action::Screenshot(_)))266+ .find(|bind| matches!(bind.action, Action::Screenshot(_, _)))
267 {267 {
268 actions.push(&bind.action);268 actions.push(&bind.action);
269 }269 }
@@ -479,7 +479,7 @@ fn action_name(action: &Action) -> String {
479 String::from("Switch Focus Between Floating and Tiling")479 String::from("Switch Focus Between Floating and Tiling")
480 }480 }
481 Action::ToggleOverview => String::from("Open the Overview"),481 Action::ToggleOverview => String::from("Open the Overview"),
482- Action::Screenshot(_) => String::from("Take a Screenshot"),482+ Action::Screenshot(_, _) => String::from("Take a Screenshot"),
483 Action::Spawn(args) => format!(483 Action::Spawn(args) => format!(
484 "Spawn <span face='monospace' bgcolor='#000000'>{}</span>",484 "Spawn <span face='monospace' bgcolor='#000000'>{}</span>",
485 args.first().unwrap_or(&String::new())485 args.first().unwrap_or(&String::new())
@@ -620,7 +620,7 @@ mod tests {
620 #[test]620 #[test]
621 fn test_format_bind() {621 fn test_format_bind() {
622 // Not bound.622 // Not bound.
623- assert_snapshot!(check("", Action::Screenshot(true)), @" (not bound) : Take a Screenshot");623+ assert_snapshot!(check("", Action::Screenshot(true, None)), @" (not bound) : Take a Screenshot");
624 624
625 // Bound with a default title.625 // Bound with a default title.
626 assert_snapshot!(626 assert_snapshot!(
@@ -628,7 +628,7 @@ mod tests {
628 r#"binds {628 r#"binds {
629 Mod+P { screenshot; }629 Mod+P { screenshot; }
630 }"#,630 }"#,
631- Action::Screenshot(true),631+ Action::Screenshot(true, None),
632 ),632 ),
633 @" Super + P : Take a Screenshot"633 @" Super + P : Take a Screenshot"
634 );634 );
@@ -639,7 +639,7 @@ mod tests {
639 r#"binds {639 r#"binds {
640 Mod+P hotkey-overlay-title="Hello" { screenshot; }640 Mod+P hotkey-overlay-title="Hello" { screenshot; }
641 }"#,641 }"#,
642- Action::Screenshot(true),642+ Action::Screenshot(true, None),
643 ),643 ),
644 @" Super + P : Hello"644 @" Super + P : Hello"
645 );645 );
@@ -651,7 +651,7 @@ mod tests {
651 Mod+P { screenshot; }651 Mod+P { screenshot; }
652 Print { screenshot; }652 Print { screenshot; }
653 }"#,653 }"#,
654- Action::Screenshot(true),654+ Action::Screenshot(true, None),
655 ),655 ),
656 @" Super + P : Take a Screenshot"656 @" Super + P : Take a Screenshot"
657 );657 );
@@ -663,7 +663,7 @@ mod tests {
663 Mod+P { screenshot; }663 Mod+P { screenshot; }
664 Print hotkey-overlay-title="My Cool Bind" { screenshot; }664 Print hotkey-overlay-title="My Cool Bind" { screenshot; }
665 }"#,665 }"#,
666- Action::Screenshot(true),666+ Action::Screenshot(true, None),
667 ),667 ),
668 @" PrtSc : My Cool Bind"668 @" PrtSc : My Cool Bind"
669 );669 );
@@ -675,7 +675,7 @@ mod tests {
675 Mod+P hotkey-overlay-title="First" { screenshot; }675 Mod+P hotkey-overlay-title="First" { screenshot; }
676 Print hotkey-overlay-title="My Cool Bind" { screenshot; }676 Print hotkey-overlay-title="My Cool Bind" { screenshot; }
677 }"#,677 }"#,
678- Action::Screenshot(true),678+ Action::Screenshot(true, None),
679 ),679 ),
680 @" Super + P : First"680 @" Super + P : First"
681 );681 );
@@ -687,7 +687,7 @@ mod tests {
687 Mod+P { screenshot; }687 Mod+P { screenshot; }
688 Print hotkey-overlay-title=null { screenshot; }688 Print hotkey-overlay-title=null { screenshot; }
689 }"#,689 }"#,
690- Action::Screenshot(true),690+ Action::Screenshot(true, None),
691 ),691 ),
692 @"None"692 @"None"
693 );693 );
@@ -699,7 +699,7 @@ mod tests {
699 Mod+P hotkey-overlay-title="Hello" { screenshot; }699 Mod+P hotkey-overlay-title="Hello" { screenshot; }
700 Print hotkey-overlay-title=null { screenshot; }700 Print hotkey-overlay-title=null { screenshot; }
701 }"#,701 }"#,
702- Action::Screenshot(true),702+ Action::Screenshot(true, None),
703 ),703 ),
704 @" Super + P : Hello"704 @" Super + P : Hello"
705 );705 );
src/ui/screenshot_ui.rsmodified+3 -0
@@ -63,6 +63,7 @@ pub enum ScreenshotUi {
63 open_anim: Animation,63 open_anim: Animation,
64 clock: Clock,64 clock: Clock,
65 config: Rc<RefCell<Config>>,65 config: Rc<RefCell<Config>>,
66+ path: Option<String>,
66 },67 },
67 }68 }
68 69
@@ -141,6 +142,7 @@ impl ScreenshotUi {
141 screenshots: HashMap<Output, [OutputScreenshot; 3]>,142 screenshots: HashMap<Output, [OutputScreenshot; 3]>,
142 default_output: Output,143 default_output: Output,
143 show_pointer: bool,144 show_pointer: bool,
145+ path: Option<String>,
144 ) -> bool {146 ) -> bool {
145 if screenshots.is_empty() {147 if screenshots.is_empty() {
146 return false;148 return false;
@@ -235,6 +237,7 @@ impl ScreenshotUi {
235 open_anim,237 open_anim,
236 clock: clock.clone(),238 clock: clock.clone(),
237 config: config.clone(),239 config: config.clone(),
240+ path,
238 };241 };
239 242
240 self.update_buffers();243 self.update_buffers();