mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-09-19 10:51:01 +03:00
fix: preserve unzoomed cursor size for hosts without density
This commit is contained in:
@@ -1129,8 +1129,9 @@ class _ImagePaintState extends State<ImagePaint> {
|
|||||||
// buildCursorOfCache() converts it back to logical scale for the plugin.
|
// buildCursorOfCache() converts it back to logical scale for the plugin.
|
||||||
return (isWindows ? dpr : 1.0) / peerDpr;
|
return (isWindows ? dpr : 1.0) / peerDpr;
|
||||||
}
|
}
|
||||||
// Density metadata is optional. Keep the legacy path for hosts that
|
// Without density, keep the legacy unzoomed scale of 1. Dividing by
|
||||||
// omit it so capture-backend upgrades are not a client prerequisite.
|
// controller DPR would also trigger the legacy short-edge minimum,
|
||||||
|
// enlarging thin artwork that previously needed no resizing.
|
||||||
final imageScale = isViewScaled() && zoomCursor.isTrue
|
final imageScale = isViewScaled() && zoomCursor.isTrue
|
||||||
? _cursorImageScale(widget.ffi, cursor, useLocalPointer: true)
|
? _cursorImageScale(widget.ffi, cursor, useLocalPointer: true)
|
||||||
: s;
|
: s;
|
||||||
@@ -1143,12 +1144,6 @@ class _ImagePaintState extends State<ImagePaint> {
|
|||||||
} else {
|
} else {
|
||||||
if (zoomCursor.value || isViewOriginal()) {
|
if (zoomCursor.value || isViewOriginal()) {
|
||||||
cursorScale = imageScale;
|
cursorScale = imageScale;
|
||||||
} else if (!isWeb) {
|
|
||||||
// NSCursor and GdkCursor treat the bitmap size as logical
|
|
||||||
// pixels, so an unzoomed cursor must be shrunk by the DPR to
|
|
||||||
// keep 1 remote px == 1 physical px, the size Original view
|
|
||||||
// already renders it at.
|
|
||||||
cursorScale = 1.0 / dpr;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cursorScale;
|
return cursorScale;
|
||||||
|
|||||||
@@ -101,6 +101,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
tearDown(() =>
|
tearDown(() =>
|
||||||
binding.defaultBinaryMessenger.setMockMethodCallHandler(channel, null));
|
binding.defaultBinaryMessenger.setMockMethodCallHandler(channel, null));
|
||||||
|
_legacySizingTests(registrations);
|
||||||
for (final style in [kRemoteViewStyleAdaptive, kRemoteViewStyleCustom]) {
|
for (final style in [kRemoteViewStyleAdaptive, kRemoteViewStyleCustom]) {
|
||||||
for (final density in ['0', '1', '2', '1e-300', '0.001']) {
|
for (final density in ['0', '1', '2', '1e-300', '0.001']) {
|
||||||
testWidgets(
|
testWidgets(
|
||||||
@@ -111,6 +112,28 @@ void main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _legacySizingTests(List<Map<dynamic, dynamic>> registrations) {
|
||||||
|
for (final style in [kRemoteViewStyleAdaptive, kRemoteViewStyleCustom]) {
|
||||||
|
for (final density in [null, '0']) {
|
||||||
|
for (final (width, height, dpr) in [
|
||||||
|
(4, 32, 1.0),
|
||||||
|
(4, 32, 2.0),
|
||||||
|
(9, 18, 1.0),
|
||||||
|
(9, 18, 2.0),
|
||||||
|
(32, 32, 1.0),
|
||||||
|
(32, 32, 2.0),
|
||||||
|
]) {
|
||||||
|
testWidgets(
|
||||||
|
'legacy $style density=$density ${width}x$height DPR=$dpr',
|
||||||
|
(tester) => tester.runAsync(() => checkDensity(
|
||||||
|
tester, (style, density), registrations,
|
||||||
|
sourceSize: Size(width.toDouble(), height.toDouble()),
|
||||||
|
dpr: dpr)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _rasterBoundsTests() {
|
void _rasterBoundsTests() {
|
||||||
for (final (width, height, scale, legacy, rasterScale) in [
|
for (final (width, height, scale, legacy, rasterScale) in [
|
||||||
(32, 32, 1e300, false, 1.0),
|
(32, 32, 1e300, false, 1.0),
|
||||||
@@ -146,13 +169,14 @@ void _rasterBoundsTests() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> checkDensity(WidgetTester tester, (String, String) input,
|
Future<void> checkDensity(WidgetTester tester, (String, String?) input,
|
||||||
List<Map<dynamic, dynamic>> registrations) async {
|
List<Map<dynamic, dynamic>> registrations,
|
||||||
|
{Size sourceSize = const Size(32, 32), double dpr = 1}) async {
|
||||||
final (style, density) = input;
|
final (style, density) = input;
|
||||||
final id = '$style-$density';
|
final id = '$style-$density';
|
||||||
tester.view.devicePixelRatio = 1;
|
tester.view.devicePixelRatio = dpr;
|
||||||
addTearDown(tester.view.resetDevicePixelRatio);
|
addTearDown(tester.view.resetDevicePixelRatio);
|
||||||
final canvas = _Canvas(1, style: style, scale: 0.5);
|
final canvas = _Canvas(dpr, style: style, scale: 0.5);
|
||||||
final ffi = _FFI(canvas)..ffiModel.pi.platform = kPeerPlatformMacOS;
|
final ffi = _FFI(canvas)..ffiModel.pi.platform = kPeerPlatformMacOS;
|
||||||
final cursor = CursorModel(WeakReference(ffi))..id = id;
|
final cursor = CursorModel(WeakReference(ffi))..id = id;
|
||||||
addTearDown(() async {
|
addTearDown(() async {
|
||||||
@@ -164,20 +188,35 @@ Future<void> checkDensity(WidgetTester tester, (String, String) input,
|
|||||||
cursor.dispose();
|
cursor.dispose();
|
||||||
canvas.dispose();
|
canvas.dispose();
|
||||||
});
|
});
|
||||||
await cursor.updateCursorData(_cursorEvent(id, density));
|
await cursor.updateCursorData(_cursorEvent(id, density, size: sourceSize));
|
||||||
final rejected = density == '1e-300' || density == '0.001';
|
final rejected = density == '1e-300' || density == '0.001';
|
||||||
if (rejected) {
|
if (rejected) {
|
||||||
expect(cursor.cache, isNull,
|
expect(cursor.cache, isNull,
|
||||||
reason: 'Reject density before publishing a cursor');
|
reason: 'Reject density before publishing a cursor');
|
||||||
await cursor.updateCursorData(_cursorEvent(id, '2'));
|
await cursor.updateCursorData(_cursorEvent(id, '2'));
|
||||||
}
|
}
|
||||||
expect(cursor.cache!.pixelRatio, rejected ? 2 : double.parse(density));
|
expect(cursor.cache!.pixelRatio, rejected ? 2 : double.parse(density ?? '0'));
|
||||||
|
await _paintCursor(tester, ffi, cursor);
|
||||||
|
expect(tester.takeException(), isNull);
|
||||||
|
for (final key in cursor.cachedKeys) {
|
||||||
|
await CursorManager.instance.ensureCursorRegistered(key);
|
||||||
|
}
|
||||||
|
expect(registrations, hasLength(1));
|
||||||
|
await tester.pumpWidget(const SizedBox.shrink());
|
||||||
|
if (density == null || density == '0') {
|
||||||
|
expect(cursor.cache!.scale, 1.0);
|
||||||
|
_expectLegacyRaster(registrations.single, sourceSize, dpr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _paintCursor(
|
||||||
|
WidgetTester tester, _FFI ffi, CursorModel cursor) async {
|
||||||
await tester.pumpWidget(MediaQuery(
|
await tester.pumpWidget(MediaQuery(
|
||||||
data: const MediaQueryData(devicePixelRatio: 1),
|
data: MediaQueryData(devicePixelRatio: ffi.canvasModel.devicePixelRatio),
|
||||||
child: MultiProvider(
|
child: MultiProvider(
|
||||||
providers: [
|
providers: [
|
||||||
ChangeNotifierProvider<ImageModel>(create: (_) => _Image()),
|
ChangeNotifierProvider<ImageModel>(create: (_) => _Image()),
|
||||||
ChangeNotifierProvider<CanvasModel>.value(value: canvas),
|
ChangeNotifierProvider<CanvasModel>.value(value: ffi.canvasModel),
|
||||||
ChangeNotifierProvider<CursorModel>.value(value: cursor),
|
ChangeNotifierProvider<CursorModel>.value(value: cursor),
|
||||||
],
|
],
|
||||||
child: ImagePaint(
|
child: ImagePaint(
|
||||||
@@ -188,20 +227,41 @@ Future<void> checkDensity(WidgetTester tester, (String, String) input,
|
|||||||
keyboardEnabled: true.obs,
|
keyboardEnabled: true.obs,
|
||||||
remoteCursorMoved: false.obs)),
|
remoteCursorMoved: false.obs)),
|
||||||
));
|
));
|
||||||
expect(tester.takeException(), isNull);
|
|
||||||
for (final key in cursor.cachedKeys) {
|
|
||||||
await CursorManager.instance.ensureCursorRegistered(key);
|
|
||||||
}
|
|
||||||
expect(registrations, hasLength(1));
|
|
||||||
await tester.pumpWidget(const SizedBox.shrink());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, String> _cursorEvent(String id, String density) => {
|
void _expectLegacyRaster(Map<dynamic, dynamic> args, Size size, double dpr) {
|
||||||
|
// Base unzoomed sizing is logical on macOS/GTK, physical on Windows.
|
||||||
|
final rasterScale = common.isWindows ? 1.0 : dpr;
|
||||||
|
final width = (size.width * rasterScale).toInt();
|
||||||
|
final height = (size.height * rasterScale).toInt();
|
||||||
|
final bufferWidth = common.isLinux ? size.longestSide * rasterScale : width;
|
||||||
|
expect((args['width'], args['height']), (bufferWidth, height));
|
||||||
|
expect((args['hotX'], args['hotY']),
|
||||||
|
((size.width ~/ 2) * rasterScale, (size.height ~/ 2) * rasterScale));
|
||||||
|
expect(args['imagePixelRatio'], dpr);
|
||||||
|
final bytes = args['buffer'] as Uint8List;
|
||||||
|
final decoded = common.isWindows
|
||||||
|
? img.Image.fromBytes(
|
||||||
|
width: width,
|
||||||
|
height: height,
|
||||||
|
bytes: bytes.buffer,
|
||||||
|
bytesOffset: bytes.offsetInBytes,
|
||||||
|
order: img.ChannelOrder.bgra)
|
||||||
|
: img.decodePng(bytes)!;
|
||||||
|
expect((decoded.width, decoded.height), (bufferWidth, height));
|
||||||
|
expect(decoded.getPixel(width - 1, height - 1).a, 255);
|
||||||
|
if (bufferWidth > width) expect(decoded.getPixel(width, 0).a, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, String> _cursorEvent(String id, String? density,
|
||||||
|
{Size size = const Size(32, 32)}) =>
|
||||||
|
{
|
||||||
'id': id,
|
'id': id,
|
||||||
'width': '32',
|
'width': '${size.width.toInt()}',
|
||||||
'height': '32',
|
'height': '${size.height.toInt()}',
|
||||||
'hotx': '8',
|
'hotx': '${size.width ~/ 2}',
|
||||||
'hoty': '12',
|
'hoty': '${size.height ~/ 2}',
|
||||||
'scale': density,
|
if (density != null) 'scale': density,
|
||||||
'colors': jsonEncode(List<int>.filled(32 * 32 * 4, 255)),
|
'colors': jsonEncode(
|
||||||
|
List<int>.filled((size.width * size.height * 4).toInt(), 255)),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -151,8 +151,8 @@ void main() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
for (final testCase in [
|
for (final testCase in [
|
||||||
(kRemoteViewStyleAdaptive, false, 0, 0.25, windows ? 1.0 : 4 / 3),
|
(kRemoteViewStyleAdaptive, false, 0, 0.25, 1.0),
|
||||||
(kRemoteViewStyleCustom, false, 0, 0.25, windows ? 1.0 : 4 / 3),
|
(kRemoteViewStyleCustom, false, 0, 0.25, 1.0),
|
||||||
(kRemoteViewStyleAdaptive, false, 1, 0.25, windows ? 2.0 : 1.0),
|
(kRemoteViewStyleAdaptive, false, 1, 0.25, windows ? 2.0 : 1.0),
|
||||||
(kRemoteViewStyleAdaptive, false, 2, 0.25, windows ? 1.0 : 0.5),
|
(kRemoteViewStyleAdaptive, false, 2, 0.25, windows ? 1.0 : 0.5),
|
||||||
(kRemoteViewStyleCustom, false, 2, 0.25, windows ? 1.0 : 0.5),
|
(kRemoteViewStyleCustom, false, 2, 0.25, windows ? 1.0 : 0.5),
|
||||||
@@ -231,7 +231,8 @@ Future<void> _checkPolicy(
|
|||||||
if (revoke) {
|
if (revoke) {
|
||||||
final args = registrations.last;
|
final args = registrations.last;
|
||||||
expect(args['name'], contains('_${kPreForbiddenCursorId}_'));
|
expect(args['name'], contains('_${kPreForbiddenCursorId}_'));
|
||||||
expect((args['width'], args['height']), (32, 32));
|
final rasterSize = 32 * (Platform.isWindows ? 1 : dpr);
|
||||||
|
expect((args['width'], args['height']), (rasterSize, rasterSize));
|
||||||
expect((args['hotX'], args['hotY']), (0.0, 0.0));
|
expect((args['hotX'], args['hotY']), (0.0, 0.0));
|
||||||
}
|
}
|
||||||
if (style == kRemoteViewStyleAdaptive && !zoom && density > 0) {
|
if (style == kRemoteViewStyleAdaptive && !zoom && density > 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user