mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-23 02:05:33 +07:00
Extract make_screenshot_path()
This commit is contained in:
+2
-23
@@ -8,7 +8,6 @@ use std::time::Duration;
|
|||||||
use std::{env, thread};
|
use std::{env, thread};
|
||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use directories::UserDirs;
|
|
||||||
use sd_notify::NotifyState;
|
use sd_notify::NotifyState;
|
||||||
use smithay::backend::allocator::dmabuf::Dmabuf;
|
use smithay::backend::allocator::dmabuf::Dmabuf;
|
||||||
use smithay::backend::allocator::Fourcc;
|
use smithay::backend::allocator::Fourcc;
|
||||||
@@ -56,7 +55,6 @@ use smithay::wayland::shell::xdg::XdgShellState;
|
|||||||
use smithay::wayland::shm::ShmState;
|
use smithay::wayland::shm::ShmState;
|
||||||
use smithay::wayland::socket::ListeningSocketSource;
|
use smithay::wayland::socket::ListeningSocketSource;
|
||||||
use smithay::wayland::tablet_manager::TabletManagerState;
|
use smithay::wayland::tablet_manager::TabletManagerState;
|
||||||
use time::OffsetDateTime;
|
|
||||||
use zbus::fdo::RequestNameFlags;
|
use zbus::fdo::RequestNameFlags;
|
||||||
|
|
||||||
use crate::backend::{Backend, Tty, Winit};
|
use crate::backend::{Backend, Tty, Winit};
|
||||||
@@ -67,7 +65,7 @@ use crate::dbus::mutter_service_channel::ServiceChannel;
|
|||||||
use crate::frame_clock::FrameClock;
|
use crate::frame_clock::FrameClock;
|
||||||
use crate::layout::{MonitorRenderElement, MonitorSet};
|
use crate::layout::{MonitorRenderElement, MonitorSet};
|
||||||
use crate::pw_utils::{Cast, PipeWire};
|
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;
|
use crate::LoopData;
|
||||||
|
|
||||||
pub struct Niri {
|
pub struct Niri {
|
||||||
@@ -1069,26 +1067,7 @@ impl Niri {
|
|||||||
.context("error mapping texture")?;
|
.context("error mapping texture")?;
|
||||||
let pixels = copy.to_vec();
|
let pixels = copy.to_vec();
|
||||||
|
|
||||||
let dirs = UserDirs::new().context("error retrieving home directory")?;
|
let path = make_screenshot_path().context("error making screenshot path")?;
|
||||||
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);
|
|
||||||
|
|
||||||
debug!("saving screenshot to {path:?}");
|
debug!("saving screenshot to {path:?}");
|
||||||
|
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
use std::path::PathBuf;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use anyhow::{anyhow, Context};
|
use anyhow::{anyhow, Context};
|
||||||
|
use directories::UserDirs;
|
||||||
use smithay::backend::allocator::Fourcc;
|
use smithay::backend::allocator::Fourcc;
|
||||||
use smithay::backend::renderer::element::texture::TextureBuffer;
|
use smithay::backend::renderer::element::texture::TextureBuffer;
|
||||||
use smithay::backend::renderer::gles::{GlesRenderer, GlesTexture};
|
use smithay::backend::renderer::gles::{GlesRenderer, GlesTexture};
|
||||||
use smithay::reexports::nix::time::{clock_gettime, ClockId};
|
use smithay::reexports::nix::time::{clock_gettime, ClockId};
|
||||||
use smithay::utils::{Logical, Physical, Point, Rectangle, Transform};
|
use smithay::utils::{Logical, Physical, Point, Rectangle, Transform};
|
||||||
|
use time::OffsetDateTime;
|
||||||
use xcursor::parser::parse_xcursor;
|
use xcursor::parser::parse_xcursor;
|
||||||
use xcursor::CursorTheme;
|
use xcursor::CursorTheme;
|
||||||
|
|
||||||
@@ -80,3 +83,27 @@ pub fn load_default_cursor(
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
(texture, (frame.xhot as i32, frame.yhot as i32).into())
|
(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)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user