aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2023-09-19 19:05:03 +0400
committerIvan Molodetskikh <yalterz@gmail.com>2023-09-19 19:05:03 +0400
commit69f561cd6f9d9b87d5624dd09be0fd5660f9cf2e (patch)
tree5fafa961e57a667052406fd66abe5ed46a83d083 /src
parent495cce054b0859901203eed7c27759bc6b636581 (diff)
downloadniri-69f561cd6f9d9b87d5624dd09be0fd5660f9cf2e.tar.gz
niri-69f561cd6f9d9b87d5624dd09be0fd5660f9cf2e.tar.bz2
niri-69f561cd6f9d9b87d5624dd09be0fd5660f9cf2e.zip
Extract make_screenshot_path()
Diffstat (limited to 'src')
-rw-r--r--src/niri.rs25
-rw-r--r--src/utils.rs27
2 files changed, 29 insertions, 23 deletions
diff --git a/src/niri.rs b/src/niri.rs
index 651b9075..cfe89532 100644
--- a/src/niri.rs
+++ b/src/niri.rs
@@ -8,7 +8,6 @@ use std::time::Duration;
use std::{env, thread};
use anyhow::Context;
-use directories::UserDirs;
use sd_notify::NotifyState;
use smithay::backend::allocator::dmabuf::Dmabuf;
use smithay::backend::allocator::Fourcc;
@@ -56,7 +55,6 @@ use smithay::wayland::shell::xdg::XdgShellState;
use smithay::wayland::shm::ShmState;
use smithay::wayland::socket::ListeningSocketSource;
use smithay::wayland::tablet_manager::TabletManagerState;
-use time::OffsetDateTime;
use zbus::fdo::RequestNameFlags;
use crate::backend::{Backend, Tty, Winit};
@@ -67,7 +65,7 @@ use crate::dbus::mutter_service_channel::ServiceChannel;
use crate::frame_clock::FrameClock;
use crate::layout::{MonitorRenderElement, MonitorSet};
use crate::pw_utils::{Cast, PipeWire};
-use crate::utils::{center, get_monotonic_time, load_default_cursor};
+use crate::utils::{center, get_monotonic_time, load_default_cursor, make_screenshot_path};
use crate::LoopData;
pub struct Niri {
@@ -1069,26 +1067,7 @@ impl Niri {
.context("error mapping texture")?;
let pixels = copy.to_vec();
- 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);
-
+ let path = make_screenshot_path().context("error making screenshot path")?;
debug!("saving screenshot to {path:?}");
thread::spawn(move || {
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)
+}