use super::*;
const RECENT_DIRS: usize = 3;
const HEIGHTS: [Option<u32>; 5] = [None, Some(2160), Some(1440), Some(1080), Some(720)];
impl App {
pub(crate) fn summary_chips(&mut self, ui: &mut egui::Ui) {
let ids: Vec<egui::Id> = ["output", "save", "size", "after"]
.iter()
.map(|salt| ui.scope_id().with(("settings strip", *salt)))
.collect();
let is_open = |i: usize| egui::Popup::is_id_open(ui.ctx(), ids[i]);
let save = self.settings.save_summary();
let save = save.strip_prefix("In ").unwrap_or(&save).to_owned();
let no_folder = self.settings.save_to_folder && self.settings.output_dir.is_none();
let size = size_value(self.max_height);
let mut items = vec![
theme::StripItem {
label: "Format",
value: self.settings.output_summary(),
accented: false,
open: is_open(0),
},
theme::StripItem {
label: "Save to",
value: save,
accented: no_folder,
open: is_open(1),
},
theme::StripItem {
label: "Size",
value: size,
accented: false,
open: is_open(2),
},
theme::StripItem {
label: "After",
value: self.settings.after_summary(),
accented: false,
open: is_open(3),
},
];
let tuned = !self.tuning.is_default();
if tuned {
items.push(theme::StripItem {
label: "Tuning",
value: "Custom".to_owned(),
accented: true,
open: false,
});
}
let hints = [
"What to create",
"Where to save",
"Largest output size",
"What happens after converting",
];
let responses = theme::strip(ui, &items);
for (i, response) in responses.iter().enumerate().take(4) {
let response = if items[i].open {
response.clone()
} else {
response.clone().on_hover_text(hints[i])
};
strip_menu(&response, ids[i], |ui| match i {
0 => settings_grid(ui, "output menu", |ui| self.output_rows(ui)),
1 => {
if self.save_menu(ui) {
ui.close();
}
}
2 => {
ui.set_max_width(260.0);
let labels: Vec<_> = HEIGHTS
.iter()
.map(|&h| (h, self.resolution_label(h)))
.collect();
for (h, label) in labels {
if ui
.selectable_value(&mut self.max_height, h, label)
.clicked()
{
ui.close();
}
}
ui.label(
RichText::new(
"Keeps the aspect ratio. Smaller images are never scaled up.",
)
.weak()
.size(12.0),
);
}
_ => settings_grid(ui, "after menu", |ui| self.after_rows(ui)),
});
}
if tuned
&& responses[4]
.clone()
.on_hover_text(
"Fine-tuning is changed for this session. Click to see it in Settings.",
)
.clicked()
{
self.settings_open = true;
}
}
pub(crate) fn settings_page(&mut self, ui: &mut egui::Ui) {
ui.horizontal(|ui| {
if theme::icon_button(ui, icons::back)
.on_hover_text("Back to the files (Esc)")
.clicked()
{
self.settings_open = false;
}
ui.add_space(2.0);
ui.label(RichText::new("Settings").font(theme::semibold(18.0)));
});
ui.add_space(4.0);
egui::ScrollArea::vertical()
.auto_shrink([false, false])
.show(ui, |ui| {
if self.running() {
ui.weak("Settings can be changed once the images are converted.");
}
theme::section(ui, "General");
theme::card(ui, |ui| {
settings_grid(ui, "general", |ui| self.general_rows(ui));
});
ui.add_enabled_ui(!self.running(), |ui| {
theme::section(ui, "Output");
theme::card(ui, |ui| {
settings_grid(ui, "output", |ui| {
self.output_rows(ui);
self.resolution_row(ui);
self.quality_rows(ui);
});
});
theme::section(ui, "Saving");
theme::card(ui, |ui| self.saving_ui(ui));
theme::section(ui, "After converting");
theme::card(ui, |ui| {
settings_grid(ui, "after", |ui| self.after_rows(ui))
});
if screenshot::SUPPORTED {
theme::section(ui, "Screenshots");
theme::card(ui, |ui| self.screenshot_ui(ui));
}
theme::section(ui, "Watch folder");
theme::card(ui, |ui| self.watch_ui(ui));
if tray::SUPPORTED {
theme::section(ui, "Background");
theme::card(ui, |ui| {
settings_grid(ui, "background", |ui| self.background_rows(ui))
});
}
theme::section(ui, "Fine-tuning");
theme::card(ui, |ui| self.tuning_ui(ui));
});
});
}
fn general_rows(&mut self, ui: &mut egui::Ui) {
theme::row_label(ui, "Theme");
if theme::segmented(
ui,
&mut self.settings.theme,
&[
(
ThemeChoice::System,
"System",
"Light or dark, as the system is set",
),
(ThemeChoice::Light, "Light", "Always light"),
(ThemeChoice::Dark, "Dark", "Always dark"),
],
) {
self.settings.theme.apply(ui.ctx());
}
ui.end_row();
theme::row_label(ui, "Updates");
ui.checkbox(
&mut self.settings.update_check,
"Check for updates once a week",
)
.on_hover_text(
"When hdrshot starts, ask GitHub for its latest release at most once \
a week. If there is a newer one, the link at the bottom of the window \
offers it; nothing is downloaded until you choose Update.",
);
ui.end_row();
if assoc::SUPPORTED {
theme::row_label(ui, "Files");
self.default_app_ui(ui);
ui.end_row();
}
theme::row_label(ui, "Feedback");
ui.horizontal(|ui| {
ui.hyperlink_to("Report a problem", report_url())
.on_hover_text("Opens a bug report on GitHub, with this version filled in");
ui.add_space(12.0);
ui.hyperlink_to("Ask a question", DISCUSSIONS_URL)
.on_hover_text("Opens hdrshot's Discussions on GitHub");
});
ui.end_row();
}
pub(crate) fn output_rows(&mut self, ui: &mut egui::Ui) {
theme::row_label(ui, "Create");
theme::segmented(
ui,
&mut self.settings.mode,
&[
(
Mode::Both,
"HDR + SDR",
"An HDR image and a tone-mapped SDR image for each image",
),
(
Mode::Hdr,
"HDR only",
"Only the HDR image, in the format chosen below",
),
(
Mode::Sdr,
"SDR only",
"Tone-mapped 8-bit image that looks right everywhere",
),
],
);
ui.end_row();
theme::row_label(ui, "HDR format");
ui.add_enabled_ui(self.settings.mode != Mode::Sdr, |ui| {
hdr_format_choice(ui, &mut self.settings.hdr_format);
});
ui.end_row();
ui.label("");
let png = self.settings.mode != Mode::Sdr && self.settings.hdr_format == Format::Png;
ui.horizontal(|ui| {
ui.add_enabled(
png,
egui::Checkbox::new(&mut self.settings.discord_png, "Discord-compatible PNG"),
);
theme::info_icon(
ui,
"Saves HDR PNGs without their cICP and mDCV chunks. Discord turns \
PNGs with cICP yellow; without it, Discord shows them in HDR with \
the right colors.\n\n\
Windows Photos and most other HDR viewers need cICP to show HDR, \
so they show these PNGs in SDR only. Leave this off unless you \
upload the saved files to Discord yourself: Copy for Discord \
already copies a Discord-compatible version.",
);
});
ui.end_row();
theme::row_label(ui, "SDR format");
ui.add_enabled_ui(self.settings.mode != Mode::Hdr, |ui| {
sdr_format_choice(ui, &mut self.settings.sdr_format);
});
ui.end_row();
}
fn quality_rows(&mut self, ui: &mut egui::Ui) {
let s = &mut self.settings;
let avif = s.mode != Mode::Sdr && s.hdr_format == Format::Avif
|| s.screenshot_mode.is_some_and(|m| m != Mode::Sdr)
&& s.screenshot_hdr_format == Format::Avif;
let jpeg = s.mode != Mode::Hdr && s.sdr_format == SdrKind::Jpeg
|| s.screenshot_mode.is_some_and(|m| m != Mode::Hdr)
&& s.screenshot_sdr_format == SdrKind::Jpeg;
let lossless = |f: Format| matches!(f, Format::Png | Format::Jxl);
let png = s.mode != Mode::Sdr && lossless(s.hdr_format)
|| s.screenshot_mode.is_some_and(|m| m != Mode::Sdr)
&& lossless(s.screenshot_hdr_format);
let defaults = AvifOptions::default();
ui.label("");
ui.add_enabled(
png,
egui::Checkbox::new(&mut s.hdr_png_16bit, "Full 16-bit HDR PNG and JPEG XL"),
)
.on_hover_text(
"Keep all 16 bits of brightness steps instead of 10, the precision HDR \
screens show. The files get about twice as large for a difference you \
won't see; for editing, the JPEG XR original keeps everything anyway.",
);
ui.end_row();
theme::row_label(ui, "AVIF quality");
ui.add_enabled_ui(avif, |ui| {
ui.horizontal(|ui| {
ui.add(egui::Slider::new(&mut s.avif_quality, 1..=100))
.on_hover_text("Higher is closer to the original and larger");
if s.avif_quality != defaults.quality && ui.small_button("Reset").clicked() {
s.avif_quality = defaults.quality;
}
});
});
ui.end_row();
theme::row_label(ui, "AVIF speed");
ui.add_enabled_ui(avif, |ui| {
ui.horizontal(|ui| {
ui.add(egui::Slider::new(&mut s.avif_speed, 0..=10))
.on_hover_text("0 is the slowest and gives the smallest file, 10 the fastest");
if s.avif_speed != defaults.speed && ui.small_button("Reset").clicked() {
s.avif_speed = defaults.speed;
}
});
});
ui.end_row();
ui.label("");
ui.add_enabled(
avif,
egui::Checkbox::new(&mut s.avif_420, "Smaller AVIF color (4:2:0)"),
)
.on_hover_text(
"Store color at half resolution: smaller files, but colored text and thin \
colored edges get softer",
);
ui.end_row();
theme::row_label(ui, "JPEG quality");
ui.add_enabled_ui(jpeg, |ui| {
ui.horizontal(|ui| {
ui.add(egui::Slider::new(&mut s.jpeg_quality, 1..=100))
.on_hover_text("Quality of SDR JPEGs; higher is sharper and larger");
let default = SdrFormat::DEFAULT_JPEG_QUALITY;
if s.jpeg_quality != default && ui.small_button("Reset").clicked() {
s.jpeg_quality = default;
}
});
});
ui.end_row();
}
pub(crate) fn resolution_row(&mut self, ui: &mut egui::Ui) {
theme::row_label(ui, "Resolution");
let selected = self.resolution_label(self.max_height);
let labels: Vec<_> = HEIGHTS
.iter()
.map(|&h| (h, self.resolution_label(h)))
.collect();
egui::ComboBox::from_id_salt("resolution")
.selected_text(selected)
.show_ui(ui, |ui| {
for (h, label) in labels {
ui.selectable_value(&mut self.max_height, h, label);
}
})
.response
.on_hover_text(RESOLUTION_HINT);
ui.end_row();
}
pub(crate) fn resolution_label(&self, max_height: Option<u32>) -> String {
let name = max_height.map_or_else(|| "Source".to_owned(), |h| format!("{h}p"));
match output_size(&self.files, max_height) {
OutputSize::Unknown => name,
OutputSize::Same(w, h) => format!("{name} ({w}×{h})"),
OutputSize::Varies => format!("{name} (sizes vary)"),
}
}
pub(crate) fn save_menu(&mut self, ui: &mut egui::Ui) -> bool {
let mut chosen = false;
let folders = self.settings.save_folders();
let s = &mut self.settings;
if ui
.selectable_label(!s.save_to_folder, "Next to each original")
.on_hover_text("Save the new files in the folder of the image they come from")
.clicked()
{
s.save_to_folder = false;
chosen = true;
}
for dir in folders {
let selected = s.save_to_folder && s.output_dir.as_ref() == Some(&dir);
if ui
.selectable_label(selected, folder_name(&dir))
.on_hover_text(dir.display().to_string())
.clicked()
{
s.use_output_dir(dir);
chosen = true;
}
}
ui.separator();
if ui.button("Choose a folder…").clicked() {
let mut dialog = rfd::FileDialog::new().set_title("Save images to");
if let Some(dir) = &s.output_dir {
dialog = dialog.set_directory(dir);
}
if let Some(dir) = dialog.pick_folder() {
s.use_output_dir(dir);
}
chosen = true;
}
chosen
}
pub(crate) fn saving_ui(&mut self, ui: &mut egui::Ui) {
settings_grid(ui, "saving", |ui| {
theme::row_label(ui, "Save to");
let selected = match (&self.settings.output_dir, self.settings.save_to_folder) {
(_, false) => "Next to each original".to_owned(),
(Some(dir), true) => dir.display().to_string(),
(None, true) => "Choose a folder…".to_owned(),
};
egui::ComboBox::from_id_salt("save to")
.selected_text(selected)
.width(ui.available_width().min(300.0))
.truncate()
.show_ui(ui, |ui| self.save_menu(ui));
ui.end_row();
});
ui.add_space(4.0);
ui.checkbox(&mut self.settings.keep_date, "Keep the capture date")
.on_hover_text(
"Give each PNG the date of its screenshot, so folders sorted \
by date stay in capture order",
);
let s = &mut self.settings;
ui.checkbox(&mut s.subfolders, "Save HDR and SDR images in subfolders")
.on_hover_text("Put them in folders named hdr and sdr");
let needed = s.suffix_needed();
let mut suffix = s.type_suffix || needed;
ui.add_enabled_ui(!needed && !s.custom_names, |ui| {
if ui
.checkbox(&mut suffix, "End file names in _hdr and _sdr")
.on_hover_text("Off: shot.jxr becomes shot.png")
.on_disabled_hover_text(
"Needed to tell the two PNGs apart when both are saved in the \
same folder",
)
.changed()
{
s.type_suffix = suffix;
}
});
ui.horizontal(|ui| {
ui.checkbox(&mut s.custom_names, "Custom file names")
.on_hover_text(
"Name files by a pattern: {name} is the original's name, {type} is \
hdr or sdr",
);
ui.add_enabled(
s.custom_names,
egui::TextEdit::singleline(&mut s.name_pattern)
.desired_width(180.0)
.hint_text(Naming::DEFAULT_PATTERN),
);
});
let problems: Vec<String> = [Some(s.mode), s.screenshot_mode]
.into_iter()
.flatten()
.filter_map(|mode| s.custom_naming(mode)?.err())
.collect();
if let Some(problem) = problems.first() {
let mut text = problem.clone();
if let Some(first) = text.get(..1) {
text = first.to_uppercase() + &text[1..];
}
ui.label(
RichText::new(format!("{text}. The usual names are used until then."))
.color(ui.visuals().error_fg_color),
);
}
self.name_preview_ui(ui);
}
fn name_preview_ui(&self, ui: &mut egui::Ui) {
let input = self
.files
.first()
.map_or_else(|| PathBuf::from(SAMPLE_INPUT), |entry| entry.path.clone());
let names = name_preview(&input, &self.convert_options(Existing::Skip));
ui.add_space(6.0);
egui::Frame::new()
.fill(ui.visuals().panel_fill)
.corner_radius(6.0)
.inner_margin(egui::Margin::symmetric(10, 8))
.show(ui, |ui| {
ui.set_width(ui.available_width());
ui.spacing_mut().item_spacing.y = 3.0;
let source = input.file_name().unwrap_or_default().to_string_lossy();
ui.label(RichText::new(format!("{source} becomes")).size(12.0).weak());
for name in names {
ui.add(egui::Label::new(RichText::new(name).size(13.0)).truncate());
}
});
}
pub(crate) fn after_rows(&mut self, ui: &mut egui::Ui) {
theme::row_label(ui, "Clipboard");
ui.checkbox(
&mut self.settings.copy_to_clipboard,
"Copy the last converted image",
)
.on_hover_text(if screenshot::SUPPORTED {
"After converting, copy the last image to the clipboard as a file \
(the HDR one if made), ready to paste into Discord, a browser or a \
folder. Screenshots follow Afterwards under Screenshots instead."
} else {
"After converting, copy the last image to the clipboard as a file \
(the HDR one if made), ready to paste into Discord, a browser or a folder"
});
ui.end_row();
theme::row_label(ui, "Originals");
ui.checkbox(
&mut self.settings.trash_originals,
format!("Replace the original (it goes to the {RECYCLE_BIN})"),
)
.on_hover_text(format!(
"Once all of an image's files are saved, move the original to the \
{RECYCLE_BIN}, so only the converted files are left. It can \
be restored from there. Images that fail, or whose files already \
existed, are kept, and so is everything when you stop the batch."
));
ui.end_row();
}
pub(crate) fn tuning_ui(&mut self, ui: &mut egui::Ui) {
ui.label(
RichText::new(
"Not needed normally: by default the results match the original \
image. Use these only to fine-tune the result. They reset when \
hdrshot closes.",
)
.weak(),
);
let t = &mut self.tuning;
let mode = self.settings.mode;
fn nits(value: &mut f32, min: f32) -> egui::DragValue<'_> {
egui::DragValue::new(value)
.range(min..=10_000.0)
.speed(5.0)
.suffix(" nits")
}
egui::Grid::new("tuning")
.num_columns(2)
.spacing([12.0, 8.0])
.show(ui, |ui| {
ui.add_enabled_ui(mode != Mode::Sdr, |ui| {
ui.checkbox(&mut t.limit_hdr_peak, "Limit HDR peak")
.on_hover_text(
"Roll off highlights brighter than this in the HDR image. \
Off keeps the original brightness.",
);
});
ui.add_enabled(
mode != Mode::Sdr && t.limit_hdr_peak,
nits(&mut t.hdr_peak, 100.0),
);
ui.end_row();
ui.label("SDR white").on_hover_text(
"HDR brightness that becomes white in the SDR image. \
Lower makes the SDR picture brighter. At the default, 80, \
phone photos keep their own SDR white.",
);
ui.horizontal(|ui| {
ui.add(nits(&mut t.sdr_white, 10.0));
let default = SdrOptions::default().white_nits;
if t.sdr_white != default && ui.small_button("Reset").clicked() {
t.sdr_white = default;
}
});
ui.end_row();
ui.checkbox(&mut t.fixed_sdr_peak, "Fixed SDR peak")
.on_hover_text(
"HDR brightness that maps to full SDR white. \
Off uses the brightest 0.1% of each image.",
);
ui.add_enabled(t.fixed_sdr_peak, nits(&mut t.sdr_peak, 10.0));
ui.end_row();
ui.checkbox(&mut t.fixed_input_white, "Render white")
.on_hover_text(
"For OpenEXR, Radiance and float JPEG XL files: the \
brightness of a value of 1.0. Off uses the file's own value, or 80 nits. \
For phone photos: the brightness of SDR white. Off uses 203 nits.",
);
ui.add_enabled(t.fixed_input_white, nits(&mut t.input_white, 1.0));
ui.end_row();
});
if !t.is_default() && ui.button("Back to automatic").clicked() {
*t = Tuning::default();
}
}
}
pub(crate) fn hdr_format_choice(ui: &mut egui::Ui, format: &mut Format) {
theme::segmented(
ui,
format,
&[
(
Format::Png,
"PNG",
"16-bit lossless PNG, shown in HDR by Windows Photos, Chrome \
and Edge. The largest files.",
),
(
Format::Avif,
"AVIF",
"10-bit AVIF, about a twentieth of the PNG's size, shown in HDR \
by Chrome, Edge and Firefox. Takes a few seconds per image.",
),
(
Format::UltraHdr,
"Ultra HDR JPEG",
"A JPEG that every app shows in SDR and that Chrome, Edge \
and Android show in HDR.",
),
(
Format::Jxl,
"JPEG XL",
"Lossless JPEG XL, shown in HDR by Chrome and by viewers with \
JPEG XL support. Smaller than the PNG for games and photos; \
desktop screenshots can come out larger.",
),
],
);
}
pub(crate) fn sdr_format_choice(ui: &mut egui::Ui, kind: &mut SdrKind) {
theme::segmented(
ui,
kind,
&[
(
SdrKind::Png,
"PNG",
"8-bit lossless PNG, the exact tone-mapped picture",
),
(
SdrKind::Jpeg,
"JPEG",
"JPEG, a fraction of the PNG's size, for chats and forums \
that don't show HDR. Transparency is lost. The quality is \
under Output in Settings.",
),
],
);
}
const RESOLUTION_HINT: &str = "Scale images taller than this down to this height, keeping the \
aspect ratio, so ultrawide images stay ultrawide. Smaller images are never scaled up. \
The size in brackets is what the listed files come out at.";
const SAMPLE_INPUT: &str = "Screenshot 2026-10-14 212314.jxr";
pub(crate) fn name_preview(input: &Path, options: &ConvertOptions) -> Vec<String> {
let outputs = hdrshot_core::output_paths(input, options);
let dir = options
.output_dir
.clone()
.or_else(|| input.parent().map(Path::to_path_buf))
.unwrap_or_default();
[outputs.hdr, outputs.sdr]
.into_iter()
.flatten()
.map(|path| {
let path = path.strip_prefix(&dir).unwrap_or(&path);
path.components()
.map(|c| c.as_os_str().to_string_lossy())
.collect::<Vec<_>>()
.join("/")
})
.collect()
}
const DISCUSSIONS_URL: &str = "https://github.com/snaketech-tu/hdrshot/discussions";
pub(crate) fn report_url() -> String {
let os = match std::env::consts::OS {
"macos" => "&os=macOS",
"linux" => "&os=Linux",
_ => "",
};
format!(
"https://github.com/snaketech-tu/hdrshot/issues/new?template=bug.yml&version={}&surface=Desktop%20app{os}",
env!("CARGO_PKG_VERSION")
)
}
pub(crate) fn settings_grid(ui: &mut egui::Ui, id: &str, add_rows: impl FnOnce(&mut egui::Ui)) {
egui::Grid::new(id)
.num_columns(2)
.spacing([16.0, 10.0])
.show(ui, add_rows);
}
fn strip_menu(response: &egui::Response, id: egui::Id, menu: impl FnOnce(&mut egui::Ui)) {
egui::Popup::from_toggle_button_response(response)
.id(id)
.align(egui::RectAlign::TOP_START)
.gap(6.0)
.close_behavior(egui::PopupCloseBehavior::CloseOnClickOutside)
.show(|ui| {
ui.set_min_width(220.0);
menu(ui);
});
}
pub(crate) fn size_value(max_height: Option<u32>) -> String {
max_height.map_or_else(|| "Source".to_owned(), |h| format!("Up to {h}p"))
}
fn some_shortcut<'de, D: serde::Deserializer<'de>>(
deserializer: D,
) -> Result<Option<screenshot::Shortcut>, D::Error> {
screenshot::Shortcut::deserialize(deserializer).map(Some)
}
fn plain_shortcut<S: serde::Serializer>(
shortcut: &Option<screenshot::Shortcut>,
serializer: S,
) -> Result<S::Ok, S::Error> {
shortcut
.unwrap_or(screenshot::Shortcut::CtrlAltPrintScreen)
.serialize(serializer)
}
#[derive(Serialize, Deserialize)]
#[serde(default)]
pub(crate) struct Settings {
pub(crate) mode: Mode,
pub(crate) hdr_format: Format,
pub(crate) sdr_format: SdrKind,
pub(crate) save_to_folder: bool,
pub(crate) output_dir: Option<PathBuf>,
pub(crate) copy_to_clipboard: bool,
pub(crate) keep_date: bool,
pub(crate) subfolders: bool,
pub(crate) type_suffix: bool,
pub(crate) discord_png: bool,
pub(crate) trash_originals: bool,
pub(crate) watch: bool,
pub(crate) watch_dir: Option<PathBuf>,
pub(crate) recent_dirs: Vec<PathBuf>,
pub(crate) hidden_tips: Vec<String>,
pub(crate) theme: ThemeChoice,
pub(crate) update_check: bool,
pub(crate) last_update_check: u64,
pub(crate) window: Option<window::Place>,
pub(crate) tray: bool,
pub(crate) start_with_windows: bool,
pub(crate) notify: bool,
pub(crate) tray_note_shown: bool,
pub(crate) screenshot_shortcut: screenshot::Shortcut,
#[serde(
deserialize_with = "some_shortcut",
serialize_with = "plain_shortcut",
skip_serializing_if = "Option::is_none"
)]
pub(crate) region_shortcut: Option<screenshot::Shortcut>,
pub(crate) screenshot_dir: Option<PathBuf>,
pub(crate) screenshot_area: screenshot::Area,
pub(crate) screenshot_game_folders: bool,
pub(crate) screenshot_month_folders: bool,
pub(crate) screenshot_delay: u8,
pub(crate) controller_shortcut: screenshot::Buttons,
pub(crate) hdr_png_16bit: bool,
pub(crate) view: View,
pub(crate) screenshot_mode: Option<Mode>,
pub(crate) screenshot_hdr_format: Format,
pub(crate) screenshot_sdr_format: SdrKind,
pub(crate) after_screenshot: Option<AfterShot>,
pub(crate) shutter_sound: bool,
pub(crate) avif_quality: u8,
pub(crate) avif_speed: u8,
pub(crate) avif_420: bool,
pub(crate) jpeg_quality: u8,
pub(crate) custom_names: bool,
pub(crate) name_pattern: String,
}
impl Settings {
pub(crate) fn suffix_needed(&self) -> bool {
self.suffix_needed_for(self.mode)
}
fn suffix_needed_for(&self, mode: Mode) -> bool {
mode == Mode::Both && !self.subfolders
}
pub(crate) fn naming(&self) -> Naming {
self.naming_for(self.mode)
}
fn naming_for(&self, mode: Mode) -> Naming {
if let Some(naming) = self.custom_naming(mode).and_then(Result::ok) {
return naming;
}
Naming {
pattern: if self.type_suffix || self.suffix_needed_for(mode) {
Naming::DEFAULT_PATTERN.into()
} else {
"{name}".into()
},
subfolders: self.subfolders,
}
}
pub(crate) fn custom_naming(&self, mode: Mode) -> Option<Result<Naming, String>> {
if !self.custom_names {
return None;
}
let naming = Naming {
pattern: self.name_pattern.trim().to_owned(),
subfolders: self.subfolders,
};
Some(naming.check(mode.into()).map(|()| naming))
}
pub(crate) fn avif(&self) -> AvifOptions {
AvifOptions {
quality: self.avif_quality.clamp(1, 100),
speed: self.avif_speed.min(10),
full_color: !self.avif_420,
}
}
pub(crate) fn sdr_file_format(&self, kind: SdrKind) -> SdrFormat {
match kind {
SdrKind::Png => SdrFormat::Png,
SdrKind::Jpeg => SdrFormat::Jpeg {
quality: self.jpeg_quality.clamp(1, 100),
},
}
}
pub(crate) fn screenshot_options(&self, mut options: ConvertOptions) -> ConvertOptions {
let Some(mode) = self.screenshot_mode else {
return options;
};
options.mode = mode.into();
options.hdr.format = self.screenshot_hdr_format.into();
options.sdr_format = self.sdr_file_format(self.screenshot_sdr_format);
options.naming = self.naming_for(mode);
options
}
pub(crate) fn save_folder_missing(&self) -> bool {
self.save_to_folder && self.output_dir.is_none()
}
pub(crate) fn after_screenshot(&self) -> AfterShot {
self.after_screenshot.unwrap_or(if self.copy_to_clipboard {
AfterShot::Copy
} else {
AfterShot::Nothing
})
}
pub(crate) fn region_shortcut(&self) -> screenshot::Shortcut {
use screenshot::Shortcut;
self.region_shortcut.unwrap_or_else(|| {
let main = self.screenshot_shortcut;
if main != Shortcut::CtrlAltPrintScreen {
return Shortcut::CtrlAltPrintScreen;
}
Shortcut::ALL
.into_iter()
.find(|&s| s != main && s != Shortcut::Off)
.unwrap_or(Shortcut::Off)
})
}
pub(crate) fn settle(&mut self) {
self.after_screenshot = Some(self.after_screenshot());
self.region_shortcut = Some(self.region_shortcut());
}
pub(crate) fn output_summary(&self) -> String {
let hdr = match self.hdr_format {
Format::Png if self.discord_png => "HDR PNG for Discord",
Format::Png => "HDR PNG",
Format::Avif => "HDR AVIF",
Format::UltraHdr => "Ultra HDR JPEG",
Format::Jxl => "HDR JPEG XL",
};
let sdr = match self.sdr_format {
SdrKind::Png => "SDR PNG",
SdrKind::Jpeg => "SDR JPEG",
};
match self.mode {
Mode::Both => format!("{hdr} + {sdr}"),
Mode::Hdr => hdr.to_owned(),
Mode::Sdr => sdr.to_owned(),
}
}
pub(crate) fn save_summary(&self) -> String {
if !self.save_to_folder {
return "Next to originals".to_owned();
}
match &self.output_dir {
Some(dir) => format!("In {}", folder_name(dir)),
None => "Choose a folder".to_owned(),
}
}
pub(crate) fn use_output_dir(&mut self, dir: PathBuf) {
self.recent_dirs.retain(|d| d != &dir);
self.recent_dirs.insert(0, dir.clone());
self.recent_dirs.truncate(RECENT_DIRS);
self.output_dir = Some(dir);
self.save_to_folder = true;
}
pub(crate) fn save_folders(&self) -> Vec<PathBuf> {
let mut folders: Vec<PathBuf> = Vec::new();
for dir in self.output_dir.iter().chain(&self.recent_dirs) {
if !folders.contains(dir) && dir.is_dir() {
folders.push(dir.clone());
}
}
folders.truncate(RECENT_DIRS);
folders
}
pub(crate) fn after_summary(&self) -> String {
match (self.trash_originals, self.copy_to_clipboard) {
(false, true) => "Keep originals",
(true, true) => "Replace originals",
(false, false) => "Keep originals, no clipboard",
(true, false) => "Replace originals, no clipboard",
}
.to_owned()
}
}
impl Default for Settings {
fn default() -> Self {
Self {
mode: Mode::Both,
hdr_format: Format::Png,
sdr_format: SdrKind::Png,
save_to_folder: false,
output_dir: None,
copy_to_clipboard: true,
keep_date: true,
subfolders: false,
type_suffix: true,
discord_png: false,
trash_originals: false,
watch: false,
watch_dir: watching::default_watch_dir(),
recent_dirs: Vec::new(),
hidden_tips: Vec::new(),
theme: ThemeChoice::System,
update_check: true,
last_update_check: 0,
window: None,
tray: false,
start_with_windows: false,
notify: true,
tray_note_shown: false,
screenshot_shortcut: screenshot::Shortcut::CtrlShiftPrintScreen,
region_shortcut: None,
screenshot_dir: None,
screenshot_area: screenshot::Area::Window,
screenshot_game_folders: true,
screenshot_month_folders: false,
screenshot_delay: 0,
controller_shortcut: screenshot::Buttons::DEFAULT,
hdr_png_16bit: false,
view: View::Files,
screenshot_mode: None,
screenshot_hdr_format: Format::Png,
screenshot_sdr_format: SdrKind::Png,
after_screenshot: None,
shutter_sound: false,
avif_quality: AvifOptions::default().quality,
avif_speed: AvifOptions::default().speed,
avif_420: false,
jpeg_quality: SdrFormat::DEFAULT_JPEG_QUALITY,
custom_names: false,
name_pattern: Naming::DEFAULT_PATTERN.to_owned(),
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub(crate) enum AfterShot {
Copy,
Reveal,
Nothing,
}
impl AfterShot {
pub(crate) const ALL: [Self; 3] = [Self::Copy, Self::Reveal, Self::Nothing];
pub(crate) fn label(self) -> &'static str {
match self {
Self::Copy => "Copy for Discord",
Self::Reveal => "Open the folder",
Self::Nothing => "Nothing",
}
}
}
#[derive(Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub(crate) enum ThemeChoice {
System,
Light,
Dark,
}
impl ThemeChoice {
pub(crate) fn apply(self, ctx: &egui::Context) {
let (preference, title_bar) = match self {
Self::System => (
egui::ThemePreference::System,
egui::SystemTheme::SystemDefault,
),
Self::Light => (egui::ThemePreference::Light, egui::SystemTheme::Light),
Self::Dark => (egui::ThemePreference::Dark, egui::SystemTheme::Dark),
};
ctx.set_theme(preference);
ctx.send_viewport_cmd(egui::ViewportCommand::SetTheme(title_bar));
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub(crate) enum Mode {
Hdr,
Sdr,
Both,
}
impl From<Mode> for OutputMode {
fn from(mode: Mode) -> Self {
match mode {
Mode::Hdr => Self::Hdr,
Mode::Sdr => Self::Sdr,
Mode::Both => Self::Both,
}
}
}
#[derive(Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub(crate) enum Format {
Png,
Avif,
UltraHdr,
Jxl,
}
impl From<Format> for HdrFormat {
fn from(format: Format) -> Self {
match format {
Format::Png => Self::Png,
Format::Avif => Self::Avif,
Format::UltraHdr => Self::UltraHdr,
Format::Jxl => Self::Jxl,
}
}
}
#[derive(Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub(crate) enum SdrKind {
Png,
Jpeg,
}
impl From<SdrKind> for SdrFormat {
fn from(kind: SdrKind) -> Self {
match kind {
SdrKind::Png => Self::Png,
SdrKind::Jpeg => Self::Jpeg {
quality: Self::DEFAULT_JPEG_QUALITY,
},
}
}
}
pub(crate) struct Tuning {
pub(crate) limit_hdr_peak: bool,
pub(crate) hdr_peak: f32,
pub(crate) sdr_white: f32,
pub(crate) fixed_sdr_peak: bool,
pub(crate) sdr_peak: f32,
pub(crate) fixed_input_white: bool,
pub(crate) input_white: f32,
}
impl Default for Tuning {
fn default() -> Self {
Self {
limit_hdr_peak: false,
hdr_peak: 1000.0,
sdr_white: SdrOptions::default().white_nits,
fixed_sdr_peak: false,
sdr_peak: 1000.0,
fixed_input_white: false,
input_white: 80.0,
}
}
}
impl Tuning {
pub(crate) fn is_default(&self) -> bool {
!self.limit_hdr_peak
&& !self.fixed_sdr_peak
&& !self.fixed_input_white
&& self.sdr_white == SdrOptions::default().white_nits
}
}
#[derive(Debug, PartialEq)]
pub(crate) enum OutputSize {
Unknown,
Same(u32, u32),
Varies,
}
pub(crate) fn output_size(files: &[Entry], max_height: Option<u32>) -> OutputSize {
let mut sizes = files
.iter()
.filter_map(|e| e.size)
.map(|(w, h)| max_height.map_or((w, h), |max| hdrshot_core::resize::fit_height(w, h, max)));
let Some(first) = sizes.next() else {
return OutputSize::Unknown;
};
if sizes.all(|s| s == first) {
OutputSize::Same(first.0, first.1)
} else {
OutputSize::Varies
}
}
#[cfg(test)]
mod tests {
use super::*;
fn entry(size: Option<(u32, u32)>) -> Entry {
Entry {
path: PathBuf::new(),
status: Status::Waiting,
size,
info: String::new(),
saved: String::new(),
thumb: Thumb::Failed,
}
}
#[test]
fn output_size_keeps_ultrawide_aspect() {
let files = [entry(Some((3440, 1440))), entry(Some((3440, 1440)))];
assert_eq!(output_size(&files, None), OutputSize::Same(3440, 1440));
assert_eq!(
output_size(&files, Some(1080)),
OutputSize::Same(2580, 1080)
);
assert_eq!(
output_size(&files, Some(2160)),
OutputSize::Same(3440, 1440)
);
}
#[test]
fn output_size_varies_or_unknown() {
let mixed = [entry(Some((3440, 1440))), entry(Some((3840, 2160)))];
assert_eq!(output_size(&mixed, Some(1080)), OutputSize::Varies);
assert_eq!(output_size(&mixed, Some(1440)), OutputSize::Varies);
assert_eq!(output_size(&[], Some(1080)), OutputSize::Unknown);
assert_eq!(output_size(&[entry(None)], None), OutputSize::Unknown);
}
#[test]
fn recent_folders_come_newest_first() {
let mut s = Settings::default();
let base = std::env::temp_dir();
for name in ["a", "b", "c", "d", "b"] {
s.use_output_dir(base.join(name));
}
assert_eq!(
s.recent_dirs,
[base.join("b"), base.join("d"), base.join("c")]
);
assert_eq!(s.output_dir, Some(base.join("b")));
s.recent_dirs.push(base.clone());
s.output_dir = Some(base.clone());
assert_eq!(s.save_folders(), [base]);
}
#[test]
fn every_setting_is_in_the_parity_table() {
let table = include_str!("../../../docs/feature-parity.md");
let mut settings = Settings::default();
settings.settle();
let saved = serde_json::to_value(&settings).unwrap();
let missing: Vec<&String> = saved
.as_object()
.unwrap()
.keys()
.filter(|field| !table.contains(&format!("`{field}`")))
.collect();
assert!(
missing.is_empty(),
"add {missing:?} to docs/feature-parity.md, with the command line's \
counterpart (the rule is in CONTRIBUTING.md)"
);
}
#[test]
fn custom_names_and_quality() {
let mut s = Settings {
custom_names: true,
name_pattern: "{name}-{type}".into(),
..Settings::default()
};
assert_eq!(s.naming().pattern, "{name}-{type}");
s.name_pattern = "{name}".into();
assert!(matches!(s.custom_naming(Mode::Both), Some(Err(_))));
assert_eq!(s.naming().pattern, Naming::DEFAULT_PATTERN);
s.mode = Mode::Hdr;
assert_eq!(s.naming().pattern, "{name}");
s.jpeg_quality = 70;
assert_eq!(
s.sdr_file_format(SdrKind::Jpeg),
SdrFormat::Jpeg { quality: 70 }
);
s.avif_quality = 60;
s.avif_420 = true;
assert_eq!(s.avif().quality, 60);
assert!(!s.avif().full_color);
}
#[test]
fn name_preview_lists_the_files() {
let input = Path::new("shots").join("Screenshot 1.jxr");
let mut s = Settings::default();
let names = |s: &Settings| {
let options = ConvertOptions {
mode: s.mode.into(),
output_dir: s.save_to_folder.then(|| s.output_dir.clone()).flatten(),
naming: s.naming(),
hdr: HdrOptions {
format: s.hdr_format.into(),
..Default::default()
},
sdr_format: s.sdr_format.into(),
..Default::default()
};
name_preview(&input, &options)
};
assert_eq!(names(&s), ["Screenshot 1_hdr.png", "Screenshot 1_sdr.png"]);
s.subfolders = true;
s.type_suffix = false;
s.hdr_format = Format::Avif;
s.sdr_format = SdrKind::Jpeg;
assert_eq!(names(&s), ["hdr/Screenshot 1.avif", "sdr/Screenshot 1.jpg"]);
s.mode = Mode::Hdr;
s.save_to_folder = true;
s.output_dir = Some(std::env::temp_dir().join("out"));
assert_eq!(names(&s), ["hdr/Screenshot 1.avif"]);
}
#[test]
fn screenshots_get_their_own_output() {
let mut s = Settings {
mode: Mode::Hdr,
hdr_format: Format::Png,
type_suffix: false,
keep_date: false,
save_to_folder: true,
output_dir: Some(PathBuf::from("out")),
..Default::default()
};
let batch = ConvertOptions {
mode: s.mode.into(),
output_dir: s.output_dir.clone(),
naming: s.naming(),
keep_date: s.keep_date,
max_height: Some(1440),
..Default::default()
};
let same = s.screenshot_options(batch.clone());
assert_eq!(same.mode, OutputMode::Hdr);
assert_eq!(same.naming, batch.naming);
assert_eq!(same.hdr.format, HdrFormat::Png);
s.screenshot_mode = Some(Mode::Both);
s.screenshot_hdr_format = Format::Avif;
s.screenshot_sdr_format = SdrKind::Jpeg;
let own = s.screenshot_options(batch.clone());
assert_eq!(own.mode, OutputMode::Both);
assert_eq!(own.hdr.format, HdrFormat::Avif);
assert!(matches!(own.sdr_format, SdrFormat::Jpeg { .. }));
assert_eq!(own.naming.pattern, Naming::DEFAULT_PATTERN);
assert_eq!(own.output_dir, batch.output_dir);
assert_eq!(own.max_height, Some(1440));
assert!(!own.keep_date);
let input = Path::new("shots").join("Game 2026-11-28 20-15-00.jxr");
assert_eq!(
name_preview(&input, &own),
[
"Game 2026-11-28 20-15-00_hdr.avif",
"Game 2026-11-28 20-15-00_sdr.jpg"
]
);
s.screenshot_mode = Some(Mode::Sdr);
let sdr = s.screenshot_options(batch);
assert_eq!(sdr.mode, OutputMode::Sdr);
assert_eq!(name_preview(&input, &sdr), ["Game 2026-11-28 20-15-00.jpg"]);
}
#[test]
fn after_screenshot_follows_the_clipboard_setting_from_2_4_0() {
let copying: Settings = serde_json::from_str(r#"{"copy_to_clipboard": true}"#).unwrap();
assert_eq!(copying.after_screenshot(), AfterShot::Copy);
let mut off: Settings = serde_json::from_str(r#"{"copy_to_clipboard": false}"#).unwrap();
assert_eq!(off.after_screenshot(), AfterShot::Nothing);
off.settle();
off.copy_to_clipboard = true;
assert_eq!(off.after_screenshot(), AfterShot::Nothing);
let chosen: Settings =
serde_json::from_str(r#"{"copy_to_clipboard": false, "after_screenshot": "Reveal"}"#)
.unwrap();
assert_eq!(chosen.after_screenshot(), AfterShot::Reveal);
assert_eq!(Settings::default().after_screenshot(), AfterShot::Copy);
}
#[test]
fn region_shortcut_moves_off_the_screenshot_shortcut_from_2_4_0() {
use screenshot::Shortcut;
let mut s: Settings =
serde_json::from_str(r#"{"screenshot_shortcut": "CtrlAltPrintScreen"}"#).unwrap();
assert_eq!(s.region_shortcut(), Shortcut::CtrlShiftPrintScreen);
s.settle();
assert_eq!(s.region_shortcut, Some(Shortcut::CtrlShiftPrintScreen));
let mut s: Settings =
serde_json::from_str(r#"{"screenshot_shortcut": "ShiftPrintScreen"}"#).unwrap();
s.settle();
assert_eq!(s.region_shortcut(), Shortcut::CtrlAltPrintScreen);
assert_eq!(
Settings::default().region_shortcut(),
Shortcut::CtrlAltPrintScreen
);
let mut s: Settings = serde_json::from_str(
r#"{"screenshot_shortcut": "CtrlAltPrintScreen", "region_shortcut": "CtrlAltPrintScreen"}"#,
)
.unwrap();
s.settle();
assert_eq!(s.region_shortcut(), Shortcut::CtrlAltPrintScreen);
s.region_shortcut = Some(Shortcut::ShiftPrintScreen);
let saved = ron::to_string(&s).unwrap();
assert!(
saved.contains("region_shortcut:ShiftPrintScreen"),
"{saved}"
);
let back: Settings = ron::from_str(&saved).unwrap();
assert_eq!(back.region_shortcut, Some(Shortcut::ShiftPrintScreen));
}
#[test]
fn controller_shortcut_is_saved_and_never_breaks_loading() {
use crate::screenshot::Buttons;
let mut s = Settings::default();
assert_eq!(s.controller_shortcut, Buttons::DEFAULT);
s.controller_shortcut = "LT+RT+Y".parse().unwrap();
s.screenshot_month_folders = true;
let saved = ron::to_string(&s).unwrap();
assert!(saved.contains("controller_shortcut:\"LT+RT+Y\""), "{saved}");
let back: Settings = ron::from_str(&saved).unwrap();
assert_eq!(back.controller_shortcut, s.controller_shortcut);
assert!(back.screenshot_month_folders);
let odd = saved.replace("\"LT+RT+Y\"", "\"Guide+Share\"");
let back: Settings = ron::from_str(&odd).unwrap();
assert_eq!(back.controller_shortcut, Buttons::DEFAULT);
assert!(back.screenshot_month_folders);
let off: Settings = serde_json::from_str(r#"{"controller_shortcut": "Off"}"#).unwrap();
assert!(off.controller_shortcut.is_off());
}
#[test]
fn report_url_fills_in_the_version() {
let url = report_url();
assert!(
url.starts_with("https://github.com/snaketech-tu/hdrshot/issues/new?template=bug.yml&")
);
assert!(url.contains(&format!("version={}", env!("CARGO_PKG_VERSION"))));
assert!(!url.contains(' '));
}
#[test]
fn chips_sum_up_the_settings() {
let mut s = Settings::default();
assert_eq!(s.output_summary(), "HDR PNG + SDR PNG");
assert_eq!(s.save_summary(), "Next to originals");
assert_eq!(s.after_summary(), "Keep originals");
assert_eq!(size_value(None), "Source");
assert_eq!(size_value(Some(1440)), "Up to 1440p");
s.mode = Mode::Hdr;
s.hdr_format = Format::Avif;
assert_eq!(s.output_summary(), "HDR AVIF");
s.mode = Mode::Sdr;
s.sdr_format = SdrKind::Jpeg;
assert_eq!(s.output_summary(), "SDR JPEG");
s.save_to_folder = true;
s.output_dir = None;
assert_eq!(s.save_summary(), "Choose a folder");
s.output_dir = Some(PathBuf::from("shots").join("HDR"));
assert_eq!(s.save_summary(), "In HDR");
s.trash_originals = true;
assert_eq!(s.after_summary(), "Replace originals");
s.copy_to_clipboard = false;
assert_eq!(s.after_summary(), "Replace originals, no clipboard");
s.trash_originals = false;
assert_eq!(s.after_summary(), "Keep originals, no clipboard");
}
}