mirror of
https://github.com/rustdesk/rustdesk.git
synced 2024-11-27 23:19:02 +08:00
Merge pull request #1472 from fufesou/flutter_cursors_cache
flutter_destkop: fix cursor cache scale
This commit is contained in:
commit
e393c6aafe
@ -539,7 +539,7 @@ class ImagePaint extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final m = Provider.of<ImageModel>(context);
|
||||
var c = Provider.of<CanvasModel>(context);
|
||||
final cursor = Provider.of<CursorModel>(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<CursorModel>(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;
|
||||
|
@ -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 = <int, Tuple3<ui.Image, double, double>>{};
|
||||
CursorData? _cacheLinux;
|
||||
final _cacheMapLinux = <int, CursorData>{};
|
||||
final _cacheKeysLinux = <String>{};
|
||||
double _x = -10000;
|
||||
double _y = -10000;
|
||||
double _hotx = 0;
|
||||
@ -649,8 +651,8 @@ class CursorModel with ChangeNotifier {
|
||||
|
||||
CursorModel(this.parent);
|
||||
|
||||
List<String> get cachedKeysLinux =>
|
||||
_cacheMapLinux.values.map((v) => v.key).toList();
|
||||
Set<String> 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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user