mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-09-11 23:11:01 +03:00
fix(flutter): read the live DPR and clamp the painted cursor like the native one
CanvasModel caches devicePixelRatio and only refreshes it when the view style changes, so after the window moves to a monitor with a different DPR the unzoomed cursor kept the previous monitor's scale. Read it from MediaQuery instead, which also rebuilds the cursor when it changes. The native path clamps the scaled bitmap to kMinCursorSize; apply the same clamp to the painted cursor so a small cursor does not change size when the peer moves the mouse. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K8HSHTEHo27mDcJXVyVfSP
This commit is contained in:
@@ -1101,6 +1101,9 @@ class _ImagePaintState extends State<ImagePaint> {
|
|||||||
final m = Provider.of<ImageModel>(context);
|
final m = Provider.of<ImageModel>(context);
|
||||||
var c = Provider.of<CanvasModel>(context);
|
var c = Provider.of<CanvasModel>(context);
|
||||||
final s = c.scale;
|
final s = c.scale;
|
||||||
|
// CanvasModel caches the DPR and only refreshes it when the view style
|
||||||
|
// changes, so read it live to follow the window across monitors.
|
||||||
|
final dpr = MediaQuery.devicePixelRatioOf(context);
|
||||||
|
|
||||||
bool isViewAdaptive() => c.viewStyle.style == kRemoteViewStyleAdaptive;
|
bool isViewAdaptive() => c.viewStyle.style == kRemoteViewStyleAdaptive;
|
||||||
bool isViewOriginal() => c.viewStyle.style == kRemoteViewStyleOriginal;
|
bool isViewOriginal() => c.viewStyle.style == kRemoteViewStyleOriginal;
|
||||||
@@ -1122,7 +1125,7 @@ class _ImagePaintState extends State<ImagePaint> {
|
|||||||
// pixels, so an unzoomed cursor must be shrunk by the DPR to
|
// pixels, so an unzoomed cursor must be shrunk by the DPR to
|
||||||
// keep 1 remote px == 1 physical px, the size Original view
|
// keep 1 remote px == 1 physical px, the size Original view
|
||||||
// already renders it at.
|
// already renders it at.
|
||||||
cursorScale = 1.0 / c.devicePixelRatio;
|
cursorScale = 1.0 / dpr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cursorScale;
|
return cursorScale;
|
||||||
@@ -1420,8 +1423,17 @@ class CursorPaint extends StatelessWidget {
|
|||||||
scale = c.scale;
|
scale = c.scale;
|
||||||
} else if (!isWindows) {
|
} else if (!isWindows) {
|
||||||
// Keep the painted cursor the same physical size as the native one
|
// Keep the painted cursor the same physical size as the native one
|
||||||
// built by getCursorScale() above.
|
// built by getCursorScale() above, including its min-size clamp.
|
||||||
scale = 1.0 / c.devicePixelRatio;
|
scale = 1.0 / MediaQuery.devicePixelRatioOf(context);
|
||||||
|
final image = m.image ?? preDefaultCursor.image;
|
||||||
|
if (scale != 1.0 &&
|
||||||
|
image != null &&
|
||||||
|
((image.width * scale).toInt() < kMinCursorSize ||
|
||||||
|
(image.height * scale).toInt() < kMinCursorSize)) {
|
||||||
|
final sw = kMinCursorSize / image.width;
|
||||||
|
final sh = kMinCursorSize / image.height;
|
||||||
|
scale = sw < sh ? sh : sw;
|
||||||
|
}
|
||||||
x = (m.x * c.scale + cx) / scale - hotx;
|
x = (m.x * c.scale + cx) / scale - hotx;
|
||||||
y = (m.y * c.scale + cy) / scale - hoty;
|
y = (m.y * c.scale + cy) / scale - hoty;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user