From f4e2f5f4c6608d907c1137df0938103cb4841451 Mon Sep 17 00:00:00 2001 From: Codex Date: Mon, 30 Nov 2026 12:16:39 +0100 Subject: [PATCH] Honor pre-refactor window preferences and preserve Hand placement clicks --- apps/vectorcraft/src/main.rs | 15 +++++++++++---- crates/ui-egui/src/canvas/tool_adapter.rs | 4 ++-- crates/ui-egui/src/state.rs | 13 +++++++++++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/apps/vectorcraft/src/main.rs b/apps/vectorcraft/src/main.rs index 8f1fb42d68..ea2810fd02 100644 --- a/apps/vectorcraft/src/main.rs +++ b/apps/vectorcraft/src/main.rs @@ -114,8 +114,8 @@ const MIN_SIZE: [f32; 2] = [800.0, 500.0]; /// Apply the saved main-window placement before the first frame. On a first launch the /// framework maximizes the window when its default size would not fit the current screen. -fn restore_main_window(window: &winit::window::Window, store: &Store, wayland: bool) { - use craft::behavior::placement::{Defaults, place}; +fn restore_main_window(window: &winit::window::Window, store: &Store, legacy: Option, wayland: bool) { + use craft::behavior::placement::{Defaults, Placement, place}; use craft::behavior::{Monitor, MonitorKey}; use winit::dpi::{LogicalSize, PhysicalPosition}; @@ -131,7 +131,14 @@ fn restore_main_window(window: &winit::window::Window, store: &Store, wayland: b .collect(); let home = window.current_monitor().or_else(|| window.primary_monitor()).and_then(|monitor| handles.iter().position(|m| *m == monitor)); let defaults = Defaults::new(DEFAULT_SIZE, MIN_SIZE).with_no_position(wayland); - let placement = place(store.get(craft::window::restore::MAIN).as_ref(), &monitors, home, &defaults); + let saved = store.get(craft::window::restore::MAIN).or_else(|| { + let old = legacy?; + let mut placement = Placement::new(old.size, window.scale_factor() as f32); + placement.position_px = old.pos; + placement.maximized = old.maximized; + placement.repaired() + }); + let placement = place(saved.as_ref(), &monitors, home, &defaults); if let Some([x, y]) = placement.position_px { window.set_outer_position(PhysicalPosition::new(x, y)); } @@ -819,7 +826,7 @@ fn main() -> std::process::ExitCode { let winit_window = cc.winit_window().cloned(); let placement = placement_store(); if let Some(window) = &winit_window { - restore_main_window(window, &placement, wayland); + restore_main_window(window, &placement, settings.lock().get().ui.legacy_window, wayland); } let spec = InstallSpec::new(shell_info, Arc::new(SystemWindows)) .app_id(vectorcraft_ui_egui::os_window::app_id()) diff --git a/crates/ui-egui/src/canvas/tool_adapter.rs b/crates/ui-egui/src/canvas/tool_adapter.rs index 031e2875b6..6ebdd54af4 100644 --- a/crates/ui-egui/src/canvas/tool_adapter.rs +++ b/crates/ui-egui/src/canvas/tool_adapter.rs @@ -650,12 +650,12 @@ pub(crate) fn run(app: &mut VectorcraftApp, ui: &mut Ui, pass: &ToolPass) -> Too let mut picked = ToolHostResponse::default(); let mut response = if crate::dialogs::recolor::edit_tab::with_theme_pick(app, |app, tool| picked = host_run(app, ui, pass, tool)) { picked - } else if app.session.tool_id() == "hand" && app.ui.screen_mode != 3 { + } else if app.session.tool_id() == "hand" && app.ui.screen_mode != 3 && app.ui.rearrange_placement.is_none() { let options = crate::app::view::navigation(&app.session.prefs); let mut hand = app.canvas.hand.take().unwrap_or_else(|| craft::ui::canvas::HandTool::new(options)); hand.options = options; let response = host_run(app, ui, pass, &mut hand); - if response.gesture.is_some() && !view_tool_held(app) && ui.input(|i| i.pointer.primary_down()) { + if response.gesture.is_some() && !view_tool_held(app) && ui.input(|i| i.pointer.primary_down() || i.pointer.primary_pressed()) { crate::shortcuts::note_tool_use(app); } app.canvas.hand = Some(hand); diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index 5ac49daeb9..eeef403f06 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -490,6 +490,15 @@ pub struct ContextSpelling { pub suggestions: Vec, } +/// The main window as saved in the UI preferences through 0.24.1. Positions are desktop pixels. +#[derive(Clone, Copy, Debug, Deserialize)] +pub struct LegacyWindow { + pub pos: Option<[i32; 2]>, + pub size: [f32; 2], + #[serde(default)] + pub maximized: bool, +} + /// Two states are equal when they save the same: the settings store writes only a changed saved form, /// and the panels' session state is no change to save. #[derive(Clone, Debug, Serialize, Deserialize)] @@ -500,6 +509,9 @@ pub struct UiState { /// it is never written back. #[serde(rename = "language", skip_serializing)] pub legacy_language: Option, + /// Used until the shared window store has recorded the main window. + #[serde(rename = "window", skip_serializing)] + pub legacy_window: Option, pub brightness: Brightness, /// The panel arrangement: docks, floating windows, closed panels and where each goes back. One /// `Arc` the dock area keeps across frames; writers change it through `Arc::make_mut`. @@ -1448,6 +1460,7 @@ impl Default for UiState { fn default() -> Self { Self { legacy_language: None, + legacy_window: None, brightness: Brightness::MediumDark, dock_workspace: std::sync::Arc::new(crate::panel_docking::default_workspace(&[])), tools_last_used: Default::default(),