Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

Application bar: use craft-window's shared title bar (#1811)

aionggfec0897a5d42
diff --git a/Cargo.lock b/Cargo.lock
index 2cecf98e1..1b8a1240a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -868,6 +868,17 @@ dependencies = [
"serde",
]
+[[package]]
+name = "craft-window"
+version = "0.1.0"
+source = "git+https://github.com/storytold/craft-libs?rev=ea4c823abb46fa9d21361604ed1c6d21c54e9ca8#ea4c823abb46fa9d21361604ed1c6d21c54e9ca8"
+dependencies = [
+ "egui",
+ "objc2 0.6.4",
+ "objc2-app-kit 0.3.2",
+ "wayland-client",
+]
+
[[package]]
name = "crc32fast"
version = "1.5.2"
@@ -945,6 +956,7 @@ name = "designcraft"
version = "0.13.0"
dependencies = [
"arboard",
+ "craft-window",
"designcraft-engine",
"designcraft-ui-egui",
"eframe",
@@ -1239,6 +1251,7 @@ name = "designcraft-ui-egui"
version = "0.13.0"
dependencies = [
"craft-ui",
+ "craft-window",
"designcraft-color",
"designcraft-compose",
"designcraft-doc",
diff --git a/Cargo.toml b/Cargo.toml
index 9fc362328..e61b0f932 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -87,6 +87,8 @@ craft-cms = { version = "0.1.0", git = "https://github.com/storytold/craft-libs"
# ui
# Shared frontend components; keep this dependency above the engine boundary.
craft-ui = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5c874d51eeb3de70e735c8ce87a59a7dedd47675", features = ["serde"] }
+# The application bar as the window's title bar (craft-libs).
+craft-window = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "ea4c823abb46fa9d21361604ed1c6d21c54e9ca8", features = ["egui"] }
egui = "0.36"
egui_extras = { version = "0.36", default-features = false, features = ["svg"] }
eframe = { version = "0.36", default-features = false }
diff --git a/ROADMAP.md b/ROADMAP.md
index 458b706cc..11c895468 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -12,6 +12,9 @@
DesignCraft aims at full Adobe InDesign parity — and to be better: faster, open (documented JSON format + IDML), scriptable by agents (MCP), and available on the web.
+- **2026-10-25** · The application bar uses craft-window's shared title-bar code. A drag that
+ starts on a floating panel over the bar moves the panel, not the window, and in full screen the
+ bar no longer zooms or moves the window. No readiness percentage change.
- **2026-10-24** · Embedded IDML keeps independent placed-PDF layer choices in table-cell and
footnote text. The variant rewrite reaches endnote stories too, but IDML endnote structures and
artwork remain unsupported. External-only export continues to reject active nested choices.
diff --git a/apps/designcraft/Cargo.toml b/apps/designcraft/Cargo.toml
index 7dc83bc55..9424948d2 100644
--- a/apps/designcraft/Cargo.toml
+++ b/apps/designcraft/Cargo.toml
@@ -41,10 +41,12 @@ winsafe = { version = "0.0.29", default-features = false, features = ["user"] }
# The same winit as eframe; only the native termination opt-in is used.
winit = { version = "0.30", default-features = false }
muda = { version = "0.21", default-features = false }
-# The input context, to drop the IME's marked text when the Type tool ends a composition; the
-# window's `movable` flag (see `mac_window`). The versions muda uses, through safe methods.
+# The input context, to drop the IME's marked text when the Type tool ends a composition. The
+# versions muda uses, through safe methods.
objc2 = "0.6"
-objc2-app-kit = { version = "0.3", default-features = false, features = ["std", "NSApplication", "NSResponder", "NSTextInputContext", "NSWindow"] }
+objc2-app-kit = { version = "0.3", default-features = false, features = ["std", "NSResponder", "NSTextInputContext"] }
+# The window's `movable` flag follows the application bar's controls.
+craft-window = { workspace = true }
# Finder double-clicks, Open With, Dock drops and `open -a DesignCraft brochure.idml` arrive as a
# kAEOpenDocuments Apple event, which winit 0.30 doesn't handle. This crate (also used by PhotoCraft,
# PdfCraft and WordCraft) registers the handler behind a safe API (Objective-C interop needs unsafe,
diff --git a/apps/designcraft/src/mac_window.rs b/apps/designcraft/src/mac_window.rs
deleted file mode 100644
index b7fd267f1..000000000
--- a/apps/designcraft/src/mac_window.rs
+++ /dev/null
@@ -1,31 +0,0 @@
-//! macOS: AppKit moves the window when a drag starts anywhere in the title-bar band, on the
-//! application bar's controls too. The window is made unmovable while the pointer is on one of
-//! them (`designcraft_ui_egui::title_bar::window_movable`), so only the bar's empty space moves it.
-
-use objc2::MainThreadMarker;
-use objc2_app_kit::{NSApplication, NSWindowStyleMask};
-
-/// Sets the window's `movable` flag from this frame's title bar. `applied` holds the value last
-/// set, so AppKit is only called when it changes.
-pub fn sync_movable(ctx: &egui::Context, applied: &mut Option<bool>) {
- let movable = designcraft_ui_egui::title_bar::window_movable(ctx);
- if *applied == Some(movable) {
- return;
- }
- // eframe runs the app on the main thread; anywhere else AppKit is out of reach.
- let Some(mtm) = MainThreadMarker::new() else {
- return;
- };
- let mut found = false;
- for window in NSApplication::sharedApplication(mtm).windows().to_vec() {
- // The main window is the only one with a full-size content view.
- if window.styleMask().contains(NSWindowStyleMask::FullSizeContentView) {
- window.setMovable(movable);
- found = true;
- }
- }
- // Before the window is on screen there is nothing to set yet; try again next frame.
- if found {
- *applied = Some(movable);
- }
-}
diff --git a/apps/designcraft/src/main.rs b/apps/designcraft/src/main.rs
index 195a2dc6e..1f2c0ff32 100644
--- a/apps/designcraft/src/main.rs
+++ b/apps/designcraft/src/main.rs
@@ -20,8 +20,6 @@ mod gpu;
mod gpu_limits;
mod logging;
#[cfg(target_os = "macos")]
-mod mac_window;
-#[cfg(target_os = "macos")]
mod native_menu;
mod profile;
@@ -91,7 +89,7 @@ impl eframe::App for App {
discard_marked_text();
}
#[cfg(target_os = "macos")]
- mac_window::sync_movable(ui.ctx(), &mut self.movable);
+ craft_window::title_bar::sync_movable(ui.ctx(), &mut self.movable);
}
fn on_exit(&mut self) {
// A normal exit before the third frame is not a crash.
diff --git a/crates/ui-egui/Cargo.toml b/crates/ui-egui/Cargo.toml
index c9d85253f..816144f97 100644
--- a/crates/ui-egui/Cargo.toml
+++ b/crates/ui-egui/Cargo.toml
@@ -11,6 +11,7 @@ workspace = true
[dependencies]
craft-ui = { workspace = true }
+craft-window = { workspace = true }
designcraft-geom = { workspace = true }
designcraft-color = { workspace = true }
designcraft-doc = { workspace = true }
diff --git a/crates/ui-egui/src/chrome.rs b/crates/ui-egui/src/chrome.rs
index 5183222eb..c6ba485c6 100644
--- a/crates/ui-egui/src/chrome.rs
+++ b/crates/ui-egui/src/chrome.rs
@@ -204,7 +204,7 @@ pub fn app_bar(app: &mut DesignApp, ui: &mut egui::Ui) {
egui::pos2(full.min.x - f32::from(left), full.min.y),
egui::pos2(full.max.x + 10.0, full.min.y + MAC_APP_BAR),
);
- crate::title_bar::empty_area(ui, band);
+ let _ = craft_window::title_bar::empty_area(ui, band);
}
let mut menus_end = full.min.x;
let mut tools_start = full.max.x;
@@ -2088,7 +2088,7 @@ mod tests {
let mut movable_at = |at: egui::Pos2| {
h.hover_at(at);
h.run_steps(2);
- crate::title_bar::window_movable(&h.ctx)
+ craft_window::title_bar::window_movable(&h.ctx)
};
for at in [pos2(bar.center().x, mid), pos2(bar.min.x + MAC_CONTENT_LEFT - 4.0, bar.min.y + 4.0), pos2(bar.center().x, 500.0)] {
assert!(movable_at(at), "empty title bar or the page at {at:?}");
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index 96c2c6eda..26ea71f59 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -32,7 +32,6 @@ mod shortcut_import;
pub mod story_editor;
pub mod taskbar;
pub mod theme;
-pub mod title_bar;
pub mod toolbar;
pub mod widgets;
diff --git a/crates/ui-egui/src/title_bar.rs b/crates/ui-egui/src/title_bar.rs
deleted file mode 100644
index a369fa9fb..000000000
--- a/crates/ui-egui/src/title_bar.rs
+++ /dev/null
@@ -1,138 +0,0 @@
-//! The application bar as the window's title bar (macOS): an empty part of it moves the window
-//! when dragged and follows the system's title-bar double-click setting.
-//!
-//! The window has a full-size content view, so AppKit hands every click in the title-bar band to
-//! the app (that is how the bar's own controls work) and does not zoom the window. It does move
-//! the window when a drag starts anywhere in the band, on the bar's controls too, unless the
-//! window is not movable. [`window_movable`] tells the macOS shell when the pointer is on a
-//! control, so it can switch that off before the press.
-
-use std::sync::{Once, OnceLock};
-
-/// System Settings › Desktop & Dock › "Double-click a window's title bar to".
-#[derive(Clone, Copy, Debug, PartialEq, Eq)]
-pub enum DoubleClick {
- Zoom,
- Minimize,
- Nothing,
-}
-
-/// The value of the global default `AppleActionOnDoubleClick`, as `defaults read` prints it.
-/// Anything other than "Minimize" or "None" zooms, the macOS default ("Maximize"; macOS 15 adds
-/// "Fill", which zooming comes closest to).
-pub fn parse(defaults_output: &str) -> DoubleClick {
- match defaults_output.trim() {
- "Minimize" => DoubleClick::Minimize,
- "None" => DoubleClick::Nothing,
- _ => DoubleClick::Zoom,
- }
-}
-
-static ACTION: OnceLock<DoubleClick> = OnceLock::new();
-static READ: Once = Once::new();
-
-/// Starts reading the system setting on a background thread, once per run.
-fn prefetch() {
- READ.call_once(|| {
- #[cfg(all(target_os = "macos", not(test)))]
- {
- // No thread, no setting: the bar zooms.
- let _ = std::thread::Builder::new().name("title-bar-setting".into()).spawn(|| {
- let action = match std::process::Command::new("/usr/bin/defaults").args(["read", "-g", "AppleActionOnDoubleClick"]).output() {
- Ok(out) if out.status.success() => parse(&String::from_utf8_lossy(&out.stdout)),
- // Absent (never changed) or unreadable: the default.
- _ => DoubleClick::Zoom,
- };
- let _ = ACTION.set(action);
- });
- }
- });
-}
-
-/// The system setting; zoom until it has been read.
-pub fn action() -> DoubleClick {
- ACTION.get().copied().unwrap_or(DoubleClick::Zoom)
-}
-
-/// What a double-click on the empty title bar asks of the window.
-pub fn double_click_command(action: DoubleClick, maximized: bool) -> Option<egui::ViewportCommand> {
- match action {
- DoubleClick::Zoom => Some(egui::ViewportCommand::Maximized(!maximized)),
- DoubleClick::Minimize => Some(egui::ViewportCommand::Minimized(true)),
- DoubleClick::Nothing => None,
- }
-}
-
-/// Makes the empty part of `rect` act as a title bar. Call it before drawing the bar's controls:
-/// they sit on top and take their own clicks.
-///
-/// The area senses clicks only. A drag-sensing background would also receive drags that start
-/// on a click-only control (egui gives clicks and drags to different widgets), so a drag is
-/// detected here as a press on the empty area that has stopped being a click.
-pub fn empty_area(ui: &mut egui::Ui, rect: egui::Rect) {
- prefetch();
- let resp = ui.interact(rect, ui.id().with("title_bar_empty"), egui::Sense::click());
- // A control in this layer covers the empty area under the pointer. Another layer on top (a
- // modal's backdrop, a tooltip) leaves the window movable, as AppKit's own title bar would be.
- let on_control =
- ui.ctx().pointer_hover_pos().is_some_and(|p| rect.contains(p) && ui.ctx().layer_id_at(p) == Some(ui.layer_id())) && !resp.hovered();
- let pass = ui.ctx().cumulative_pass_nr();
- ui.data_mut(|d| d.insert_temp(movable_id(), (pass, !on_control)));
- if resp.double_clicked() {
- let maximized = ui.input(|i| i.viewport().maximized).unwrap_or(false);
- if let Some(cmd) = double_click_command(action(), maximized) {
- ui.ctx().send_viewport_cmd(cmd);
- }
- }
- // egui forgets which widget a press landed on once it can no longer be a click, so the press
- // is remembered (by its start time) while it still can.
- let armed = resp.id.with("drag_press");
- let press = ui.input(|i| i.pointer.press_start_time());
- if resp.is_pointer_button_down_on() {
- ui.data_mut(|d| d.insert_temp(armed, press));
- }
- if press.is_some() && ui.input(|i| i.pointer.is_decidedly_dragging()) && ui.data(|d| d.get_temp::<Option<f64>>(armed)) == Some(press) {
- // Once per press: AppKit's drag loop takes the mouse-up, so egui may still see the button
- // down afterwards.
- ui.data_mut(|d| d.remove::<Option<f64>>(armed));
- ui.ctx().send_viewport_cmd(egui::ViewportCommand::StartDrag);
- }
-}
-
-fn movable_id() -> egui::Id {
- egui::Id::new("title_bar_window_movable")
-}
-
-/// Whether AppKit may move the window when a drag starts in the title-bar band: false while the
-/// pointer is on one of the bar's controls, so pressing and dragging it does not move the window.
-/// True when neither this pass nor the one before drew a title bar.
-pub fn window_movable(ctx: &egui::Context) -> bool {
- match ctx.data(|d| d.get_temp::<(u64, bool)>(movable_id())) {
- Some((pass, movable)) if ctx.cumulative_pass_nr().saturating_sub(pass) <= 1 => movable,
- _ => true,
- }
-}
-
-#[cfg(test)]
-mod tests {
- use super::*;
-
- #[test]
- fn parses_the_defaults_output() {
- assert_eq!(parse("Maximize\n"), DoubleClick::Zoom);
- assert_eq!(parse("Minimize\n"), DoubleClick::Minimize);
- assert_eq!(parse("None\n"), DoubleClick::Nothing);
- for junk in ["", "Fill", "minimize", "1", "The domain/default pair of (kCFPreferencesAnyApplication, X) does not exist"] {
- assert_eq!(parse(junk), DoubleClick::Zoom, "{junk:?}");
- }
- }
-
- #[test]
- fn zoom_toggles_and_minimize_minimizes() {
- use egui::ViewportCommand::{Maximized, Minimized};
- assert_eq!(double_click_command(DoubleClick::Zoom, false), Some(Maximized(true)));
- assert_eq!(double_click_command(DoubleClick::Zoom, true), Some(Maximized(false)));
- assert_eq!(double_click_command(DoubleClick::Minimize, false), Some(Minimized(true)));
- assert_eq!(double_click_command(DoubleClick::Nothing, true), None);
- }
-}
diff --git a/xtask/src/layers.rs b/xtask/src/layers.rs
index 8355fb95d..cff38ae87 100644
--- a/xtask/src/layers.rs
+++ b/xtask/src/layers.rs
@@ -74,7 +74,7 @@ fn intra_layer_allowed(from: &str, to: &str) -> bool {
/// External crates that constitute a UI toolkit / windowing dependency.
/// Entries ending in `*` are prefixes.
-pub const UI_CRATES: &[&str] = &["craft-ui", "egui", "eframe", "winit", "egui_kittest", "rfd", "bevy*"];
+pub const UI_CRATES: &[&str] = &["craft-ui", "craft-window", "egui", "eframe", "winit", "egui_kittest", "rfd", "bevy*"];
/// First layer allowed to use UI crates.
pub const UI_MIN_LAYER: u8 = 6;