Keep floating window moves pixel-stable

Round fitted window frames to whole logical pixels and accumulate drag deltas from the gesture start. This prevents floating-point size noise from rebuilding window content while preserving fractional pointer movement and resizing behavior.
This commit is contained in:
2026-11-11 03:28:34 +00:00
parent 98c985e27f
commit 8361322fe2
5 changed files with 325 additions and 20 deletions
+42 -8
View File
@@ -106,12 +106,26 @@ class _WindowLayerState extends State<WindowLayer>
/// Where the pointer is in the host while the title is dragged.
Offset? _pointer;
/// The frame the current move or resize started from and the pointer delta
/// summed since. Every event sets the frame from `start + total`: fitting
/// one fractional step after another would round part of the pointer's
/// movement away each time and drift, and shifting the fitted frame would
/// change its size in its last bits.
Rect? _dragStart;
Offset _dragTotal = Offset.zero;
void _move(Offset delta, Offset globalPosition) {
final box = context.findRenderObject();
_pointer = box is RenderBox ? box.globalToLocal(globalPosition) : null;
final start = _dragStart ??= _current;
_dragTotal += delta;
widget.manager.setFrame(
_id,
fitWindowFrame(_current.shift(delta), widget.bounds, widget.kind.minSize),
fitWindowFrame(
start.shift(_dragTotal),
widget.bounds,
widget.kind.minSize,
),
save: false,
);
}
@@ -121,6 +135,7 @@ class _WindowLayerState extends State<WindowLayer>
void _moveEnded() {
final pointer = _pointer;
_pointer = null;
_endDrag();
final bounds = widget.bounds;
final snap = pointer == null ? null : windowSnapFor(pointer, bounds);
if (snap == WindowSnap.maximize) {
@@ -145,15 +160,16 @@ class _WindowLayerState extends State<WindowLayer>
}
void _resize(Offset delta) {
final rect = _current;
final start = _dragStart ??= _current;
_dragTotal += delta;
widget.manager.setFrame(
_id,
fitWindowFrame(
Rect.fromLTWH(
rect.left,
rect.top,
rect.width + delta.dx,
rect.height + delta.dy,
start.left,
start.top,
start.width + _dragTotal.dx,
start.height + _dragTotal.dy,
),
widget.bounds,
widget.kind.minSize,
@@ -162,16 +178,34 @@ class _WindowLayerState extends State<WindowLayer>
);
}
void _resizeEnded() {
_endDrag();
widget.manager.commit(_id);
}
/// A drag ends here even if it is cancelled or another gesture begins.
void _endDrag() {
_dragStart = null;
_dragTotal = Offset.zero;
}
/// A press brings the window to the top and gives it the keyboard at
/// once, before the press does anything else (focus a field, open a
/// popup that takes the keyboard itself).
void _pressed() {
// A new gesture measures from where it starts, even if the last drag was
// cancelled before it ended.
_endDrag();
if (!widget.focus.has(_id)) widget.focus.focusNow(_id);
widget.manager.raise(_id);
}
ThemeData _pageThemeFor(ThemeData theme) {
if (identical(theme, _themeSource)) return _pageTheme!;
// Equal to the last theme means the same page theme, even when the app's
// animated theme hands over a new but equal `ThemeData` object: a new
// page theme would notify every content widget that reads the theme on
// every frame of a move.
if (theme == _themeSource) return _pageTheme!;
_themeSource = theme;
return _pageTheme = WindowNavigator.themeData(theme);
}
@@ -263,7 +297,7 @@ class _WindowLayerState extends State<WindowLayer>
bottom: widget.bounds.height - frame.bottom,
child: WindowResizeCorner(
onResize: _resize,
onResizeEnd: () => manager.commit(_id),
onResizeEnd: _resizeEnded,
),
),
],