diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2023-10-31 08:57:44 +0400 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2023-10-31 08:57:44 +0400 |
| commit | 8fa5bf9a3644bb0548f85e83998781f7d055bb8d (patch) | |
| tree | 35bd1443c3f4bc352f87b0235dc50a9b47909840 /src/utils.rs | |
| parent | d854c2d699b15c68c4715dc6be803065c01f2fe6 (diff) | |
| download | niri-8fa5bf9a3644bb0548f85e83998781f7d055bb8d.tar.gz niri-8fa5bf9a3644bb0548f85e83998781f7d055bb8d.tar.bz2 niri-8fa5bf9a3644bb0548f85e83998781f7d055bb8d.zip | |
Make screenshot path configurable
Diffstat (limited to 'src/utils.rs')
| -rw-r--r-- | src/utils.rs | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/src/utils.rs b/src/utils.rs index 134112dc..92b6509c 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -12,6 +12,8 @@ use directories::UserDirs; use smithay::reexports::rustix::time::{clock_gettime, ClockId}; use smithay::utils::{Logical, Point, Rectangle}; +use crate::config::Config; + pub fn get_monotonic_time() -> Duration { let ts = clock_gettime(ClockId::Monotonic); Duration::new(ts.tv_sec as u64, ts.tv_nsec as u32) @@ -21,15 +23,22 @@ pub fn center(rect: Rectangle<i32, Logical>) -> Point<i32, Logical> { rect.loc + rect.size.downscale(2).to_point() } -pub fn make_screenshot_path() -> anyhow::Result<PathBuf> { - let dirs = UserDirs::new().context("error retrieving home directory")?; - let mut path = dirs.picture_dir().map(|p| p.to_owned()).unwrap_or_else(|| { - let mut dir = dirs.home_dir().to_owned(); - dir.push("Pictures"); - dir - }); - path.push("Screenshots"); +pub fn make_screenshot_path(config: &Config) -> anyhow::Result<Option<PathBuf>> { + let Some(mut path) = config.screenshot_path.clone() else { + return Ok(None); + }; + + if let Ok(rest) = path.strip_prefix("~") { + let dirs = UserDirs::new().context("error retrieving home directory")?; + path = [dirs.home_dir(), rest].iter().collect(); + } + + add_screenshot_filename(&mut path)?; + + Ok(Some(path)) +} +pub fn add_screenshot_filename(path: &mut PathBuf) -> anyhow::Result<()> { let mut buf = [0u8; 256]; let name; unsafe { @@ -53,7 +62,7 @@ pub fn make_screenshot_path() -> anyhow::Result<PathBuf> { path.push(name); - Ok(path) + Ok(()) } /// Spawns the command to run independently of the compositor. |
