Fix predefined cursor density and scrollbar centering

This commit is contained in:
fufesou
2026-09-13 00:18:06 +08:00
parent feff308f11
commit 32e9895294
3 changed files with 55 additions and 21 deletions

View File

@@ -4,6 +4,7 @@ import 'dart:ui' as ui;
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_custom_cursor/cursor_manager.dart' show CursorManager;
import 'package:flutter_hbb/consts.dart';
import 'package:flutter_hbb/desktop/pages/remote_page.dart';
import 'package:flutter_hbb/models/input_model.dart';
@@ -167,6 +168,9 @@ void main() {
test('live DPR changes invalidate a cached native cursor',
() => _checkDprChange(view, registrations));
for (final style in [kRemoteViewStyleAdaptive, kRemoteViewStyleCustom]) {
testWidgets('$style forbidden cursor ignores remote DPR', (tester) =>
tester.runAsync(() => _checkPolicy(tester,
(style, false, 2, 0.25, 0.5), registrations, dpr: 1)));
testWidgets('Linux $style zoom follows video pixels', (tester) => tester.runAsync(
() => _checkPolicy(tester, (style, true, 2, 1.0, windows ? 1.0 : 0.5),
registrations, linux: true)));
@@ -176,9 +180,10 @@ void main() {
Future<void> _checkPolicy(
WidgetTester tester,
(String, bool, int, double, double) testCase,
List<Map<dynamic, dynamic>> registrations, {bool linux = false}) async {
List<Map<dynamic, dynamic>> registrations,
{bool linux = false, double dpr = 2}) async {
final (style, zoom, density, viewScale, expectedScale) = testCase;
tester.view.devicePixelRatio = 2;
tester.view.devicePixelRatio = dpr;
final data = await _data(density, '$style-$zoom-$density');
final originalBytes = data.data;
// A stale cached DPR must not affect the cursor when the window moves.
@@ -187,8 +192,9 @@ Future<void> _checkPolicy(
ffi.ffiModel.isPeerLinux = linux;
if (linux) ffi.ffiModel.pi.displays.add(_LinuxDisplay());
final cursor = _Cursor(data, ffi);
final keyboardEnabled = true.obs;
await tester.pumpWidget(MediaQuery(
data: const MediaQueryData(devicePixelRatio: 2),
data: MediaQueryData(devicePixelRatio: dpr),
child: MultiProvider(
providers: [
ChangeNotifierProvider<ImageModel>(create: (_) => _Image()),
@@ -200,10 +206,17 @@ Future<void> _checkPolicy(
id: 'dpi-policy',
zoomCursor: zoom.obs,
cursorOverImage: true.obs,
keyboardEnabled: true.obs,
keyboardEnabled: keyboardEnabled,
remoteCursorMoved: false.obs,
)),
));
final revoke = !zoom && style != kRemoteViewStyleOriginal;
if (revoke) {
await Future.wait(cursor.cachedKeys
.map(CursorManager.instance.ensureCursorRegistered));
keyboardEnabled.value = false;
await tester.pump();
}
await tester.pumpWidget(const SizedBox.shrink());
for (final key in cursor.cachedKeys) {
await deleteCustomCursor(key);
@@ -215,11 +228,17 @@ Future<void> _checkPolicy(
expect(data.hotx, closeTo(data.hotxOrigin * expectedScale, 1e-9));
expect(data.hoty, closeTo(data.hotyOrigin * expectedScale, 1e-9));
expect(data.data, same(originalBytes));
if (revoke) {
final args = registrations.last;
expect(args['name'], contains('_${kPreForbiddenCursorId}_'));
expect((args['width'], args['height']), (32, 32));
expect((args['hotX'], args['hotY']), (0.0, 0.0));
}
if (style == kRemoteViewStyleAdaptive && !zoom && density > 0) {
final args = registrations.single;
expect((args['width'], args['height']), (Platform.isLinux ? 36 : 18, 36));
expect((args['hotX'], args['hotY']), (8.0, 18.0));
expect(args['imagePixelRatio'], 2.0);
final args = registrations.first;
expect((args['width'], args['height']), ((Platform.isLinux ? 18 : 9) * dpr, 18 * dpr));
expect((args['hotX'], args['hotY']), (4 * dpr, 9 * dpr));
expect(args['imagePixelRatio'], dpr);
}
}