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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EZ49AbZJYfm8NTp5yDPMab
This commit is contained in:
rustdesk
2026-09-23 19:52:42 +08:00
co-authored by Claude Opus 5.5
parent 85214000b5
commit 18ebd9cf17
2 changed files with 31 additions and 0 deletions
+7
View File
@@ -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) {
+24
View File
@@ -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');