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:
@@ -75,22 +75,54 @@ String windowFrameKey(String kind, String? serverKey, String contentId) =>
|
||||
'$kind\n${serverKey ?? ''}\n$contentId';
|
||||
|
||||
/// [rect] moved and shrunk to fit inside [bounds], at least [minSize] where
|
||||
/// the bounds allow it.
|
||||
/// the bounds allow it, on whole logical pixels.
|
||||
///
|
||||
/// Whole pixels keep a moved window exactly its size from frame to frame: a
|
||||
/// `Rect` stores left, top, right and bottom, so shifting a frame by a
|
||||
/// fractional delta makes its width differ in its last bits, and every widget
|
||||
/// that reads the window's size (its `MediaQuery`) rebuilds and lays out
|
||||
/// again on every pointer event.
|
||||
Rect fitWindowFrame(Rect rect, Size bounds, Size minSize) {
|
||||
final width = rect.width
|
||||
.clamp(minSize.width, double.infinity)
|
||||
.clamp(0.0, bounds.width);
|
||||
final height = rect.height
|
||||
.clamp(minSize.height, double.infinity)
|
||||
.clamp(0.0, bounds.height);
|
||||
final width = _wholePixel(
|
||||
rect.width.clamp(minSize.width, double.infinity).clamp(0.0, bounds.width),
|
||||
minSize.width,
|
||||
bounds.width,
|
||||
);
|
||||
final height = _wholePixel(
|
||||
rect.height
|
||||
.clamp(minSize.height, double.infinity)
|
||||
.clamp(0.0, bounds.height),
|
||||
minSize.height,
|
||||
bounds.height,
|
||||
);
|
||||
return Rect.fromLTWH(
|
||||
rect.left.clamp(0.0, bounds.width - width),
|
||||
rect.top.clamp(0.0, bounds.height - height),
|
||||
_wholePixel(
|
||||
rect.left.clamp(0.0, bounds.width - width),
|
||||
0,
|
||||
bounds.width - width,
|
||||
),
|
||||
_wholePixel(
|
||||
rect.top.clamp(0.0, bounds.height - height),
|
||||
0,
|
||||
bounds.height - height,
|
||||
),
|
||||
width,
|
||||
height,
|
||||
);
|
||||
}
|
||||
|
||||
/// [value] rounded to a whole logical pixel and kept within
|
||||
/// `[minimum, limit]`.
|
||||
///
|
||||
/// A fractional [minimum] rounds up, so the whole-pixel size never drops below
|
||||
/// the minimum the caller asked for; when the limit is too small to hold that,
|
||||
/// the limit wins.
|
||||
double _wholePixel(double value, double minimum, double limit) {
|
||||
final max = limit.floorToDouble();
|
||||
final min = minimum.ceilToDouble().clamp(0.0, max);
|
||||
return value.roundToDouble().clamp(min, max);
|
||||
}
|
||||
|
||||
/// Where [entry] is drawn inside [bounds]: fitted, or filling the area less
|
||||
/// a margin when maximised.
|
||||
Rect drawnWindowFrame(WindowEntry entry, Size bounds, Size minSize) =>
|
||||
|
||||
Reference in New Issue
Block a user