forge
Explore
Log in

Don't you dare go Hollow

Extract make_screenshot_path()

Browse files at this commit

69f561cd6f9d9b87d5624dd09be0fd5660f9cf2eIvan MolodetskikhParent: 495cce0
src/niri.rsmodified+2 -23
@@ -8,7 +8,6 @@ use std::time::Duration;
88 use std::{env, thread};
99
1010 use anyhow::Context;
11-use directories::UserDirs;
1211 use sd_notify::NotifyState;
1312 use smithay::backend::allocator::dmabuf::Dmabuf;
1413 use smithay::backend::allocator::Fourcc;
@@ -56,7 +55,6 @@ use smithay::wayland::shell::xdg::XdgShellState;
5655 use smithay::wayland::shm::ShmState;
5756 use smithay::wayland::socket::ListeningSocketSource;
5857 use smithay::wayland::tablet_manager::TabletManagerState;
59-use time::OffsetDateTime;
6058 use zbus::fdo::RequestNameFlags;
6159
6260 use crate::backend::{Backend, Tty, Winit};
@@ -67,7 +65,7 @@ use crate::dbus::mutter_service_channel::ServiceChannel;
6765 use crate::frame_clock::FrameClock;
6866 use crate::layout::{MonitorRenderElement, MonitorSet};
6967 use crate::pw_utils::{Cast, PipeWire};
70-use crate::utils::{center, get_monotonic_time, load_default_cursor};
68+use crate::utils::{center, get_monotonic_time, load_default_cursor, make_screenshot_path};
7169 use crate::LoopData;
7270
7371 pub struct Niri {
@@ -1069,26 +1067,7 @@ impl Niri {
10691067 .context("error mapping texture")?;
10701068 let pixels = copy.to_vec();
10711069
1072- let dirs = UserDirs::new().context("error retrieving home directory")?;
1073- let mut path = dirs.picture_dir().map(|p| p.to_owned()).unwrap_or_else(|| {
1074- let mut dir = dirs.home_dir().to_owned();
1075- dir.push("Pictures");
1076- dir
1077- });
1078- path.push("Screenshots");
1079-
1080- unsafe {
1081- // are you kidding me
1082- time::util::local_offset::set_soundness(time::util::local_offset::Soundness::Unsound);
1083- };
1084-
1085- let now = OffsetDateTime::now_local().unwrap_or_else(|_| OffsetDateTime::now_utc());
1086- let desc = time::macros::format_description!(
1087- "Screenshot from [year]-[month]-[day] [hour]-[minute]-[second].png"
1088- );
1089- let name = now.format(desc).context("error formatting time")?;
1090- path.push(name);
1091-
1070+ let path = make_screenshot_path().context("error making screenshot path")?;
10921071 debug!("saving screenshot to {path:?}");
10931072
10941073 thread::spawn(move || {
src/utils.rsmodified+27 -0
@@ -1,13 +1,16 @@
11 use std::fs::File;
22 use std::io::Read;
3+use std::path::PathBuf;
34 use std::time::Duration;
45
56 use anyhow::{anyhow, Context};
7+use directories::UserDirs;
68 use smithay::backend::allocator::Fourcc;
79 use smithay::backend::renderer::element::texture::TextureBuffer;
810 use smithay::backend::renderer::gles::{GlesRenderer, GlesTexture};
911 use smithay::reexports::nix::time::{clock_gettime, ClockId};
1012 use smithay::utils::{Logical, Physical, Point, Rectangle, Transform};
13+use time::OffsetDateTime;
1114 use xcursor::parser::parse_xcursor;
1215 use xcursor::CursorTheme;
1316
@@ -80,3 +83,27 @@ pub fn load_default_cursor(
8083 .unwrap();
8184 (texture, (frame.xhot as i32, frame.yhot as i32).into())
8285 }
86+
87+pub fn make_screenshot_path() -> anyhow::Result<PathBuf> {
88+ let dirs = UserDirs::new().context("error retrieving home directory")?;
89+ let mut path = dirs.picture_dir().map(|p| p.to_owned()).unwrap_or_else(|| {
90+ let mut dir = dirs.home_dir().to_owned();
91+ dir.push("Pictures");
92+ dir
93+ });
94+ path.push("Screenshots");
95+
96+ unsafe {
97+ // are you kidding me
98+ time::util::local_offset::set_soundness(time::util::local_offset::Soundness::Unsound);
99+ };
100+
101+ let now = OffsetDateTime::now_local().unwrap_or_else(|_| OffsetDateTime::now_utc());
102+ let desc = time::macros::format_description!(
103+ "Screenshot from [year]-[month]-[day] [hour]-[minute]-[second].png"
104+ );
105+ let name = now.format(desc).context("error formatting time")?;
106+ path.push(name);
107+
108+ Ok(path)
109+}