mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 15:44:26 +00:00
Dock a native window by dragging its title row
A floating dock group in its own OS window now moves through a window move gesture the app runs, which reports Begin, Update, Commit and Cancel like a layer's move, so the dock marks the target under the pointer and docks the whole window on release. - macOS (Caps::OS_MOVES_TRACKED): the OS moves the window (StartMove), and the app follows the system pointer, button and Cmd through SystemWindows, the running platform's WindowSystem in craft-window. The hand-off ends when the system reports the button up. - X11 and Windows: the app moves the window with SetOuterPosition so the pressed point stays under the pointer; Escape puts it back. - A drag started by a container shown in its own OS window follows that window's pointer, not its parent's. - The runtime's end hook sets NSWindow.movable for every window; a window whose move the app runs is never moved by AppKit from its band.
This commit is contained in:
@@ -11,7 +11,7 @@ use craft_host::target::{Backend, Os, ShellInfo, WindowState};
|
||||
use craft_window::desktop::fits;
|
||||
use craft_window::policy::Decision;
|
||||
use craft_window::restore::Store;
|
||||
use craft_window::system::{NoWindows, WindowSystem};
|
||||
use craft_window::system::{SystemWindows, WindowSystem};
|
||||
use egui::{Context, Ui, ViewportId};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use web_time::Instant;
|
||||
@@ -29,7 +29,7 @@ pub struct AppSpec {
|
||||
pub defaults: Defaults,
|
||||
/// Where window placement is kept.
|
||||
pub placement: Arc<Mutex<Store>>,
|
||||
/// The OS services the window host reads: the system pointer and its warp.
|
||||
/// The OS services the window host reads: the system pointer, button and modifier state, and the pointer's warp.
|
||||
pub window_system: Arc<dyn WindowSystem>,
|
||||
/// Who draws the root window's frame (`craft_window::policy::decide_for`). Unset: the OS draws it.
|
||||
pub frame: Option<Decision>,
|
||||
@@ -45,7 +45,7 @@ impl AppSpec {
|
||||
shell_info: ShellInfo::default().backend(Backend::from_env()),
|
||||
defaults,
|
||||
placement: Arc::new(Mutex::new(Store::in_memory())),
|
||||
window_system: Arc::new(NoWindows),
|
||||
window_system: Arc::new(SystemWindows),
|
||||
frame: None,
|
||||
}
|
||||
}
|
||||
@@ -119,8 +119,6 @@ pub trait ShellApp {
|
||||
/// frame. `logic` carries the close path, which must run while the window is hidden.
|
||||
struct Driver<A> {
|
||||
app: A,
|
||||
/// The `movable` flag last set on the native window.
|
||||
movable: Option<bool>,
|
||||
/// Whether the first fit of the root window to its monitor has run.
|
||||
fitted: bool,
|
||||
}
|
||||
@@ -174,7 +172,6 @@ impl<A: ShellApp> eframe::App for Driver<A> {
|
||||
self.fitted = fit_first(ui.ctx());
|
||||
}
|
||||
self.app.ui(ui);
|
||||
super::title_bar::sync_movable(ui.ctx(), &mut self.movable);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,7 +216,7 @@ fn create<A: ShellApp + 'static>(
|
||||
crate::install(&cc.egui_ctx, install).map_err(|error| format!("the runtime could not be installed: {error}"))?;
|
||||
// The suite's interface face; an app that installs its own fonts in `make` replaces it.
|
||||
crate::fonts::UiFonts::new(&crate::fonts::I18nScripts).install(&cc.egui_ctx);
|
||||
Ok(Box::new(Driver { app: make(&cc.egui_ctx), movable: None, fitted: false }))
|
||||
Ok(Box::new(Driver { app: make(&cc.egui_ctx), fitted: false }))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,12 +6,10 @@ use egui::Context;
|
||||
|
||||
/// Whether the OS may move the running viewport's window from where the pointer is in this pass: what the move bands
|
||||
/// of the pass wrote (the body step writes it for every move band of an OS window, `true` only where a press would go
|
||||
/// to the band), else what the app wrote with [`set_window_movable`], else true.
|
||||
/// to the band), else what the app wrote with [`set_window_movable`], else true. The runtime sets macOS's
|
||||
/// `NSWindow.movable` from it at the end of each window's pass.
|
||||
pub fn window_movable(ctx: &Context) -> bool {
|
||||
match viewports::movable_record(ctx) {
|
||||
Some((pass, movable)) if pass == viewports::pass_number(ctx) => movable,
|
||||
_ => true,
|
||||
}
|
||||
viewports::movable(ctx)
|
||||
}
|
||||
|
||||
/// Records that the OS may move the running viewport's window in this pass (`true`) or not. `AppShell` writes `false`
|
||||
@@ -22,26 +20,6 @@ pub fn set_window_movable(ctx: &Context, movable: bool) {
|
||||
viewports::write_movable(ctx, movable);
|
||||
}
|
||||
|
||||
/// Sets the `movable` flag of the context's window from this pass's [`window_movable`]: the one place AppKit's flag is
|
||||
/// set. Call it once per frame per window, after that window's UI has run; `applied` holds the value last set for the window, so AppKit is only
|
||||
/// called when it changes.
|
||||
///
|
||||
/// A window is told apart by its viewport: the key window is the one whose viewport has focus, so an unfocused
|
||||
/// viewport is left as it is. Only a window with a full-size content view and visible window buttons is touched,
|
||||
/// because floating panels in their own windows keep their own `movable`, which AppKit also needs to resize them.
|
||||
/// Only a macOS window has a flag to set; elsewhere the call does nothing. Apple builds do not run on the dev box,
|
||||
/// so the macOS side compiles by inspection until the Mac builds it.
|
||||
pub fn sync_movable(ctx: &Context, applied: &mut Option<bool>) {
|
||||
if !viewports::current(ctx).focus_reported {
|
||||
return;
|
||||
}
|
||||
let movable = window_movable(ctx);
|
||||
if *applied == Some(movable) {
|
||||
return;
|
||||
}
|
||||
viewports::set_native_movable(movable, applied);
|
||||
}
|
||||
|
||||
// The bar, its title and its two ends.
|
||||
mod bar;
|
||||
mod measure;
|
||||
|
||||
Reference in New Issue
Block a user