refactor: use latest custom cursor api

This commit is contained in:
kingtous 2022-12-11 14:17:29 +08:00
parent a6135068a9
commit 46a6df86ea
3 changed files with 34 additions and 23 deletions

View File

@ -5,6 +5,8 @@ import 'dart:ui' as ui;
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_custom_cursor/cursor_manager.dart'
as custom_cursor_manager;
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:wakelock/wakelock.dart'; import 'package:wakelock/wakelock.dart';
@ -109,17 +111,17 @@ class _RemotePageState extends State<RemotePage>
id: widget.id, arg: 'show-remote-cursor'); id: widget.id, arg: 'show-remote-cursor');
_zoomCursor.value = _zoomCursor.value =
bind.sessionGetToggleOptionSync(id: widget.id, arg: 'zoom-cursor'); bind.sessionGetToggleOptionSync(id: widget.id, arg: 'zoom-cursor');
if (!_isCustomCursorInited) { // if (!_isCustomCursorInited) {
customCursorController.registerNeedUpdateCursorCallback( // customCursorController.registerNeedUpdateCursorCallback(
(String? lastKey, String? currentKey) async { // (String? lastKey, String? currentKey) async {
if (_firstEnterImage.value) { // if (_firstEnterImage.value) {
_firstEnterImage.value = false; // _firstEnterImage.value = false;
return true; // return true;
} // }
return lastKey == null || lastKey != currentKey; // return lastKey == null || lastKey != currentKey;
}); // });
_isCustomCursorInited = true; // _isCustomCursorInited = true;
} // }
} }
@override @override
@ -366,15 +368,23 @@ class _ImagePaintState extends State<ImagePaint> {
return MouseCursor.defer; return MouseCursor.defer;
} else { } else {
final key = cache.updateGetKey(scale, zoomCursor.value); final key = cache.updateGetKey(scale, zoomCursor.value);
cursor.addKey(key); if (!cursor.cachedKeys.contains(key)) {
return FlutterCustomMemoryImageCursor( debugPrint("Register custom cursor with key $key");
pixbuf: cache.data, // [Safety]
key: key, // It's ok to call async registerCursor in current synchronous context,
hotx: cache.hotx, // because activating the cursor is also an async call and will always
hoty: cache.hoty, // be executed after this.
imageWidth: (cache.width * cache.scale).toInt(), custom_cursor_manager.CursorManager.instance
imageHeight: (cache.height * cache.scale).toInt(), .registerCursor(custom_cursor_manager.CursorData()
); ..buffer = cache.data!
..height = (cache.height * cache.scale).toInt()
..width = (cache.width * cache.scale).toInt()
..hotX = cache.hotx
..hotY = cache.hoty
..name = key);
cursor.addKey(key);
}
return FlutterCustomMemoryImageCursor(key: key);
} }
} }

View File

@ -19,7 +19,7 @@ import 'package:flutter_hbb/common/shared_state.dart';
import 'package:flutter_hbb/utils/multi_window_manager.dart'; import 'package:flutter_hbb/utils/multi_window_manager.dart';
import 'package:tuple/tuple.dart'; import 'package:tuple/tuple.dart';
import 'package:image/image.dart' as img2; import 'package:image/image.dart' as img2;
import 'package:flutter_custom_cursor/flutter_custom_cursor.dart'; import 'package:flutter_custom_cursor/cursor_manager.dart';
import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_svg/flutter_svg.dart';
import '../common.dart'; import '../common.dart';
@ -1113,7 +1113,8 @@ class CursorModel with ChangeNotifier {
_clearCache() { _clearCache() {
final keys = {...cachedKeys}; final keys = {...cachedKeys};
for (var k in keys) { for (var k in keys) {
customCursorController.freeCache(k); debugPrint("deleting cursor with key $k");
CursorManager.instance.deleteCursor(k);
} }
} }
} }

View File

@ -68,7 +68,7 @@ dependencies:
flutter_custom_cursor: flutter_custom_cursor:
git: git:
url: https://github.com/Kingtous/rustdesk_flutter_custom_cursor url: https://github.com/Kingtous/rustdesk_flutter_custom_cursor
ref: 74b1b314142b6775c1243067a3503ac568ebc74b ref: da241145957988efd91cc12a364848eabe505e83
window_size: window_size:
git: git:
url: https://github.com/google/flutter-desktop-embedding.git url: https://github.com/google/flutter-desktop-embedding.git