Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/wayshot.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Wayshot - Screenshot tool for compositors implementing zwlr_screencopy_v1 such a

*output*,
Location to send captured screenshot to, it can be of the following types:
1. A directory, image outputs will be saved in the default format "wayshot-yyyy-mm-dd-hh-mm-ss.png"
1. A directory, image outputs will be saved in the default format "wayshot-yyyy-mm-dd-hh-mm-ss.png" (Parent directories will be created if they do not exist)

2. A path (Encoding is automatically inferred from the extension).

Expand Down
2 changes: 1 addition & 1 deletion docs/wayshot.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ This section documents the *[file]* table of the configuration file

Refer to _[base]_ category's _file_ for examples

Default: _"None"_ (current working directory)
Default: _"None"_ ($HOME/Pictures/Screenshots, fallbacks to current working directory)

*name_format* = _"<string>"_ | _"None"_

Expand Down
10 changes: 9 additions & 1 deletion wayshot/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,21 @@ pub struct File {
impl Default for File {
fn default() -> Self {
File {
path: Some(env::current_dir().unwrap_or_default()),
path: Some(File::get_default_screenshot_dir()),
name_format: Some("wayshot-%Y_%m_%d-%H_%M_%S".to_string()),
encoding: Some(EncodingFormat::Png),
}
}
}

impl File {
pub fn get_default_screenshot_dir() -> PathBuf {
dirs::picture_dir()
.map(|path| path.join("Screenshots"))
.unwrap_or_else(|| env::current_dir().unwrap_or_default())
}
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Encoding {
pub jxl: Option<Jxl>,
Expand Down
7 changes: 5 additions & 2 deletions wayshot/src/wayshot.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use config::Config;
use std::{
env,
fs,
io::{self, BufWriter, Cursor, Write},
};

Expand Down Expand Up @@ -101,7 +101,7 @@ fn main() -> Result<()> {
if base.file.unwrap_or_default() {
let dir = file
.path
.unwrap_or_else(|| env::current_dir().unwrap_or_default());
.unwrap_or_else(config::File::get_default_screenshot_dir);
Some(utils::get_full_file_name(&dir, &file_name_format, encoding))
} else {
None
Expand Down Expand Up @@ -262,6 +262,9 @@ fn main() -> Result<()> {
let mut image_buf: Option<Cursor<Vec<u8>>> = None;

if let Some(f) = file {
if let Some(parent) = f.parent() {
fs::create_dir_all(parent)?;
}
if encoding == EncodingFormat::Jxl {
if let Err(e) = utils::encode_to_jxl(
&image_buffer,
Expand Down