From 6a2b6aa2c09844c17993f22f5ba6b85780c027d9 Mon Sep 17 00:00:00 2001 From: texjer Date: Tue, 27 Oct 2026 11:38:10 -0400 Subject: [PATCH 1/4] Camera Raw: coming back to PhotoCraft brings its window to the front MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ⌘Tab or the Dock could bring the main window over Camera Raw's, leaving only the dimmed main window, which takes no input. The main window gaining focus, or a click on it, now focuses Camera Raw's window. --- crates/ui-egui/src/dialogs/camera_raw_ui.rs | 2 + .../src/dialogs/camera_raw_ui/controls.rs | 40 +++++++++++++++++-- .../src/dialogs/camera_raw_ui/convert.rs | 1 + 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/dialogs/camera_raw_ui.rs b/crates/ui-egui/src/dialogs/camera_raw_ui.rs index 1b71ef33064..1d3ea1a835b 100644 --- a/crates/ui-egui/src/dialogs/camera_raw_ui.rs +++ b/crates/ui-egui/src/dialogs/camera_raw_ui.rs @@ -79,6 +79,8 @@ pub struct CameraRawDialog { pub(crate) detail: crate::camera_raw_detail_ui::DetailPreview, display: std::sync::Arc, pub(crate) viewport: Option, + /// Whether the main window had focus last frame (see [`show`]). + main_focused: bool, pub(crate) float: bool, tex: Option, before_tex: Option, diff --git a/crates/ui-egui/src/dialogs/camera_raw_ui/controls.rs b/crates/ui-egui/src/dialogs/camera_raw_ui/controls.rs index 426872e3472..c1a949a2423 100644 --- a/crates/ui-egui/src/dialogs/camera_raw_ui/controls.rs +++ b/crates/ui-egui/src/dialogs/camera_raw_ui/controls.rs @@ -205,14 +205,26 @@ pub fn show(app: &mut PhotocraftApp, ctx: &egui::Context) { // Camera Raw is modal, as in Photoshop: the main window is dimmed and takes no input while it // is open (in a separate window, or drawn over it where there are no extra windows). let main = ctx.content_rect(); - egui::Area::new(egui::Id::unique("camera-raw-modal")).order(egui::Order::Foreground).fixed_pos(main.min).show(ctx, |ui| { - let (r, _) = ui.allocate_exact_size(main.size(), Sense::click_and_drag()); + let scrim = egui::Area::new(egui::Id::unique("camera-raw-modal")).order(egui::Order::Foreground).fixed_pos(main.min).show(ctx, |ui| { + let (r, response) = ui.allocate_exact_size(main.size(), Sense::click_and_drag()); ui.painter().rect_filled(r, 0.0, Tokens::get(ui.ctx()).scrim); + response }); + let window = egui::ViewportId::from_hash_of("camera-raw-window"); + // Coming back to PhotoCraft (⌘Tab, the Dock) can bring the main window over Camera Raw, + // leaving only the dimmed window that takes no input: the main window gaining focus, or a + // click on it, brings Camera Raw back to the front. + let main_focused = ctx.input(|i| i.viewport().focused.unwrap_or(false)); + if let Some(d) = app.camera_raw.as_mut() { + if raise_camera_raw(d.main_focused, main_focused, scrim.inner.clicked() || scrim.inner.drag_started()) { + ctx.send_viewport_cmd_to(window, egui::ViewportCommand::Focus); + } + d.main_focused = main_focused; + } // A window of its own (title bar, moved and resized like any window), like Adobe Camera Raw. let builder = crate::os_window::builder().with_title(window_title).with_inner_size([1360.0, 900.0]).with_min_inner_size([900.0, 600.0]); let mut close = false; - ctx.show_viewport_immediate(egui::ViewportId::from_hash_of("camera-raw-window"), builder, |ui, class| { + ctx.show_viewport_immediate(window, builder, |ui, class| { if ui.ctx().input(|i| i.viewport().close_requested()) { close = true; } @@ -223,6 +235,12 @@ pub fn show(app: &mut PhotocraftApp, ctx: &egui::Context) { } } +/// Whether to bring Camera Raw's window to the front: when the main window has just gained focus +/// (it came forward over Camera Raw's) or is clicked. +fn raise_camera_raw(was_focused: bool, focused: bool, clicked: bool) -> bool { + (focused && !was_focused) || clicked +} + impl CameraRawDialog { /// "Camera Raw (name)" for the open-time dialog, "Camera Raw Filter (layer)" otherwise. fn window_title(&self) -> String { @@ -522,3 +540,19 @@ fn draw(app: &mut PhotocraftApp, ctx: &egui::Context, own_window: bool) { _ => {} } } + +#[cfg(test)] +mod tests { + use super::*; + + /// Coming back to PhotoCraft can put the main window over Camera Raw's: the main window + /// gaining focus brings Camera Raw's window to the front, once per activation, and so does a + /// click on the dimmed main window. + #[test] + fn the_main_window_gaining_focus_brings_camera_raw_back_to_the_front() { + assert!(raise_camera_raw(false, true, false), "the main window came forward"); + assert!(!raise_camera_raw(true, true, false), "only once, so Camera Raw's own focus isn't fought"); + assert!(!raise_camera_raw(true, false, false) && !raise_camera_raw(false, false, false)); + assert!(raise_camera_raw(true, true, true), "a click on the dimmed main window"); + } +} diff --git a/crates/ui-egui/src/dialogs/camera_raw_ui/convert.rs b/crates/ui-egui/src/dialogs/camera_raw_ui/convert.rs index 908f01e1f14..b10cdbdf396 100644 --- a/crates/ui-egui/src/dialogs/camera_raw_ui/convert.rs +++ b/crates/ui-egui/src/dialogs/camera_raw_ui/convert.rs @@ -185,6 +185,7 @@ pub(super) fn open_pixels( undo: Vec::new(), redo: Vec::new(), edit_origin: None, + main_focused: false, }; d.render(ctx); app.camera_raw = Some(d); From 5402a531e3ef34bc048582f3130c2039958ac664 Mon Sep 17 00:00:00 2001 From: texjer Date: Thu, 5 Nov 2026 14:52:48 -0500 Subject: [PATCH 2/4] Camera Raw: raising its window restores it first when it was minimized A minimized window ignores Focus, so clicking the dimmed main window left the app blocked until the user restored Camera Raw by hand. --- .../src/dialogs/camera_raw_ui/controls.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/dialogs/camera_raw_ui/controls.rs b/crates/ui-egui/src/dialogs/camera_raw_ui/controls.rs index c1a949a2423..1f72d3e26eb 100644 --- a/crates/ui-egui/src/dialogs/camera_raw_ui/controls.rs +++ b/crates/ui-egui/src/dialogs/camera_raw_ui/controls.rs @@ -217,7 +217,9 @@ pub fn show(app: &mut PhotocraftApp, ctx: &egui::Context) { let main_focused = ctx.input(|i| i.viewport().focused.unwrap_or(false)); if let Some(d) = app.camera_raw.as_mut() { if raise_camera_raw(d.main_focused, main_focused, scrim.inner.clicked() || scrim.inner.drag_started()) { - ctx.send_viewport_cmd_to(window, egui::ViewportCommand::Focus); + for command in raise_commands() { + ctx.send_viewport_cmd_to(window, command); + } } d.main_focused = main_focused; } @@ -241,6 +243,12 @@ fn raise_camera_raw(was_focused: bool, focused: bool, clicked: bool) -> bool { (focused && !was_focused) || clicked } +/// Brings Camera Raw's window to the front, restoring it first if it was minimized (a minimized +/// window ignores Focus). +fn raise_commands() -> [egui::ViewportCommand; 2] { + [egui::ViewportCommand::Minimized(false), egui::ViewportCommand::Focus] +} + impl CameraRawDialog { /// "Camera Raw (name)" for the open-time dialog, "Camera Raw Filter (layer)" otherwise. fn window_title(&self) -> String { @@ -555,4 +563,11 @@ mod tests { assert!(!raise_camera_raw(true, false, false) && !raise_camera_raw(false, false, false)); assert!(raise_camera_raw(true, true, true), "a click on the dimmed main window"); } + + /// Focus does nothing for a minimized window, which would leave only the dimmed main window + /// that takes no input: Camera Raw's is restored first. + #[test] + fn raising_camera_raw_restores_it_when_minimized() { + assert_eq!(raise_commands(), [egui::ViewportCommand::Minimized(false), egui::ViewportCommand::Focus]); + } } From aa9adfe83230ff0fc2a36b84468be1cb5169ef8b Mon Sep 17 00:00:00 2001 From: texjer Date: Sat, 7 Nov 2026 08:28:03 -0500 Subject: [PATCH 3/4] Camera Raw: a harness test that the main window gaining focus or a click restores and focuses Camera Raw's window --- .../src/dialogs/camera_raw_ui/tests.rs | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/crates/ui-egui/src/dialogs/camera_raw_ui/tests.rs b/crates/ui-egui/src/dialogs/camera_raw_ui/tests.rs index bcae932f5e3..433cd345e2c 100644 --- a/crates/ui-egui/src/dialogs/camera_raw_ui/tests.rs +++ b/crates/ui-egui/src/dialogs/camera_raw_ui/tests.rs @@ -86,6 +86,54 @@ fn closing_the_camera_raw_window_cancels() { assert_eq!(app.session.active().unwrap().history.past_len(), steps); } +/// Coming back to PhotoCraft (⌘Tab, the Dock) can put the main window over Camera Raw's, or +/// leave Camera Raw minimized: the main window gaining focus, or a click on its dimmed surface, +/// restores Camera Raw's window and focuses it, once per activation. +#[test] +fn the_main_window_gaining_focus_or_a_click_raises_the_camera_raw_window() { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default()); + let ctx = egui::Context::default(); + PhotocraftApp::setup_context(&ctx, crate::theme::ThemeKind::Pro); + ctx.set_embed_viewports(false); + // A multi-window backend for this thread: Camera Raw gets a window of its own, as on a desktop, + // and the commands its window receives are recorded. + let sent = std::sync::Arc::new(std::sync::Mutex::new(Vec::new())); + let record = sent.clone(); + egui::Context::set_immediate_viewport_renderer(move |ctx, immediate| { + let id = immediate.ids.this; + let mut callback = immediate.viewport_ui_cb; + let input = egui::RawInput { viewport_id: id, viewports: std::iter::once((id, egui::ViewportInfo::default())).collect(), ..Default::default() }; + let mut out = ctx.run_ui(input, |ui| callback(ui)); + out.textures_delta.clear(); + if let Some(v) = out.viewport_output.get(&id) { + record.lock().unwrap().extend(v.commands.iter().cloned()); + } + }); + app.run("file.new", json!({"width": 64, "height": 48})).unwrap(); + open(&mut app, &ctx).unwrap(); + let window = egui::ViewportId::from_hash_of("camera-raw-window"); + let raised = [egui::ViewportCommand::Minimized(false), egui::ViewportCommand::Focus]; + let frame = |app: &mut PhotocraftApp, focused: bool, events: Vec| { + let mut input = egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(800.0, 600.0))), events, ..Default::default() }; + input.viewports.entry(egui::ViewportId::ROOT).or_default().focused = Some(focused); + let mut out = ctx.run_ui(input, |ui| show(app, ui.ctx())); + out.textures_delta.clear(); + let mut commands: Vec<_> = std::mem::take(&mut *sent.lock().unwrap()); + commands.extend(out.viewport_output.get(&window).map(|v| v.commands.clone()).unwrap_or_default()); + // Only the raising commands: the window also gets its own setup (title, size) from egui. + commands.retain(|c| matches!(c, egui::ViewportCommand::Minimized(_) | egui::ViewportCommand::Focus)); + commands + }; + assert!(frame(&mut app, false, Vec::new()).is_empty(), "Camera Raw's window is in front"); + assert_eq!(frame(&mut app, true, Vec::new()), raised, "the main window came forward"); + assert!(frame(&mut app, true, Vec::new()).is_empty(), "once per activation, so Camera Raw's own focus isn't fought"); + let at = egui::pos2(400.0, 300.0); + let button = |pressed| egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE }; + frame(&mut app, true, vec![egui::Event::PointerMoved(at), button(true)]); + let after_click = frame(&mut app, true, vec![button(false)]); + assert_eq!(after_click, raised, "a click on the dimmed main window"); +} + /// A layer with tonal variation, a selection over part of it and the dialog open on it. fn worker_app() -> (PhotocraftApp, egui::Context) { let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default()); From 23356c2c95c1309fac074f436286ce2983428969 Mon Sep 17 00:00:00 2001 From: texjer Date: Sat, 7 Nov 2026 08:42:29 -0500 Subject: [PATCH 4/4] Camera Raw raise test: rustfmt; scorecard regenerated --- crates/ui-egui/src/dialogs/camera_raw_ui/tests.rs | 3 ++- docs/scorecard.md | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/dialogs/camera_raw_ui/tests.rs b/crates/ui-egui/src/dialogs/camera_raw_ui/tests.rs index 433cd345e2c..d067558b87f 100644 --- a/crates/ui-egui/src/dialogs/camera_raw_ui/tests.rs +++ b/crates/ui-egui/src/dialogs/camera_raw_ui/tests.rs @@ -114,7 +114,8 @@ fn the_main_window_gaining_focus_or_a_click_raises_the_camera_raw_window() { let window = egui::ViewportId::from_hash_of("camera-raw-window"); let raised = [egui::ViewportCommand::Minimized(false), egui::ViewportCommand::Focus]; let frame = |app: &mut PhotocraftApp, focused: bool, events: Vec| { - let mut input = egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(800.0, 600.0))), events, ..Default::default() }; + let mut input = + egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(800.0, 600.0))), events, ..Default::default() }; input.viewports.entry(egui::ViewportId::ROOT).or_default().focused = Some(focused); let mut out = ctx.run_ui(input, |ui| show(app, ui.ctx())); out.textures_delta.clear(); diff --git a/docs/scorecard.md b/docs/scorecard.md index f27b45b9fb9..7e92243bf85 100644 --- a/docs/scorecard.md +++ b/docs/scorecard.md @@ -9,7 +9,7 @@ Generated by `cargo xtask scorecard` from `perf/budgets.toml`, `perf/baseline.js | [Performance](#performance) | 3 | 22 | 51 | 85 scenarios: 3 within budget, 22 over budget or failing, 9 tracked only, 47 not run, 4 not measurable yet (baseline 2026-10-05) | | [File compatibility](#file-compatibility) | 11 | 14 | 2 | io corpus: oracle ≥ 148/170, round trip ≥ 169/170; psd-tools corpus: oracle ≥ 249/309, round trip ≥ 308/309; photoshop oracles: oracle ≥ 190/258, round trip ≥ 258/258 | | [Tools](#tools) | 36 | 9 | 0 | | -| [Workspace and UI](#workspace-and-ui) | 15 | 6 | 2 | settings that do nothing: 10 of 193 (target 0) | +| [Workspace and UI](#workspace-and-ui) | 15 | 6 | 2 | settings that do nothing: 10 of 194 (target 0) | | [Type](#type) | 5 | 5 | 0 | | | [Automation](#automation) | 5 | 3 | 3 | 661 of 661 menu items live (100.0%) | | [Reliability](#reliability) | 5 | 2 | 0 | never-crash lints on 30 of 30 crates; panic_hunt present | @@ -209,7 +209,7 @@ Corpus floors (`crates/io/tests/it/corpus.rs`): the enforced minimums; the corpu ## Workspace and UI -**Settings that do nothing: 10 of 193** (target 0, #204). Counted by the prefs audit (`xtask/src/scorecard.rs`): a `Preferences` field counts as read when code outside the prefs model (`prefs.rs` except its `impl Session` blocks; tests excluded; the schema-driven dialog never names a field) accesses `section.field`, or `.section` and `.field` in the same file, or calls a section method that reads `self.field`. It is a heuristic lower bound: a generic name can look read when it isn't. +**Settings that do nothing: 10 of 194** (target 0, #204). Counted by the prefs audit (`xtask/src/scorecard.rs`): a `Preferences` field counts as read when code outside the prefs model (`prefs.rs` except its `impl Session` blocks; tests excluded; the schema-driven dialog never names a field) accesses `section.field`, or `.section` and `.field` in the same file, or calls a section method that reads `self.field`. It is a heuristic lower bound: a generic name can look read when it isn't. Unread: `general.color_picker`, `workspace.auto_show_hidden_panels`, `workspace.enable_floating_document_window_docking`, `performance.legacy_compositing`, `units_and_rulers.column_width`, `units_and_rulers.gutter`, `plug_ins.show_extension_panels`, `plug_ins.allow_scripts_to_connect`, `type_.text_engine`, `enhanced_controls.scrubby_slider_acceleration`.