diff options
Diffstat (limited to 'src/utils.rs')
| -rw-r--r-- | src/utils.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/utils.rs b/src/utils.rs index b7dee6e2..adf14abb 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,13 +1,16 @@ use std::fs::File; use std::io::Read; +use std::path::PathBuf; use std::time::Duration; use anyhow::{anyhow, Context}; +use directories::UserDirs; use smithay::backend::allocator::Fourcc; use smithay::backend::renderer::element::texture::TextureBuffer; use smithay::backend::renderer::gles::{GlesRenderer, GlesTexture}; use smithay::reexports::nix::time::{clock_gettime, ClockId}; use smithay::utils::{Logical, Physical, Point, Rectangle, Transform}; +use time::OffsetDateTime; use xcursor::parser::parse_xcursor; use xcursor::CursorTheme; @@ -80,3 +83,27 @@ pub fn load_default_cursor( .unwrap(); (texture, (frame.xhot as i32, frame.yhot as i32).into()) } + +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"); + + unsafe { + // are you kidding me + time::util::local_offset::set_soundness(time::util::local_offset::Soundness::Unsound); + }; + + let now = OffsetDateTime::now_local().unwrap_or_else(|_| OffsetDateTime::now_utc()); + let desc = time::macros::format_description!( + "Screenshot from [year]-[month]-[day] [hour]-[minute]-[second].png" + ); + let name = now.format(desc).context("error formatting time")?; + path.push(name); + + Ok(path) +} |
