From daafa093181e1bd5fe8cdee0947d3b57482929e2 Mon Sep 17 00:00:00 2001 From: fufesou Date: Sat, 12 Sep 2026 03:33:38 +0800 Subject: [PATCH] fix(cursor): keep the Windows minimum in logical pixels --- flutter/lib/native/custom_cursor.dart | 7 ++++++- flutter/test/cursor_dpi_policy_test.dart | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/flutter/lib/native/custom_cursor.dart b/flutter/lib/native/custom_cursor.dart index b92c81590..394bacd16 100644 --- a/flutter/lib/native/custom_cursor.dart +++ b/flutter/lib/native/custom_cursor.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:math' as math; import 'package:flutter_custom_cursor/cursor_manager.dart' as custom_cursor_manager; @@ -29,7 +30,11 @@ MouseCursor buildCursorOfCache( // the proportions of thin remote cursors when normalizing their DPI. final legacyMinimum = cache.pixelRatio == 0 || cursor.parent.target?.canvasModel.viewStyle.style == kRemoteViewStyleOriginal; - final key = '${cache.updateGetKey(scale, resizeImage: false, useLegacyMinimum: legacyMinimum)}_$dpr'; + // The minimum is logical, while Windows callers pass a physical scale. + final effectiveScale = !legacyMinimum && isWindows + ? math.max(scale, kMinCursorSize * dpr / math.max(cache.width, cache.height)) + : scale; + final key = '${cache.updateGetKey(effectiveScale, resizeImage: false, useLegacyMinimum: legacyMinimum)}_$dpr'; if (!cursor.cachedKeys.contains(key)) { debugPrint( "Register custom cursor with key $key (${cache.hotx},${cache.hoty})"); diff --git a/flutter/test/cursor_dpi_policy_test.dart b/flutter/test/cursor_dpi_policy_test.dart index d70664814..ce1869840 100644 --- a/flutter/test/cursor_dpi_policy_test.dart +++ b/flutter/test/cursor_dpi_policy_test.dart @@ -123,8 +123,8 @@ void main() { (kRemoteViewStyleAdaptive, false, 1, 0.25, Platform.isWindows ? 2.0 : 1.0), (kRemoteViewStyleAdaptive, false, 2, 0.25, Platform.isWindows ? 1.0 : 0.5), (kRemoteViewStyleCustom, false, 2, 0.25, Platform.isWindows ? 1.0 : 0.5), - (kRemoteViewStyleAdaptive, true, 2, 0.25, 1 / 3), - (kRemoteViewStyleCustom, true, 2, 0.25, 1 / 3), + (kRemoteViewStyleAdaptive, true, 2, 0.25, Platform.isWindows ? 2 / 3 : 1 / 3), + (kRemoteViewStyleCustom, true, 2, 0.25, Platform.isWindows ? 2 / 3 : 1 / 3), (kRemoteViewStyleOriginal, false, 2, 0.5, Platform.isWindows ? 1.0 : 2 / 3), ]) { testWidgets(