mirror of
https://github.com/storytold/wordcraft.git
synced 2026-12-04 11:46:53 -06:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bfcfdc8987 |
@@ -42,7 +42,7 @@ use craft::platform::default_app::{DefaultApp, DefaultAppError};
|
||||
use craft::platform::logs::{self, LogNames, crash};
|
||||
use craft::platform::open::{DroppedFile, FileIntake, IntakeSender};
|
||||
use craft::print::spool::Spool;
|
||||
use craft::settings::SharedSettings;
|
||||
use craft::settings::{Remembered, SharedSettings};
|
||||
use craft::ui::InstallSpec;
|
||||
use craft::ui::runtime::windows::{WindowAction, WindowHost};
|
||||
use craft::ui::shell::embed;
|
||||
@@ -518,6 +518,22 @@ fn run_with_visible_root_fallback(
|
||||
result
|
||||
}
|
||||
|
||||
/// The saved slot of the first document window under a windowless root (`wordcraft_ui_egui::windows`).
|
||||
const MAIN_PLACE_KEY: &str = "wordcraft.main_window";
|
||||
|
||||
/// A windowless root has no window of its own to save, so the first document window keeps its place in a
|
||||
/// slot of the settings. A profile from the visible root only has the placement store's `main` entry: copy it
|
||||
/// once, so an upgrade keeps the window's size and position.
|
||||
fn migrate_main_place(host: &Host, store: &Store) {
|
||||
let slot = Remembered::<serde_json::Value>::new(MAIN_PLACE_KEY);
|
||||
if slot.recall(host).is_some() {
|
||||
return;
|
||||
}
|
||||
if let Some(old) = store.get(restore::MAIN) {
|
||||
slot.store(host, &serde_json::json!({"pos": old.normal.pos, "size": old.normal.size}));
|
||||
}
|
||||
}
|
||||
|
||||
/// Parses the command line, installs logging and the panic hook, restores preferences and window
|
||||
/// geometry, opens requested documents or the Start screen, starts the control server when
|
||||
/// asked, and runs the eframe event loop.
|
||||
@@ -784,6 +800,9 @@ fn main() -> eframe::Result {
|
||||
.lang(lang.craft_lang())
|
||||
.build(),
|
||||
);
|
||||
if windowless_in_app.load(std::sync::atomic::Ordering::Relaxed) {
|
||||
migrate_main_place(&host, &placement.lock().unwrap_or_else(std::sync::PoisonError::into_inner));
|
||||
}
|
||||
let shell = ShellInfo::current().backend(if x11 { Backend::X11 } else { Backend::from_env() });
|
||||
let mut spec = InstallSpec::new(shell, Arc::new(SystemWindows))
|
||||
.app_id(wordcraft_ui_egui::os_window::app_id())
|
||||
@@ -1271,6 +1290,29 @@ mod smoke {
|
||||
assert!(run.app.app.dialog_host_mut().is_empty(), "Escape dismisses About");
|
||||
assert_eq!(run.app.app.session.doc.plain_text(wordcraft_doc::StoryRef::Body), before);
|
||||
}
|
||||
|
||||
/// An upgraded profile has only the visible root's `main` placement: the first document window of a windowless
|
||||
/// root takes it once, and a place it saved since is kept.
|
||||
#[test]
|
||||
fn the_first_window_takes_the_visible_roots_saved_place_once() {
|
||||
let (settings, _) = prefs::open(false, &mut Store::in_memory());
|
||||
let host = Host::builder(wordcraft_ui_egui::APP).settings(Arc::new(settings)).build();
|
||||
let slot = Remembered::<serde_json::Value>::new(MAIN_PLACE_KEY);
|
||||
let mut store = Store::in_memory();
|
||||
migrate_main_place(&host, &store);
|
||||
assert!(slot.recall(&host).is_none(), "no old place: nothing to copy");
|
||||
let facts = craft::behavior::placement::Placement::new([900.0, 700.0], 1.0);
|
||||
store.set(restore::MAIN, &facts);
|
||||
migrate_main_place(&host, &store);
|
||||
let copied = slot.recall(&host).expect("the old place is copied");
|
||||
assert_eq!(copied["size"][0].as_f64(), Some(900.0));
|
||||
// A fresh profile that already saved a place keeps it.
|
||||
let (settings, _) = prefs::open(false, &mut Store::in_memory());
|
||||
let host = Host::builder(wordcraft_ui_egui::APP).settings(Arc::new(settings)).build();
|
||||
slot.store(&host, &serde_json::json!({"pos": [1.0, 2.0], "size": [300.0, 200.0]}));
|
||||
migrate_main_place(&host, &store);
|
||||
assert_eq!(slot.recall(&host).unwrap()["size"][0].as_f64(), Some(300.0), "a saved place wins");
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -145,7 +145,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
sel_result(s)
|
||||
})
|
||||
.key("Mod+W / Mod+F4")
|
||||
.params(r#"{"save"?: bool (desktop app's control channel and MCP bridge only: save the shown document, then close it; it does not apply to a background `doc`, which needs force or its own save first), "force"?: bool (desktop app's control channel and MCP bridge only: without save or force a document with unsaved changes is an error and stays open; with force the changes are discarded. Headless sessions never ask; file.closeDocument closes a document there)}"#)
|
||||
.params(r#"{"save"?: bool (desktop app's control channel and MCP bridge only: save the shown document, then close it (when another window shows the same document, only the window closes and the document stays open in it; the result has `window: true`); it does not apply to a background `doc`, which needs force or its own save first), "force"?: bool (desktop app's control channel and MCP bridge only: without save or force a document with unsaved changes is an error and stays open; with force the changes are discarded. Headless sessions never ask; file.closeDocument closes a document there)}"#)
|
||||
.pure(),
|
||||
CommandSpec::new("file.closeDocument", "Close Document", "Agents", close_document)
|
||||
.params(r#"{"id"?: n (an open document, see view.switchWindows; default the active one), "force"?: bool (discard unsaved changes; without it a document with unsaved changes is an error and stays open)} → {"closed": id, "active": id, "documents": [{"id", "title", "path", "dirty", "active"}]}; closing the last document leaves a new blank one"#)
|
||||
|
||||
@@ -613,7 +613,10 @@ impl WordApp {
|
||||
if !self.document_unsaved() {
|
||||
return Ok(None);
|
||||
}
|
||||
if self.session.path.is_none() || self.legacy_word_path() {
|
||||
if self.legacy_word_path() {
|
||||
return Err("this Word 97-2003 format can only be opened, not saved in place: use file.saveAs to write another format first, or pass {\"force\": true} to discard it".into());
|
||||
}
|
||||
if self.session.path.is_none() {
|
||||
return Err("the document has no file to save to: use file.saveAs first, or pass {\"force\": true} to discard it".into());
|
||||
}
|
||||
match self.save_for_prompt()? {
|
||||
|
||||
@@ -424,7 +424,11 @@ fn handle_request(app: &mut WordApp, ctx: &egui::Context, req: &ControlRequest)
|
||||
// `window` names another window by its key; none means the active one (spec rule 8).
|
||||
"ui.closeWindow" => {
|
||||
let viewport = match p.get("window").filter(|w| !w.is_null()) {
|
||||
None => app.active_viewport(),
|
||||
// No fallback to another window: the active one may not have drawn yet (`file.new` in the same pass).
|
||||
None => match app.active_window_viewport() {
|
||||
Some(v) => v,
|
||||
None => return err("the active window is not open yet: retry once it has drawn, or name it with `window`"),
|
||||
},
|
||||
Some(w) => match w.as_u64().and_then(|key| app.window_viewport(key)) {
|
||||
Some(v) => v,
|
||||
None => return err("`window` is not an open window: use a key from ui.inspect windows (`current`, `others[].id`)"),
|
||||
|
||||
@@ -239,6 +239,15 @@ impl WordApp {
|
||||
if windowless_root(ctx) { own.or_else(|| self.windows.viewports(ctx).first().copied()) } else { own }.unwrap_or(ViewportId::ROOT)
|
||||
}
|
||||
|
||||
/// The viewport of the active window itself: `None` while its OS window isn't open yet, where
|
||||
/// [`WordApp::active_viewport`] falls back to another window. For a request that must not reach a different one.
|
||||
pub fn active_window_viewport(&self) -> Option<ViewportId> {
|
||||
let Some(ctx) = self.ctx.as_ref().filter(|ctx| self.windows.native && WindowHost::of(ctx).opens_windows()) else {
|
||||
return Some(ViewportId::ROOT);
|
||||
};
|
||||
self.windows.viewport_of(ctx, self.windows.list.active().unwrap_or(self.windows.shown))
|
||||
}
|
||||
|
||||
/// The viewport of the window with key `key` (the number `ui.inspect` windows gives: `current`, `others[].id`): `None` when there is no such window or its OS window isn't open yet.
|
||||
pub fn window_viewport(&self, key: u64) -> Option<ViewportId> {
|
||||
let ctx = self.ctx.as_ref().filter(|ctx| self.windows.native && WindowHost::of(ctx).opens_windows())?;
|
||||
|
||||
@@ -1217,12 +1217,33 @@ fn ui_closewindow_closes_the_active_window_or_the_one_named() {
|
||||
assert_eq!(r["ok"], true, "{r}");
|
||||
rig.frame(&mut a);
|
||||
assert!(rig.sent(middle_vp, &ViewportCommand::Close) && !rig.sent(active_vp, &ViewportCommand::Close), "only the named window");
|
||||
// The next frame delivers the close: that window is gone, the other stays.
|
||||
rig.frames(&mut a, 2);
|
||||
assert_eq!(a.window_count(), 2);
|
||||
assert!(a.windows.viewport(&rig.ctx(), middle).is_none() && a.windows.viewports(&rig.ctx()).contains(&active_vp));
|
||||
ctl(&mut a, &rig, "ui.closeWindow", json!({}));
|
||||
rig.frame(&mut a);
|
||||
assert!(rig.sent(active_vp, &ViewportCommand::Close), "no `window`: the active one");
|
||||
rig.frames(&mut a, 2);
|
||||
assert_eq!(a.window_count(), 1);
|
||||
assert!(!a.windows.viewports(&rig.ctx()).contains(&active_vp));
|
||||
assert_eq!(ctl(&mut a, &rig, "ui.closeWindow", json!({"window": 9999}))["ok"], false);
|
||||
}
|
||||
|
||||
/// A `ui.closeWindow` with no `window`, sent in the pass that opened the active window, has no viewport to close
|
||||
/// yet: it refuses instead of closing the window that was active before.
|
||||
#[test]
|
||||
fn ui_closewindow_without_window_refuses_while_the_active_window_has_not_drawn() {
|
||||
let mut rig = Rig::windowless();
|
||||
let mut a = app("One");
|
||||
rig.frames(&mut a, 3);
|
||||
a.run("file.new", json!({})).unwrap();
|
||||
let r = ctl(&mut a, &rig, "ui.closeWindow", json!({}));
|
||||
assert_eq!(r["ok"], false, "{r}");
|
||||
rig.frame(&mut a);
|
||||
assert!(rig.commands.iter().all(|(_, c)| *c != ViewportCommand::Close), "no other window was closed");
|
||||
}
|
||||
|
||||
/// Spec rule 3: clicking another window while the Save prompt is up brings the prompt back
|
||||
/// (existing focus handling already does; this pins it).
|
||||
#[test]
|
||||
|
||||
@@ -16,7 +16,9 @@ craft-libs) will carry it.
|
||||
## Amendment 2026-12-03: X11 keeps a visible root
|
||||
|
||||
On X11, XWayland and BSD on X11, egui's windowless root (`RootViewportMode::Windowless`, storytold/egui#91)
|
||||
returns `UnsupportedConfiguration`. There WordCraft falls back to the visible windowed root, and the old
|
||||
returns `UnsupportedConfiguration`. WordCraft reaches the visible windowed root two ways: it chooses X11 up front
|
||||
(`uses_x11`: the display-server setting or `WORDCRAFT_WAYLAND`, with `DISPLAY` set), and then never requests the windowless root; or it requests the
|
||||
windowless root, eframe rejects it (winit chose X11 on its own) and WordCraft retries with the visible root. The old
|
||||
behaviour stays: closing the first window moves another document into it (#7752), because the root window
|
||||
can't close while the app runs. The other close rules in [the spec](../specs/multi-window-close.md) still
|
||||
apply. Revisit when egui supports the windowless root on X11 (asked of Skylar, 2026-12-03).
|
||||
|
||||
@@ -224,7 +224,7 @@ save first (`file.save`), or pass `{"force": true}` to discard the changes and g
|
||||
|
||||
`file.close` closes the shown document, so it is refused while that document has unsaved
|
||||
changes (`unsaved changes: pass save or force`); `{"save": true}` writes it first (a document with no
|
||||
file yet is an error, never a prompt) and then closes it; the bare form `{"method": "file.close", "params": {"force": true}}` (a method name that is a
|
||||
file yet, or one opened from a read-only legacy Word format (`.doc`, `.dot`), is an error with its own message, never a prompt; use `file.saveAs`) and then closes it; the bare form `{"method": "file.close", "params": {"force": true}}` (a method name that is a
|
||||
command id) is guarded the same way, and only a boolean `true` counts as `force`. A document
|
||||
without unsaved changes closes at once (#1268). Closing closes the document and its window, and
|
||||
the window focused before it becomes the active one. The last window stays open with no page,
|
||||
@@ -233,8 +233,9 @@ and `file.new` or `file.open` goes on from there (#1712); closing it doesn't qui
|
||||
the same rule (unsaved changes need `{"force": true}`), and the active window stays active.
|
||||
|
||||
When another window shows the same document, `file.close` closes only the window it is sent to:
|
||||
the document and its unsaved work stay open, so nothing is lost and the command is **not**
|
||||
refused (#3274).
|
||||
the document and its unsaved work stay open, so nothing is lost and a bare `file.close` is **not**
|
||||
refused (#3274). It closes the window without saving. `{"save": true}` still writes the document first, so it
|
||||
is refused for a document with no file or a legacy `.doc`/`.dot` file as above.
|
||||
|
||||
`file.new`, `file.open`, `file.recover` (with `restore`) and the mailings merges open their
|
||||
result as **another document beside** the open ones and leave the unsaved one alone, so they
|
||||
|
||||
+1
-1
@@ -219,7 +219,7 @@ document: the tool works on that document and the active one stays active.
|
||||
An id that names no open document, or a value that isn't a whole number from 0 up, is a tool error.
|
||||
`execute` with `view.switchWindows {"id": n}` makes a document active, and `file.closeDocument
|
||||
{"id": n, "force"?: true}` closes one (unsaved changes need `force`); `file.close {"save"?: true, "force"?: true}` closes the shown
|
||||
document, and unsaved changes need `save` (write, then close) or `force`. Through `--connect`, `doc`
|
||||
document, and unsaved changes need `save` (write, then close) or `force`. With `doc` naming a background document, `file.close` closes that document, not the shown one, and `save` does not apply to it: a dirty background document needs `force`, or make it active (`view.switchWindows`) and save it first. When another window shows the same document, a bare `file.close` closes only the window it targets: the document and its edits stay open, and neither `save` nor `force` is needed (`save` still writes first, and is refused for a document with no file or a legacy `.doc`/`.dot` file). Through `--connect`, `doc`
|
||||
reaches the app's control channel (see [Open documents](control-protocol.md#open-documents)); the
|
||||
app's window keeps showing the document it showed. `screenshot`, `click` and `key` act on the
|
||||
window, so they work on the document on screen.
|
||||
|
||||
@@ -312,9 +312,7 @@ fi
|
||||
if [[ -z "${CROSS_TARGET:-}" ]]; then
|
||||
"$STAGE/usr/bin/wordcraft-cli" --version
|
||||
elif [[ -n "${EMULATOR:-}" ]]; then
|
||||
# Set, so the CLI doesn't restart itself to apply it (malloc_tuning, #7914): under user-mode
|
||||
# QEMU without binfmt the kernel can't run the restarted foreign binary, and glibc hands it to /bin/sh.
|
||||
MALLOC_TRIM_THRESHOLD_=131072 "$EMULATOR" "$STAGE/usr/bin/wordcraft-cli" --version
|
||||
"$EMULATOR" "$STAGE/usr/bin/wordcraft-cli" --version
|
||||
fi
|
||||
echo "==> done"
|
||||
ls -lh "$DIST"
|
||||
|
||||
Reference in New Issue
Block a user