Compare commits

...
Author SHA1 Message Date
Martin Ball 5812949870 Merge remote-tracking branch 'origin/main' into HEAD 2026-11-21 15:25:30 +00:00
FredAppsandClaude Opus 5.5 f36118f0cd #7149 item 1: the root viewport and its frame come from a function the tests reach
SonarCloud's new-code coverage was 50%: the viewport and install-spec
frame wiring sat in main(), which no test runs. root_viewport builds the
window's viewport framed for the OS and returns the decision for the
install spec (its public frame field); the_root_window_is_framed_for_its_os
checks the macOS full-size content view and that Windows and Linux keep
the system bar.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 00:00:24 +01:00
Martin BallandClaude Sonnet 5.5 1f7abad395 #7149 item 1: macOS title bar: tell the shell the inset frame
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-20 15:52:10 +00:00
2 changed files with 98 additions and 14 deletions
+59 -14
View File
@@ -25,7 +25,7 @@ use std::sync::{Arc, Mutex, OnceLock};
use craft::automation::args::{ControlOptions, EnvNames, FlagNames, Source, control_port};
use craft::automation::control::ControlChannel;
use craft::dialogs::service::{FilePanels, FileService};
use craft::host::target::{Backend, ShellInfo};
use craft::host::target::{Backend, Os, Runtime, ShellInfo, WindowKind};
use craft::host::{Host, Wake};
use craft::platform::appearance::SystemReader;
use craft::platform::clipboard::{Clipboard, ClipboardImage, SystemClipboard};
@@ -37,6 +37,7 @@ use craft::settings::SharedSettings;
use craft::ui::InstallSpec;
use craft::ui::runtime::windows::{WindowAction, WindowHost};
use craft::ui::shell::embed;
use craft::window::policy::{Decision, Desktop, DesktopKind, TitleBarPref, apply, decide};
use craft::window::restore::{self, Store};
use craft::window::system::SystemWindows;
use wordcraft_engine::Session;
@@ -440,18 +441,8 @@ fn main() -> eframe::Result {
None => logger.stderr_only(),
}
}
let mut options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default()
.with_title("WordCraft")
.with_app_id("ai.storyteller.wordcraft")
.with_inner_size([1440.0, 920.0])
.with_min_inner_size(wordcraft_ui_egui::window_geometry::MIN_SIZE)
.with_drag_and_drop(true)
.with_fullsize_content_view(true)
.with_titlebar_shown(false)
.with_title_shown(false),
..Default::default()
};
let (viewport, frame) = root_viewport(Os::current());
let mut options = eframe::NativeOptions { viewport, ..Default::default() };
if let Some(icon) = app_icon() {
options.viewport = options.viewport.with_icon(icon);
}
@@ -527,11 +518,12 @@ fn main() -> eframe::Result {
.build(),
);
let shell = ShellInfo::current().backend(if x11 { Backend::X11 } else { Backend::from_env() });
let spec = InstallSpec::new(shell, Arc::new(SystemWindows))
let mut spec = InstallSpec::new(shell, Arc::new(SystemWindows))
.app_id("ai.storyteller.wordcraft")
.system(SystemReader::start(wake))
.clipboard(Clipboard::new(SystemClipboard::new().decoder(decode_png)))
.placement(placement);
spec.frame = frame;
// PLAN: assumed `wordcraft_ui_egui::ui_fonts` re-exports sh.A10's `app::fonts::ui_fonts` (`mod app` is private; app-hub/shell-w11).
embed::install(&ctx, spec, &wordcraft_ui_egui::ui_fonts(lang)).map_err(|e| format!("the runtime could not be installed: {e}"))?;
// The system region picks the new document's paper, the units and the decimal
@@ -608,6 +600,59 @@ fn main() -> eframe::Result {
result
}
/// The root window's viewport, framed for `os`, and the frame decision the install spec passes to the shell.
fn root_viewport(os: Os) -> (egui::ViewportBuilder, Option<Decision>) {
let viewport = egui::ViewportBuilder::default()
.with_title("WordCraft")
.with_app_id("ai.storyteller.wordcraft")
.with_inner_size([1440.0, 920.0])
.with_min_inner_size(wordcraft_ui_egui::window_geometry::MIN_SIZE)
.with_drag_and_drop(true);
let frame = frame_decision(os);
let viewport = match &frame {
Some(decision) => apply(viewport, &decision.frame),
None => viewport,
};
(viewport, frame)
}
/// The root window's frame, decided for the OS. macOS draws the app's own bar over a full-size content view; the shell
/// must be told (the install spec's frame), or it treats the window as OS-framed: the title bar has no move band to drag
/// the window by and no room for the traffic lights (#7149 item 1). Elsewhere the OS keeps its own frame.
fn frame_decision(os: Os) -> Option<Decision> {
// lean: no CRAFT_TITLEBAR override or "system title bar" setting on macOS yet; pass them to decide when asked.
let desktop = Desktop { kind: DesktopKind::Other, ssd: None, gtk_theme: None, icon_theme: None };
(os == Os::Mac).then(|| decide(os, Runtime::Native, Backend::from_env(), &desktop, WindowKind::Main, TitleBarPref::default(), None))
}
#[cfg(test)]
mod frame_tests {
use super::*;
use craft::window::policy::Frame;
#[test]
fn only_macos_gets_the_inset_frame() {
assert!(matches!(frame_decision(Os::Mac).map(|d| d.frame), Some(Frame::Inset(_))));
assert!(frame_decision(Os::Linux).is_none());
assert!(frame_decision(Os::Windows).is_none());
}
/// The macOS window draws the app's bar over a full-size content view with the system bar hidden, and tells the
/// shell so; Windows and Linux keep the OS frame. Every window takes dropped files.
#[test]
fn the_root_window_is_framed_for_its_os() {
let (mac, frame) = root_viewport(Os::Mac);
assert!(frame.is_some(), "the shell is told the macOS frame");
assert_eq!((mac.fullsize_content_view, mac.titlebar_shown, mac.title_shown), (Some(true), Some(false), Some(false)));
for os in [Os::Windows, Os::Linux] {
let (viewport, frame) = root_viewport(os);
assert!(frame.is_none(), "{os:?} keeps the OS frame");
assert_eq!((viewport.fullsize_content_view, viewport.titlebar_shown), (None, None), "{os:?} has the system bar");
}
assert_eq!(mac.drag_and_drop, Some(true));
}
}
// Not on macOS: APFS refuses file names that aren't valid UTF-8, so no such file can exist there.
#[cfg(all(test, unix, not(target_os = "macos")))]
mod tests {
+39
View File
@@ -436,3 +436,42 @@ fn status_bar_texts_stop_before_the_controls_in_a_narrow_window() {
let focus = wide.get_by_role_and_label(egui::accesskit::Role::Button, "Focus").rect();
assert!(painted_on_row_of(&wide, focus).iter().any(|(t, _)| t == "Track Changes: On"), "a wide window shows everything");
}
/// The macOS window as the desktop app runs it: Os::Mac with its caps; `inset` is whether the app told the shell its
/// frame is the inset one (`InstallSpec::frame`, see `frame_decision` in the app's `main.rs`). Without it the shell
/// treats the window as OS-framed.
fn mac_harness(a: WordApp, inset: bool) -> egui_kittest::Harness<'static, WordApp> {
use craft::host::target::{Caps, Os, ShellInfo};
use craft::ui::shell::Frame;
use craft::window::policy::{Decision, Desktop, DesktopKind, MacInset};
let spec = move || {
let shell = ShellInfo::default().os(Os::Mac).caps(Caps::native(Os::Mac));
let spec = craft::ui::InstallSpec::new(shell, std::sync::Arc::new(craft::ui::testing::windows::NoWindows));
let desktop = Desktop { kind: DesktopKind::Other, ssd: None, gtk_theme: None, icon_theme: None };
if inset { spec.frame(Decision { frame: Frame::Inset(MacInset::default()), overridden: None, desktop }) } else { spec }
};
let mut h = crate::test_harness::builder_with(spec).with_size(egui::vec2(1440.0, 900.0)).build_ui_state(app_frame, a);
crate::test_harness::frames(&mut h, 6);
h
}
/// #7149 item 1: on macOS the title bar moves the window by its free band, and AutoSave starts after the traffic
/// lights. Without the frame the shell had no band and no room for the lights.
#[test]
fn the_mac_title_bar_moves_the_window_and_clears_the_traffic_lights() {
use egui::accesskit::Role;
let lights = craft::window::policy::MacInset::default().leading;
let mut h = mac_harness(new_app(), true);
let title = title_rect(&h);
let at = egui::pos2(title.max.x + 8.0, title.center().y);
assert!(drag_moves_the_window(&mut h, at), "a drag of the free title bar at {at:?} moves the window");
let autosave = h.get_by_role_and_label(Role::Switch, "AutoSave").rect();
assert!(autosave.min.x >= lights, "AutoSave starts at {} under the traffic lights ({lights})", autosave.min.x);
// The app as it was: no decided frame, so no move band and AutoSave at the window's edge.
let mut h = mac_harness(new_app(), false);
let title = title_rect(&h);
let at = egui::pos2(title.max.x + 8.0, title.center().y);
assert!(!drag_moves_the_window(&mut h, at), "without the frame the title bar has no band (the bug this pins)");
assert!(h.get_by_role_and_label(Role::Switch, "AutoSave").rect().min.x < lights);
}