mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-30 18:27:00 +01:00
Merge remote-tracking branch 'origin/main' into HEAD
This commit is contained in:
commit
7f4fbeb9da
4 files changed
+69
-3
No files matched your search
@@ -22,6 +22,7 @@ use crate::display::Icon;
|
||||
use crate::primitives::IconSpec;
|
||||
use crate::runtime::drag::OsFile;
|
||||
use crate::runtime::env::{Env, Label};
|
||||
use crate::runtime::memory::sub;
|
||||
use crate::runtime::overlay::CloseReason;
|
||||
use crate::runtime::windows::{ResizeEdge, WindowSpec};
|
||||
use crate::sections::{HeaderAction, HeaderStrength, MenuRows, TitleRow};
|
||||
@@ -213,8 +214,19 @@ pub struct FloatingGroupOutput {
|
||||
pub resize: Vec<(ResizeEdge, Rect, Id)>,
|
||||
/// Where `files` were dropped, in the group's layer space, when the drop session knew the pointer.
|
||||
pub files_at: Option<Pos2>,
|
||||
/// A move of the group's window is still running after this pass: its `Begin` has been reported in `placed`, and
|
||||
/// its `Commit` or `Cancel` has not. The passes between two steps report no `placed`.
|
||||
pub moving: bool,
|
||||
}
|
||||
|
||||
/// Whether a move of the group's window is running: set by its `Begin` and `Update` steps, cleared by its `Commit`
|
||||
/// or `Cancel` and by any step of a resize.
|
||||
#[derive(Clone, Copy, Default)]
|
||||
struct Gesture(bool);
|
||||
|
||||
/// The memory slot of [`Gesture`] under the group's id.
|
||||
const GESTURE: &str = "window_gesture";
|
||||
|
||||
impl Outcome for FloatingGroupOutput {
|
||||
type Value = NoValue;
|
||||
|
||||
@@ -619,6 +631,11 @@ impl Component for FloatingGroup<'_> {
|
||||
// A dock window's band double click collapses or expands its column, as a dock column's bar does.
|
||||
let collapsed = self.column.map(|column| column.collapsed.is_some());
|
||||
let iconic = collapsed.filter(|_| self.chevron || self.toggled).map(|collapsed| !collapsed);
|
||||
let gesture = &mut cx.core.memory.shown::<Gesture>(sub(cx.core.id, GESTURE)).0;
|
||||
if let Some(change) = self.placed {
|
||||
*gesture = change.kind == PlacementKind::Move && matches!(change.phase, GesturePhase::Begin | GesturePhase::Update);
|
||||
}
|
||||
let moving = *gesture;
|
||||
let output = FloatingGroupOutput {
|
||||
response: cx.response.clone(),
|
||||
placed: self.placed,
|
||||
@@ -632,6 +649,7 @@ impl Component for FloatingGroup<'_> {
|
||||
grip: cx.move_band(),
|
||||
resize: cx.resize_grips(),
|
||||
files_at: self.files_at,
|
||||
moving,
|
||||
};
|
||||
native::raise(&cx.core.ctx, &output, self.raise);
|
||||
native::fade(&cx.core.ctx, &output);
|
||||
|
||||
@@ -129,7 +129,7 @@ pub fn waited(ctx: &Context, opening: &Opening, output: &FloatingGroupOutput) {
|
||||
/// app window's is recorded, with the rect `kept` gives for the rect the OS shows the window at (outer top-left corner
|
||||
/// and inner size, in desktop points), so a collapsed window keeps its expanded rect
|
||||
/// ([`WindowColumn::kept`](super::WindowColumn::kept)). `None` while the model already holds what the OS reports, so a
|
||||
/// window at rest costs no action.
|
||||
/// window at rest costs no action. A caller skips it while the window's move runs ([`FloatingGroupOutput::moving`]).
|
||||
#[doc(hidden)]
|
||||
pub fn reported<P: Clone>(ctx: &Context, window: &Floating<P>, viewport: ViewportId, kept: impl FnOnce(Rect) -> Rect) -> Option<Action<P>> {
|
||||
let panel = window.panels().next()?;
|
||||
|
||||
@@ -2316,8 +2316,12 @@ impl<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> Pass<'_, P> {
|
||||
kept.edge = keeps.unwrap_or(kept.edge);
|
||||
self.report.actions.push(Action::move_floating_with_edge(anchor.clone(), rect, keeps));
|
||||
}
|
||||
let reported = native::reported(&ctx, window, viewport, |shown| kept.kept(shown, opening.rect, chrome, scene.rtl));
|
||||
self.report.actions.extend(reported);
|
||||
// The OS window's place changes in every pass of a move; the workspace records it once, when the move
|
||||
// ends.
|
||||
if !output.moving {
|
||||
let reported = native::reported(&ctx, window, viewport, |shown| kept.kept(shown, opening.rect, chrome, scene.rtl));
|
||||
self.report.actions.extend(reported);
|
||||
}
|
||||
}
|
||||
} else if let Some(mut change) = output.placed.filter(|change| change.kind != PlacementKind::Move || change.phase == GesturePhase::Commit)
|
||||
{
|
||||
|
||||
@@ -528,6 +528,50 @@ fn a_native_palette_the_app_moves_follows_the_system_pointer_not_a_stale_event()
|
||||
assert_eq!(window.min + ROW_AT.to_vec2(), desktop, "the window lands where the pointer let go");
|
||||
}
|
||||
|
||||
/// While the app moves a native palette by its title row, the dock records no placement, though the OS window reports
|
||||
/// a new place in every pass: the workspace takes no edit per pass of the drag, and records where the window was let
|
||||
/// go once the move ends.
|
||||
#[trial]
|
||||
fn a_native_palette_records_its_place_once_its_move_ends_and_not_in_each_pass_of_it() {
|
||||
let system = Arc::new(FakeSystem::new());
|
||||
let mut dock = NativeDock::on(Os::Linux, Arc::clone(&system));
|
||||
let mut window = FLOAT_AT;
|
||||
let mut desktop = FLOAT_AT.min + ROW_AT.to_vec2();
|
||||
system.set_pointer(Some([desktop.x, desktop.y]));
|
||||
let recorded = |actions: &[Action<u32>]| actions.iter().filter(|action| matches!(action, Action::SetNative { .. })).count();
|
||||
// Each frame, the OS puts the window where the app sent it, and the window reports that place in the next.
|
||||
let frame = |dock: &mut NativeDock, window: &mut Rect, events: Vec<Event>| {
|
||||
let (actions, commands) = dock.frame(events);
|
||||
if let Some(to) = outer_positions(&commands).last() {
|
||||
*window = Rect::from_min_size(*to, window.size());
|
||||
dock.windows.child_info(info(true, *window));
|
||||
}
|
||||
actions
|
||||
};
|
||||
for events in [vec![moved(ROW_AT)], vec![press(ROW_AT)]] {
|
||||
frame(&mut dock, &mut window, events);
|
||||
}
|
||||
// Away from the main window, so the release docks nothing.
|
||||
let step = Vec2::new(40.0, 25.0);
|
||||
let mut during = 0;
|
||||
for _ in 0..6 {
|
||||
desktop += step;
|
||||
system.set_pointer(Some([desktop.x, desktop.y]));
|
||||
let event = moved(desktop - window.min.to_vec2());
|
||||
during += recorded(&frame(&mut dock, &mut window, vec![event]));
|
||||
}
|
||||
assert_ne!(window.min, FLOAT_AT.min, "the window follows the drag");
|
||||
assert_eq!(during, 0, "no placement is recorded while the move runs");
|
||||
let mut after = 0;
|
||||
let let_go = release(desktop - window.min.to_vec2());
|
||||
for events in [vec![let_go], vec![], vec![]] {
|
||||
after += recorded(&frame(&mut dock, &mut window, events));
|
||||
}
|
||||
assert!(after >= 1, "the place the window was let go at is recorded once the move ends");
|
||||
let placed = dock.workspace.layout().floating[0].native.as_ref().and_then(Placement::position);
|
||||
assert_eq!(placed.map(Pos2::from), Some(window.min), "the workspace holds where the window was let go");
|
||||
}
|
||||
|
||||
/// Where the OS moves windows and the app reads the system pointer and button meanwhile (macOS): the title row's press
|
||||
/// hands the move to the OS in its own pass, the system pointer over the main window's group marks it (Cmd keeps the
|
||||
/// drop floating), and the window docks when the system tells the button is up, not on the first pass after the
|
||||
|
||||
Reference in new issue
Block a user