flutter_desktop: win scale cursor data
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
6756b67492
commit
0d5eb639a0
@ -41,6 +41,9 @@ const Duration kTabTransitionDuration = Duration.zero;
|
|||||||
const double kEmptyMarginTop = 50;
|
const double kEmptyMarginTop = 50;
|
||||||
const double kDesktopIconButtonSplashRadius = 20;
|
const double kDesktopIconButtonSplashRadius = 20;
|
||||||
|
|
||||||
|
/// [kMinCursorSize] indicates min cursor (w, h)
|
||||||
|
const int kMinCursorSize = 24;
|
||||||
|
|
||||||
/// [kDefaultScrollAmountMultiplier] indicates how many rows can be scrolled after a minimum scroll action of mouse
|
/// [kDefaultScrollAmountMultiplier] indicates how many rows can be scrolled after a minimum scroll action of mouse
|
||||||
const kDefaultScrollAmountMultiplier = 5.0;
|
const kDefaultScrollAmountMultiplier = 5.0;
|
||||||
const kDefaultScrollDuration = Duration(milliseconds: 50);
|
const kDefaultScrollDuration = Duration(milliseconds: 50);
|
||||||
|
@ -339,15 +339,15 @@ class ImagePaint extends StatelessWidget {
|
|||||||
if (cacheLinux == null) {
|
if (cacheLinux == null) {
|
||||||
return MouseCursor.defer;
|
return MouseCursor.defer;
|
||||||
} else {
|
} else {
|
||||||
final key = cacheLinux.key(scale);
|
final key = cacheLinux.updateGetKey(scale);
|
||||||
cursor.addKeyLinux(key);
|
cursor.addKeyLinux(key);
|
||||||
return FlutterCustomMemoryImageCursor(
|
return FlutterCustomMemoryImageCursor(
|
||||||
pixbuf: cacheLinux.data,
|
pixbuf: cacheLinux.data,
|
||||||
key: key,
|
key: key,
|
||||||
hotx: cacheLinux.hotx,
|
hotx: cacheLinux.hotx,
|
||||||
hoty: cacheLinux.hoty,
|
hoty: cacheLinux.hoty,
|
||||||
imageWidth: (cacheLinux.width * scale).toInt(),
|
imageWidth: (cacheLinux.width * cacheLinux.scale).toInt(),
|
||||||
imageHeight: (cacheLinux.height * scale).toInt(),
|
imageHeight: (cacheLinux.height * cacheLinux.scale).toInt(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ import 'package:flutter_hbb/models/user_model.dart';
|
|||||||
import 'package:flutter_hbb/utils/multi_window_manager.dart';
|
import 'package:flutter_hbb/utils/multi_window_manager.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:tuple/tuple.dart';
|
import 'package:tuple/tuple.dart';
|
||||||
|
import 'package:image/image.dart' as img2;
|
||||||
import 'package:flutter_custom_cursor/flutter_custom_cursor.dart';
|
import 'package:flutter_custom_cursor/flutter_custom_cursor.dart';
|
||||||
import 'package:flutter_svg/flutter_svg.dart';
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
|
|
||||||
@ -665,7 +666,9 @@ class CanvasModel with ChangeNotifier {
|
|||||||
class CursorData {
|
class CursorData {
|
||||||
final String peerId;
|
final String peerId;
|
||||||
final int id;
|
final int id;
|
||||||
final Uint8List? data;
|
final img2.Image? image;
|
||||||
|
double scale;
|
||||||
|
Uint8List? data;
|
||||||
final double hotx;
|
final double hotx;
|
||||||
final double hoty;
|
final double hoty;
|
||||||
final int width;
|
final int width;
|
||||||
@ -674,6 +677,8 @@ class CursorData {
|
|||||||
CursorData({
|
CursorData({
|
||||||
required this.peerId,
|
required this.peerId,
|
||||||
required this.id,
|
required this.id,
|
||||||
|
required this.image,
|
||||||
|
required this.scale,
|
||||||
required this.data,
|
required this.data,
|
||||||
required this.hotx,
|
required this.hotx,
|
||||||
required this.hoty,
|
required this.hoty,
|
||||||
@ -683,8 +688,34 @@ class CursorData {
|
|||||||
|
|
||||||
int _doubleToInt(double v) => (v * 10e6).round().toInt();
|
int _doubleToInt(double v) => (v * 10e6).round().toInt();
|
||||||
|
|
||||||
String key(double scale) =>
|
double _checkUpdateScale(double scale) {
|
||||||
'${peerId}_${id}_${_doubleToInt(width * scale)}_${_doubleToInt(height * scale)}';
|
// Update data if scale changed.
|
||||||
|
if (Platform.isWindows) {
|
||||||
|
final tgtWidth = (width * scale).toInt();
|
||||||
|
final tgtHeight = (width * scale).toInt();
|
||||||
|
if (tgtWidth < kMinCursorSize || tgtHeight < kMinCursorSize) {
|
||||||
|
double sw = kMinCursorSize.toDouble() / width;
|
||||||
|
double sh = kMinCursorSize.toDouble() / height;
|
||||||
|
scale = sw < sh ? sh : sw;
|
||||||
|
}
|
||||||
|
if (_doubleToInt(this.scale) != _doubleToInt(scale)) {
|
||||||
|
data = img2
|
||||||
|
.copyResize(
|
||||||
|
image!,
|
||||||
|
width: (width * scale).toInt(),
|
||||||
|
height: (height * scale).toInt(),
|
||||||
|
)
|
||||||
|
.getBytes();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.scale = scale;
|
||||||
|
return scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
String updateGetKey(double scale) {
|
||||||
|
scale = _checkUpdateScale(scale);
|
||||||
|
return '${peerId}_${id}_${_doubleToInt(width * scale)}_${_doubleToInt(height * scale)}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class CursorModel with ChangeNotifier {
|
class CursorModel with ChangeNotifier {
|
||||||
@ -864,15 +895,21 @@ class CursorModel with ChangeNotifier {
|
|||||||
|
|
||||||
_updateCacheLinux(ui.Image image, int id, int w, int h) async {
|
_updateCacheLinux(ui.Image image, int id, int w, int h) async {
|
||||||
ByteData? data;
|
ByteData? data;
|
||||||
|
img2.Image? image2;
|
||||||
if (Platform.isWindows) {
|
if (Platform.isWindows) {
|
||||||
data = await image.toByteData(format: ui.ImageByteFormat.rawRgba);
|
data = await image.toByteData(format: ui.ImageByteFormat.rawRgba);
|
||||||
|
if (data != null) {
|
||||||
|
image2 = img2.Image.fromBytes(w, h, data.buffer.asUint8List());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
data = await image.toByteData(format: ui.ImageByteFormat.png);
|
data = await image.toByteData(format: ui.ImageByteFormat.png);
|
||||||
}
|
}
|
||||||
_cacheLinux = CursorData(
|
_cacheLinux = CursorData(
|
||||||
peerId: this.id,
|
peerId: this.id,
|
||||||
data: data?.buffer.asUint8List(),
|
|
||||||
id: id,
|
id: id,
|
||||||
|
image: image2,
|
||||||
|
scale: 1.0,
|
||||||
|
data: data?.buffer.asUint8List(),
|
||||||
hotx: _hotx,
|
hotx: _hotx,
|
||||||
hoty: _hoty,
|
hoty: _hoty,
|
||||||
width: w,
|
width: w,
|
||||||
|
@ -154,7 +154,7 @@ class RustDeskMultiWindowManager {
|
|||||||
int? wId = findWindowByType(type);
|
int? wId = findWindowByType(type);
|
||||||
if (wId != null) {
|
if (wId != null) {
|
||||||
debugPrint("closing multi window: ${type.toString()}");
|
debugPrint("closing multi window: ${type.toString()}");
|
||||||
saveWindowPosition(type, windowId: wId);
|
await saveWindowPosition(type, windowId: wId);
|
||||||
try {
|
try {
|
||||||
final ids = await DesktopMultiWindow.getAllSubWindowIds();
|
final ids = await DesktopMultiWindow.getAllSubWindowIds();
|
||||||
if (!ids.contains(wId)) {
|
if (!ids.contains(wId)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user