From a9bb7c794728e87b419741307fc81aa32a8f3dbe Mon Sep 17 00:00:00 2001 From: fufesou Date: Wed, 7 Sep 2022 19:52:30 -0700 Subject: [PATCH] flutter_destkop: fix cursor scale Signed-off-by: fufesou --- flutter/lib/desktop/pages/remote_page.dart | 34 +++++++++++++--------- flutter/lib/models/model.dart | 18 +++++++----- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/flutter/lib/desktop/pages/remote_page.dart b/flutter/lib/desktop/pages/remote_page.dart index cd23328a4..158028ab3 100644 --- a/flutter/lib/desktop/pages/remote_page.dart +++ b/flutter/lib/desktop/pages/remote_page.dart @@ -539,7 +539,7 @@ class ImagePaint extends StatelessWidget { Widget build(BuildContext context) { final m = Provider.of(context); var c = Provider.of(context); - final cursor = Provider.of(context); + final s = c.scale; if (c.scrollStyle == ScrollStyle.scrollbar) { final imageWidget = SizedBox( @@ -568,18 +568,7 @@ class ImagePaint extends StatelessWidget { cursor: (cursorOverImage.isTrue && keyboardEnabled.isTrue) ? (remoteCursorMoved.isTrue ? SystemMouseCursors.none - : (cursor.cacheLinux != null - ? FlutterCustomMemoryImageCursor( - pixbuf: cursor.cacheLinux!.data, - key: cursor.cacheLinux!.key, - hotx: cursor.cacheLinux!.hotx, - hoty: cursor.cacheLinux!.hoty, - imageWidth: - (cursor.cacheLinux!.width * s).toInt(), - imageHeight: - (cursor.cacheLinux!.height * s).toInt(), - ) - : MouseCursor.defer)) + : _buildCustomCursorLinux(context, s)) : MouseCursor.defer, onHover: (evt) { pos.value = evt.position; @@ -599,6 +588,25 @@ class ImagePaint extends StatelessWidget { } } + MouseCursor _buildCustomCursorLinux(BuildContext context, double scale) { + final cursor = Provider.of(context); + final cacheLinux = cursor.cacheLinux; + if (cacheLinux == null) { + return MouseCursor.defer; + } else { + final key = cacheLinux.key(scale); + cursor.addKeyLinux(key); + return FlutterCustomMemoryImageCursor( + pixbuf: cacheLinux.data, + key: key, + hotx: cacheLinux.hotx, + hoty: cacheLinux.hoty, + imageWidth: (cacheLinux.width * scale).toInt(), + imageHeight: (cacheLinux.height * scale).toInt(), + ); + } + } + Widget _buildCrossScrollbar(Widget child) { final physicsVertical = cursorOverImage.value ? const NeverScrollableScrollPhysics() : null; diff --git a/flutter/lib/models/model.dart b/flutter/lib/models/model.dart index 7cf54492a..e96eb35a3 100644 --- a/flutter/lib/models/model.dart +++ b/flutter/lib/models/model.dart @@ -604,7 +604,6 @@ class CursorData { final double hoty; final int width; final int height; - late String key; CursorData({ required this.peerId, @@ -614,10 +613,12 @@ class CursorData { required this.hoty, required this.width, required this.height, - }) { - key = - '${peerId}_${id}_${(hotx * 10e6).round().toInt()}_${(hoty * 10e6).round().toInt()}_${width}_$height'; - } + }); + + int _doubleToInt(double v) => (v * 10e6).round().toInt(); + + String key(double scale) => + '${peerId}_${id}_${_doubleToInt(hotx)}_${_doubleToInt(hoty)}_${_doubleToInt(width * scale)}_${_doubleToInt(height * scale)}'; } class CursorModel with ChangeNotifier { @@ -625,6 +626,7 @@ class CursorModel with ChangeNotifier { final _images = >{}; CursorData? _cacheLinux; final _cacheMapLinux = {}; + final _cacheKeysLinux = {}; double _x = -10000; double _y = -10000; double _hotx = 0; @@ -649,8 +651,8 @@ class CursorModel with ChangeNotifier { CursorModel(this.parent); - List get cachedKeysLinux => - _cacheMapLinux.values.map((v) => v.key).toList(); + Set get cachedKeysLinux => _cacheKeysLinux; + addKeyLinux(String key) => _cacheKeysLinux.add(key); // remote physical display coordinate Rect getVisibleRect() { @@ -878,7 +880,7 @@ class CursorModel with ChangeNotifier { } void _clearCacheLinux() { - final cachedKeys = [...cachedKeysLinux]; + final cachedKeys = {...cachedKeysLinux}; for (var key in cachedKeys) { customCursorController.freeCache(key); }