From 18ebd9cf174770cda251d9b528d97be9b02f5884 Mon Sep 17 00:00:00 2001 From: rustdesk Date: Wed, 23 Sep 2026 12:24:56 +0800 Subject: [PATCH] cursor: keep a native cursor for the shape in use alone Every shape the peer showed kept a native cursor for the session, each a raster the size of the shape as displayed. A shape switched away from now gives its native cursor up the way a replaced raster does: deleted the next time a cursor already registered is built, taken back if the shape returns first. A shape shown again after that is rebuilt from the compressed copy the core keeps. The predefined cursors are not the peer's shapes and stay registered. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EZ49AbZJYfm8NTp5yDPMab --- flutter/lib/models/model.dart | 7 +++++++ flutter/test/cursor_replay_test.dart | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/flutter/lib/models/model.dart b/flutter/lib/models/model.dart index e2f51d8bd..344c07d06 100644 --- a/flutter/lib/models/model.dart +++ b/flutter/lib/models/model.dart @@ -3688,6 +3688,13 @@ class CursorModel with ChangeNotifier { cache.releasePixels(); } } + // Only the shape in use keeps a native cursor too; the core rebuilds the others. The + // predefined cursors are not the peer's shapes and stay. + _nativeKeys.removeWhere((id, key) { + if (id == _id || !_cacheMap.containsKey(id)) return false; + if (_cacheKeys.remove(key)) _replacedKeys.add(key); + return true; + }); final tmp = _images[_id]; _image = tmp?.item1; if (tmp != null) { diff --git a/flutter/test/cursor_replay_test.dart b/flutter/test/cursor_replay_test.dart index 44ee3073d..81ed31648 100644 --- a/flutter/test/cursor_replay_test.dart +++ b/flutter/test/cursor_replay_test.dart @@ -123,6 +123,30 @@ void main() { expect(ffi.cursor.fetched, isEmpty, reason: 'nothing had to be decoded'); }); + test('only the shape in use keeps a native cursor', () async { + final cursor = ffi.cursorModel; + await _feed(ffi, '1'); + buildCursorOfCache(cursor, 1.0, cursor.cache); + await _settle(); + final first = registered.single; + await _feed(ffi, '2'); + buildCursorOfCache(cursor, 1.0, cursor.cache); + await _settle(); + buildCursorOfCache(cursor, 1.0, cursor.cache); + await _settle(); + expect(deleted, [first], reason: 'gone once the next one was shown'); + expect(cursor.cachedKeys, {registered.last}); + + _select(ffi, '1'); + expect(buildCursorOfCache(cursor, 1.0, cursor.cache), MouseCursor.defer); + await _settle(); + expect(ffi.cursor.fetched, ['1'], reason: 'rebuilt from the core'); + buildCursorOfCache(cursor, 1.0, cursor.cache); + await _settle(); + expect(registered.length, 3); + expect(cursor.cachedKeys, {registered.last}); + }); + test('a shape painted again is decoded again from the core', () async { await _feed(ffi, '1', size: 16); await _feed(ffi, '2');