Add --path argument for niri msg screenshot* commands (#2126)
Browse files at this commit8 changed files +178 -58
- niri-config/src/binds.rs +26 -6
- niri-ipc/src/lib.rs +24 -0
- src/input/mod.rs +30 -17
- src/ipc/client.rs +31 -4
- src/ipc/server.rs +22 -3
- src/niri.rs +32 -18
- src/ui/hotkey_overlay.rs +10 -10
- src/ui/screenshot_ui.rs +3 -0
niri-config/src/binds.rsmodified+26 -6
| @@ -118,16 +118,27 @@ pub enum Action { | ||
| 118 | 118 | CancelScreenshot, |
| 119 | 119 | #[knuffel(skip)] |
| 120 | 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 | 126 | ScreenshotScreen( |
| 123 | 127 | #[knuffel(property(name = "write-to-disk"), default = true)] bool, |
| 124 | 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 | 137 | #[knuffel(skip)] |
| 128 | 138 | ScreenshotWindowById { |
| 129 | 139 | id: u64, |
| 130 | 140 | write_to_disk: bool, |
| 141 | + path: Option<String>, | |
| 131 | 142 | }, |
| 132 | 143 | ToggleKeyboardShortcutsInhibit, |
| 133 | 144 | CloseWindow, |
| @@ -364,19 +375,28 @@ impl From<niri_ipc::Action> for Action { | ||
| 364 | 375 | niri_ipc::Action::Spawn { command } => Self::Spawn(command), |
| 365 | 376 | niri_ipc::Action::SpawnSh { command } => Self::SpawnSh(command), |
| 366 | 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 | 381 | niri_ipc::Action::ScreenshotScreen { |
| 369 | 382 | write_to_disk, |
| 370 | 383 | show_pointer, |
| 371 | - } => Self::ScreenshotScreen(write_to_disk, show_pointer), | |
| 384 | + path, | |
| 385 | + } => Self::ScreenshotScreen(write_to_disk, show_pointer, path), | |
| 372 | 386 | niri_ipc::Action::ScreenshotWindow { |
| 373 | 387 | id: None, |
| 374 | 388 | write_to_disk, |
| 375 | - } => Self::ScreenshotWindow(write_to_disk), | |
| 389 | + path, | |
| 390 | + } => Self::ScreenshotWindow(write_to_disk, path), | |
| 376 | 391 | niri_ipc::Action::ScreenshotWindow { |
| 377 | 392 | id: Some(id), |
| 378 | 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 | 400 | niri_ipc::Action::ToggleKeyboardShortcutsInhibit {} => { |
| 381 | 401 | Self::ToggleKeyboardShortcutsInhibit |
| 382 | 402 | } |
niri-ipc/src/lib.rsmodified+24 -0
| @@ -220,6 +220,14 @@ pub enum Action { | ||
| 220 | 220 | /// Whether to show the mouse pointer by default in the screenshot UI. |
| 221 | 221 | #[cfg_attr(feature = "clap", arg(short = 'p', long, action = clap::ArgAction::Set, default_value_t = true))] |
| 222 | 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 | 232 | /// Screenshot the focused screen. |
| 225 | 233 | ScreenshotScreen { |
| @@ -232,6 +240,14 @@ pub enum Action { | ||
| 232 | 240 | /// Whether to include the mouse pointer in the screenshot. |
| 233 | 241 | #[cfg_attr(feature = "clap", arg(short = 'p', long, action = clap::ArgAction::Set, default_value_t = true))] |
| 234 | 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 | 252 | /// Screenshot a window. |
| 237 | 253 | #[cfg_attr(feature = "clap", clap(about = "Screenshot the focused window"))] |
| @@ -246,6 +262,14 @@ pub enum Action { | ||
| 246 | 262 | /// The screenshot is saved according to the `screenshot-path` config setting. |
| 247 | 263 | #[cfg_attr(feature = "clap", arg(short = 'd', long, action = clap::ArgAction::Set, default_value_t = true))] |
| 248 | 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 | 274 | /// Enable or disable the keyboard shortcuts inhibitor (if any) for the focused surface. |
| 251 | 275 | ToggleKeyboardShortcutsInhibit {}, |
src/input/mod.rsmodified+30 -17
| @@ -605,14 +605,17 @@ impl State { | ||
| 605 | 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 | 609 | let active = self.niri.layout.active_output().cloned(); |
| 610 | 610 | if let Some(active) = active { |
| 611 | 611 | self.backend.with_primary_renderer(|renderer| { |
| 612 | - if let Err(err) = | |
| 613 | - self.niri | |
| 614 | - .screenshot(renderer, &active, write_to_disk, show_pointer) | |
| 615 | - { | |
| 612 | + if let Err(err) = self.niri.screenshot( | |
| 613 | + renderer, | |
| 614 | + &active, | |
| 615 | + write_to_disk, | |
| 616 | + show_pointer, | |
| 617 | + path, | |
| 618 | + ) { | |
| 616 | 619 | warn!("error taking screenshot: {err:?}"); |
| 617 | 620 | } |
| 618 | 621 | }); |
| @@ -636,32 +639,42 @@ impl State { | ||
| 636 | 639 | self.niri.screenshot_ui.toggle_pointer(); |
| 637 | 640 | self.niri.queue_redraw_all(); |
| 638 | 641 | } |
| 639 | - Action::Screenshot(show_cursor) => { | |
| 640 | - self.open_screenshot_ui(show_cursor); | |
| 642 | + Action::Screenshot(show_cursor, path) => { | |
| 643 | + self.open_screenshot_ui(show_cursor, path); | |
| 641 | 644 | } |
| 642 | - Action::ScreenshotWindow(write_to_disk) => { | |
| 645 | + Action::ScreenshotWindow(write_to_disk, path) => { | |
| 643 | 646 | let focus = self.niri.layout.focus_with_output(); |
| 644 | 647 | if let Some((mapped, output)) = focus { |
| 645 | 648 | self.backend.with_primary_renderer(|renderer| { |
| 646 | - if let Err(err) = | |
| 647 | - self.niri | |
| 648 | - .screenshot_window(renderer, output, mapped, write_to_disk) | |
| 649 | - { | |
| 649 | + if let Err(err) = self.niri.screenshot_window( | |
| 650 | + renderer, | |
| 651 | + output, | |
| 652 | + mapped, | |
| 653 | + write_to_disk, | |
| 654 | + path, | |
| 655 | + ) { | |
| 650 | 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 | 666 | let mut windows = self.niri.layout.windows(); |
| 657 | 667 | let window = windows.find(|(_, m)| m.id().get() == id); |
| 658 | 668 | if let Some((Some(monitor), mapped)) = window { |
| 659 | 669 | let output = monitor.output(); |
| 660 | 670 | self.backend.with_primary_renderer(|renderer| { |
| 661 | - if let Err(err) = | |
| 662 | - self.niri | |
| 663 | - .screenshot_window(renderer, output, mapped, write_to_disk) | |
| 664 | - { | |
| 671 | + if let Err(err) = self.niri.screenshot_window( | |
| 672 | + renderer, | |
| 673 | + output, | |
| 674 | + mapped, | |
| 675 | + write_to_disk, | |
| 676 | + path, | |
| 677 | + ) { | |
| 665 | 678 | warn!("error taking screenshot: {err:?}"); |
| 666 | 679 | } |
| 667 | 680 | }); |
src/ipc/client.rsmodified+31 -4
| @@ -1,20 +1,34 @@ | ||
| 1 | 1 | use std::io::ErrorKind; |
| 2 | 2 | use std::iter::Peekable; |
| 3 | -use std::slice; | |
| 3 | +use std::path::Path; | |
| 4 | +use std::{env, slice}; | |
| 4 | 5 | |
| 5 | 6 | use anyhow::{anyhow, bail, Context}; |
| 6 | 7 | use niri_config::OutputName; |
| 7 | 8 | use niri_ipc::socket::Socket; |
| 8 | 9 | use niri_ipc::{ |
| 9 | - Event, KeyboardLayouts, LogicalOutput, Mode, Output, OutputConfigChanged, Overview, Request, | |
| 10 | - Response, Transform, Window, WindowLayout, | |
| 10 | + Action, Event, KeyboardLayouts, LogicalOutput, Mode, Output, OutputConfigChanged, Overview, | |
| 11 | + Request, Response, Transform, Window, WindowLayout, | |
| 11 | 12 | }; |
| 12 | 13 | use serde_json::json; |
| 13 | 14 | |
| 14 | 15 | use crate::cli::Msg; |
| 15 | 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 | 32 | let request = match &msg { |
| 19 | 33 | Msg::Version => Request::Version, |
| 20 | 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 | 698 | #[cfg(test)] |
| 672 | 699 | mod tests { |
| 673 | 700 | use insta::assert_snapshot; |
src/ipc/server.rsmodified+22 -3
| @@ -2,7 +2,7 @@ use std::cell::RefCell; | ||
| 2 | 2 | use std::collections::HashSet; |
| 3 | 3 | use std::ffi::OsStr; |
| 4 | 4 | use std::os::unix::net::{UnixListener, UnixStream}; |
| 5 | -use std::path::PathBuf; | |
| 5 | +use std::path::{Path, PathBuf}; | |
| 6 | 6 | use std::rc::Rc; |
| 7 | 7 | use std::sync::{Arc, Mutex}; |
| 8 | 8 | use std::{env, io, process}; |
| @@ -17,8 +17,8 @@ use futures_util::{select_biased, AsyncBufReadExt, AsyncWrite, AsyncWriteExt, Fu | ||
| 17 | 17 | use niri_config::OutputName; |
| 18 | 18 | use niri_ipc::state::{EventStreamState, EventStreamStatePart as _}; |
| 19 | 19 | use niri_ipc::{ |
| 20 | - Event, KeyboardLayouts, OutputConfigChanged, Overview, Reply, Request, Response, WindowLayout, | |
| 21 | - Workspace, | |
| 20 | + Action, Event, KeyboardLayouts, OutputConfigChanged, Overview, Reply, Request, Response, | |
| 21 | + WindowLayout, Workspace, | |
| 22 | 22 | }; |
| 23 | 23 | use smithay::desktop::layer_map_for_output; |
| 24 | 24 | use smithay::input::pointer::{ |
| @@ -379,6 +379,8 @@ async fn process(ctx: &ClientCtx, request: Request) -> Reply { | ||
| 379 | 379 | Response::PickedColor(color) |
| 380 | 380 | } |
| 381 | 381 | Request::Action(action) => { |
| 382 | + validate_action(&action)?; | |
| 383 | + | |
| 382 | 384 | let (tx, rx) = async_channel::bounded(1); |
| 383 | 385 | |
| 384 | 386 | let action = niri_config::Action::from(action); |
| @@ -451,6 +453,23 @@ async fn process(ctx: &ClientCtx, request: Request) -> Reply { | ||
| 451 | 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 | 473 | async fn handle_event_stream_client(client: EventStreamClient) -> anyhow::Result<()> { |
| 455 | 474 | let EventStreamClient { |
| 456 | 475 | events, |
src/niri.rsmodified+32 -18
| @@ -1835,7 +1835,7 @@ impl State { | ||
| 1835 | 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 | 1839 | if self.niri.is_locked() || self.niri.screenshot_ui.is_open() { |
| 1840 | 1840 | return; |
| 1841 | 1841 | } |
| @@ -1876,7 +1876,7 @@ impl State { | ||
| 1876 | 1876 | self.backend.with_primary_renderer(|renderer| { |
| 1877 | 1877 | self.niri |
| 1878 | 1878 | .screenshot_ui |
| 1879 | - .open(renderer, screenshots, default_output, show_pointer) | |
| 1879 | + .open(renderer, screenshots, default_output, show_pointer, path) | |
| 1880 | 1880 | }); |
| 1881 | 1881 | |
| 1882 | 1882 | self.niri |
| @@ -1902,14 +1902,15 @@ impl State { | ||
| 1902 | 1902 | } |
| 1903 | 1903 | |
| 1904 | 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 | 1906 | return; |
| 1907 | - } | |
| 1907 | + }; | |
| 1908 | + let path = path.take(); | |
| 1908 | 1909 | |
| 1909 | 1910 | self.backend.with_primary_renderer(|renderer| { |
| 1910 | 1911 | match self.niri.screenshot_ui.capture(renderer) { |
| 1911 | 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 | 1914 | warn!("error saving screenshot: {err:?}"); |
| 1914 | 1915 | } |
| 1915 | 1916 | } |
| @@ -5533,6 +5534,7 @@ impl Niri { | ||
| 5533 | 5534 | output: &Output, |
| 5534 | 5535 | write_to_disk: bool, |
| 5535 | 5536 | include_pointer: bool, |
| 5537 | + path: Option<String>, | |
| 5536 | 5538 | ) -> anyhow::Result<()> { |
| 5537 | 5539 | let _span = tracy_client::span!("Niri::screenshot"); |
| 5538 | 5540 | |
| @@ -5559,7 +5561,7 @@ impl Niri { | ||
| 5559 | 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 | 5565 | .context("error saving screenshot") |
| 5564 | 5566 | } |
| 5565 | 5567 | |
| @@ -5569,6 +5571,7 @@ impl Niri { | ||
| 5569 | 5571 | output: &Output, |
| 5570 | 5572 | mapped: &Mapped, |
| 5571 | 5573 | write_to_disk: bool, |
| 5574 | + path: Option<String>, | |
| 5572 | 5575 | ) -> anyhow::Result<()> { |
| 5573 | 5576 | let _span = tracy_client::span!("Niri::screenshot_window"); |
| 5574 | 5577 | |
| @@ -5600,7 +5603,7 @@ impl Niri { | ||
| 5600 | 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 | 5607 | .context("error saving screenshot") |
| 5605 | 5608 | } |
| 5606 | 5609 | |
| @@ -5609,14 +5612,20 @@ impl Niri { | ||
| 5609 | 5612 | size: Size<i32, Physical>, |
| 5610 | 5613 | pixels: Vec<u8>, |
| 5611 | 5614 | write_to_disk: bool, |
| 5615 | + path_arg: Option<String>, | |
| 5612 | 5616 | ) -> anyhow::Result<()> { |
| 5613 | 5617 | let path = write_to_disk |
| 5614 | - .then(|| match make_screenshot_path(&self.config.borrow()) { | |
| 5615 | - Ok(path) => path, | |
| 5616 | - Err(err) => { | |
| 5617 | - warn!("error making screenshot path: {err:?}"); | |
| 5618 | - None | |
| 5619 | - } | |
| 5618 | + .then(|| { | |
| 5619 | + // When given an explicit path, don't try to strftime it or create parents. | |
| 5620 | + path_arg.map(|p| (PathBuf::from(p), false)).or_else(|| { | |
| 5621 | + match make_screenshot_path(&self.config.borrow()) { | |
| 5622 | + Ok(path) => path.map(|p| (p, true)), | |
| 5623 | + Err(err) => { | |
| 5624 | + warn!("error making screenshot path: {err:?}"); | |
| 5625 | + None | |
| 5626 | + } | |
| 5627 | + } | |
| 5628 | + }) | |
| 5620 | 5629 | }) |
| 5621 | 5630 | .flatten(); |
| 5622 | 5631 | |
| @@ -5652,13 +5661,18 @@ impl Niri { | ||
| 5652 | 5661 | |
| 5653 | 5662 | let mut image_path = None; |
| 5654 | 5663 | |
| 5655 | - if let Some(path) = path { | |
| 5664 | + if let Some((path, create_parent)) = path { | |
| 5656 | 5665 | debug!("saving screenshot to {path:?}"); |
| 5657 | 5666 | |
| 5658 | - if let Some(parent) = path.parent() { | |
| 5659 | - if let Err(err) = std::fs::create_dir(parent) { | |
| 5660 | - if err.kind() != std::io::ErrorKind::AlreadyExists { | |
| 5661 | - warn!("error creating screenshot directory: {err:?}"); | |
| 5667 | + if create_parent { | |
| 5668 | + if let Some(parent) = path.parent() { | |
| 5669 | + // Relative paths with one component, i.e. "test.png", have Some("") parent. | |
| 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 | 263 | // Screenshot is not as important, can omit if not bound. |
| 264 | 264 | if let Some(bind) = binds |
| 265 | 265 | .iter() |
| 266 | - .find(|bind| matches!(bind.action, Action::Screenshot(_))) | |
| 266 | + .find(|bind| matches!(bind.action, Action::Screenshot(_, _))) | |
| 267 | 267 | { |
| 268 | 268 | actions.push(&bind.action); |
| 269 | 269 | } |
| @@ -479,7 +479,7 @@ fn action_name(action: &Action) -> String { | ||
| 479 | 479 | String::from("Switch Focus Between Floating and Tiling") |
| 480 | 480 | } |
| 481 | 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 | 483 | Action::Spawn(args) => format!( |
| 484 | 484 | "Spawn <span face='monospace' bgcolor='#000000'>{}</span>", |
| 485 | 485 | args.first().unwrap_or(&String::new()) |
| @@ -620,7 +620,7 @@ mod tests { | ||
| 620 | 620 | #[test] |
| 621 | 621 | fn test_format_bind() { |
| 622 | 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 | 625 | // Bound with a default title. |
| 626 | 626 | assert_snapshot!( |
| @@ -628,7 +628,7 @@ mod tests { | ||
| 628 | 628 | r#"binds { |
| 629 | 629 | Mod+P { screenshot; } |
| 630 | 630 | }"#, |
| 631 | - Action::Screenshot(true), | |
| 631 | + Action::Screenshot(true, None), | |
| 632 | 632 | ), |
| 633 | 633 | @" Super + P : Take a Screenshot" |
| 634 | 634 | ); |
| @@ -639,7 +639,7 @@ mod tests { | ||
| 639 | 639 | r#"binds { |
| 640 | 640 | Mod+P hotkey-overlay-title="Hello" { screenshot; } |
| 641 | 641 | }"#, |
| 642 | - Action::Screenshot(true), | |
| 642 | + Action::Screenshot(true, None), | |
| 643 | 643 | ), |
| 644 | 644 | @" Super + P : Hello" |
| 645 | 645 | ); |
| @@ -651,7 +651,7 @@ mod tests { | ||
| 651 | 651 | Mod+P { screenshot; } |
| 652 | 652 | Print { screenshot; } |
| 653 | 653 | }"#, |
| 654 | - Action::Screenshot(true), | |
| 654 | + Action::Screenshot(true, None), | |
| 655 | 655 | ), |
| 656 | 656 | @" Super + P : Take a Screenshot" |
| 657 | 657 | ); |
| @@ -663,7 +663,7 @@ mod tests { | ||
| 663 | 663 | Mod+P { screenshot; } |
| 664 | 664 | Print hotkey-overlay-title="My Cool Bind" { screenshot; } |
| 665 | 665 | }"#, |
| 666 | - Action::Screenshot(true), | |
| 666 | + Action::Screenshot(true, None), | |
| 667 | 667 | ), |
| 668 | 668 | @" PrtSc : My Cool Bind" |
| 669 | 669 | ); |
| @@ -675,7 +675,7 @@ mod tests { | ||
| 675 | 675 | Mod+P hotkey-overlay-title="First" { screenshot; } |
| 676 | 676 | Print hotkey-overlay-title="My Cool Bind" { screenshot; } |
| 677 | 677 | }"#, |
| 678 | - Action::Screenshot(true), | |
| 678 | + Action::Screenshot(true, None), | |
| 679 | 679 | ), |
| 680 | 680 | @" Super + P : First" |
| 681 | 681 | ); |
| @@ -687,7 +687,7 @@ mod tests { | ||
| 687 | 687 | Mod+P { screenshot; } |
| 688 | 688 | Print hotkey-overlay-title=null { screenshot; } |
| 689 | 689 | }"#, |
| 690 | - Action::Screenshot(true), | |
| 690 | + Action::Screenshot(true, None), | |
| 691 | 691 | ), |
| 692 | 692 | @"None" |
| 693 | 693 | ); |
| @@ -699,7 +699,7 @@ mod tests { | ||
| 699 | 699 | Mod+P hotkey-overlay-title="Hello" { screenshot; } |
| 700 | 700 | Print hotkey-overlay-title=null { screenshot; } |
| 701 | 701 | }"#, |
| 702 | - Action::Screenshot(true), | |
| 702 | + Action::Screenshot(true, None), | |
| 703 | 703 | ), |
| 704 | 704 | @" Super + P : Hello" |
| 705 | 705 | ); |
src/ui/screenshot_ui.rsmodified+3 -0
| @@ -63,6 +63,7 @@ pub enum ScreenshotUi { | ||
| 63 | 63 | open_anim: Animation, |
| 64 | 64 | clock: Clock, |
| 65 | 65 | config: Rc<RefCell<Config>>, |
| 66 | + path: Option<String>, | |
| 66 | 67 | }, |
| 67 | 68 | } |
| 68 | 69 | |
| @@ -141,6 +142,7 @@ impl ScreenshotUi { | ||
| 141 | 142 | screenshots: HashMap<Output, [OutputScreenshot; 3]>, |
| 142 | 143 | default_output: Output, |
| 143 | 144 | show_pointer: bool, |
| 145 | + path: Option<String>, | |
| 144 | 146 | ) -> bool { |
| 145 | 147 | if screenshots.is_empty() { |
| 146 | 148 | return false; |
| @@ -235,6 +237,7 @@ impl ScreenshotUi { | ||
| 235 | 237 | open_anim, |
| 236 | 238 | clock: clock.clone(), |
| 237 | 239 | config: config.clone(), |
| 240 | + path, | |
| 238 | 241 | }; |
| 239 | 242 | |
| 240 | 243 | self.update_buffers(); |