From 99ed1b729ed74b1986e8b779bf1ecf4fc35bcfc3 Mon Sep 17 00:00:00 2001 From: fufesou Date: Sat, 2 Dec 2023 21:23:19 +0800 Subject: [PATCH 1/3] Fix. Do not update cursor pos when switching display on toolbar when 'Show monitors on toolbar' Signed-off-by: fufesou --- flutter/lib/common.dart | 4 +-- .../lib/desktop/widgets/remote_toolbar.dart | 12 +++++--- flutter/lib/mobile/pages/remote_page.dart | 2 +- flutter/lib/models/model.dart | 30 ++++++++++++------- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart index d65b2dc05..4e6373434 100644 --- a/flutter/lib/common.dart +++ b/flutter/lib/common.dart @@ -2698,7 +2698,7 @@ Future> getScreenRectList() async { : await getScreenListNotWayland(); } -openMonitorInTheSameTab(int i, FFI ffi, PeerInfo pi) { +openMonitorInTheSameTab(int i, FFI ffi, PeerInfo pi, bool updateCursorPos) { final displays = i == kAllDisplayValue ? List.generate(pi.displays.length, (index) => index) : [i]; @@ -2707,7 +2707,7 @@ openMonitorInTheSameTab(int i, FFI ffi, PeerInfo pi) { sessionId: ffi.sessionId, value: Int32List.fromList(displays), ); - ffi.ffiModel.switchToNewDisplay(i, ffi.sessionId, ffi.id); + ffi.ffiModel.switchToNewDisplay(i, ffi.sessionId, ffi.id, updateCursorPos); } // Open new tab or window to show this monitor. diff --git a/flutter/lib/desktop/widgets/remote_toolbar.dart b/flutter/lib/desktop/widgets/remote_toolbar.dart index 1ae380761..5017f72b0 100644 --- a/flutter/lib/desktop/widgets/remote_toolbar.dart +++ b/flutter/lib/desktop/widgets/remote_toolbar.dart @@ -730,7 +730,7 @@ class _MonitorMenu extends StatelessWidget { ], ), ), - onPressed: () => onPressed(i, pi), + onPressed: () => onPressed(i, pi, isMulti), ); }); @@ -810,14 +810,18 @@ class _MonitorMenu extends StatelessWidget { ); } - onPressed(int i, PeerInfo pi) { - _menuDismissCallback(ffi); + onPressed(int i, PeerInfo pi, bool isMulti) { + if (!isMulti) { + // If show monitors in toolbar(`buildMultiMonitorMenu()`), then the menu will dismiss automatically. + _menuDismissCallback(ffi); + } RxInt display = CurrentDisplayState.find(id); if (display.value != i) { if (isChooseDisplayToOpenInNewWindow(pi, ffi.sessionId)) { openMonitorInNewTabOrWindow(i, ffi.id, pi); } else { - openMonitorInTheSameTab(i, ffi, pi); + final updateCursorPos = !isMulti; + openMonitorInTheSameTab(i, ffi, pi, updateCursorPos); } } } diff --git a/flutter/lib/mobile/pages/remote_page.dart b/flutter/lib/mobile/pages/remote_page.dart index 1e36e49b2..cc097f22e 100644 --- a/flutter/lib/mobile/pages/remote_page.dart +++ b/flutter/lib/mobile/pages/remote_page.dart @@ -787,7 +787,7 @@ void showOptions( children.add(InkWell( onTap: () { if (i == cur) return; - openMonitorInTheSameTab(i, gFFI, pi); + openMonitorInTheSameTab(i, gFFI, pi, false); gFFI.dialogManager.dismissAll(); }, child: Ink( diff --git a/flutter/lib/models/model.dart b/flutter/lib/models/model.dart index 5d1cbbd62..6cb553cda 100644 --- a/flutter/lib/models/model.dart +++ b/flutter/lib/models/model.dart @@ -415,18 +415,21 @@ class FfiModel with ChangeNotifier { } } - updateCurDisplay(SessionID sessionId) { + updateCurDisplay(SessionID sessionId, {updateCursorPos = true}) { final newRect = displaysRect(); if (newRect == null) { return; } if (newRect != _rect) { - if (newRect.left != _rect?.left || newRect.top != _rect?.top) { - parent.target?.cursorModel - .updateDisplayOrigin(newRect.left, newRect.top); + if (updateCursorPos) { + if (newRect.left != _rect?.left || newRect.top != _rect?.top) { + parent.target?.cursorModel + .updateDisplayOrigin(newRect.left, newRect.top); + } } _rect = newRect; - parent.target?.canvasModel.updateViewStyle(); + parent.target?.canvasModel + .updateViewStyle(refreshMousePos: updateCursorPos); _updateSessionWidthHeight(sessionId); } } @@ -912,7 +915,7 @@ class FfiModel with ChangeNotifier { if (_pi.isSupportMultiUiSession) { // If the peer supports multi-ui-session, no switch display message will be send back. // We need to update the display manually. - switchToNewDisplay(newDisplay, sessionId, peerId); + switchToNewDisplay(newDisplay, sessionId, peerId, true); } } else { msgBox(sessionId, 'nocancel-error', 'Prompt', 'No Displays', '', @@ -952,12 +955,17 @@ class FfiModel with ChangeNotifier { } // Directly switch to the new display without waiting for the response. - switchToNewDisplay(int display, SessionID sessionId, String peerId) { + switchToNewDisplay( + int display, + SessionID sessionId, + String peerId, + bool updateCursorPos, + ) { // VideoHandler creation is upon when video frames are received, so either caching commands(don't know next width/height) or stopping recording when switching displays. parent.target?.recordingModel.onClose(); // no need to wait for the response pi.currentDisplay = display; - updateCurDisplay(sessionId); + updateCurDisplay(sessionId, updateCursorPos: updateCursorPos); try { CurrentDisplayState.find(peerId).value = display; } catch (e) { @@ -1242,7 +1250,7 @@ class CanvasModel with ChangeNotifier { ? windowBorderWidth + kDragToResizeAreaPadding.bottom : 0; - updateViewStyle() async { + updateViewStyle({refreshMousePos = true}) async { Size getSize() { final size = MediaQueryData.fromWindow(ui.window).size; // If minimized, w or h may be negative here. @@ -1283,7 +1291,9 @@ class CanvasModel with ChangeNotifier { _y = (size.height - displayHeight * _scale) / 2; _imageOverflow.value = _x < 0 || y < 0; notifyListeners(); - parent.target?.inputModel.refreshMousePos(); + if (refreshMousePos) { + parent.target?.inputModel.refreshMousePos(); + } } updateScrollStyle() async { From 3958090e0fbc0069b95682d863b1ef1843d70dc2 Mon Sep 17 00:00:00 2001 From: fufesou Date: Sat, 2 Dec 2023 21:52:54 +0800 Subject: [PATCH 2/3] Fix, wrong argument of mobile updating cursor position Signed-off-by: fufesou --- flutter/lib/mobile/pages/remote_page.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flutter/lib/mobile/pages/remote_page.dart b/flutter/lib/mobile/pages/remote_page.dart index cc097f22e..459d66feb 100644 --- a/flutter/lib/mobile/pages/remote_page.dart +++ b/flutter/lib/mobile/pages/remote_page.dart @@ -787,7 +787,7 @@ void showOptions( children.add(InkWell( onTap: () { if (i == cur) return; - openMonitorInTheSameTab(i, gFFI, pi, false); + openMonitorInTheSameTab(i, gFFI, pi, true); gFFI.dialogManager.dismissAll(); }, child: Ink( From 570ce7d28debc4b517edb617ac0a2cfa30f2df79 Mon Sep 17 00:00:00 2001 From: fufesou Date: Sat, 2 Dec 2023 22:01:05 +0800 Subject: [PATCH 3/3] Refactor, optional parameter 'updateCursorPos' Signed-off-by: fufesou --- flutter/lib/common.dart | 4 ++-- flutter/lib/desktop/widgets/remote_toolbar.dart | 3 +-- flutter/lib/mobile/pages/remote_page.dart | 2 +- flutter/lib/models/model.dart | 10 +++------- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart index 4e6373434..3670bbd00 100644 --- a/flutter/lib/common.dart +++ b/flutter/lib/common.dart @@ -2698,7 +2698,7 @@ Future> getScreenRectList() async { : await getScreenListNotWayland(); } -openMonitorInTheSameTab(int i, FFI ffi, PeerInfo pi, bool updateCursorPos) { +openMonitorInTheSameTab(int i, FFI ffi, PeerInfo pi, {bool updateCursorPos = true}) { final displays = i == kAllDisplayValue ? List.generate(pi.displays.length, (index) => index) : [i]; @@ -2707,7 +2707,7 @@ openMonitorInTheSameTab(int i, FFI ffi, PeerInfo pi, bool updateCursorPos) { sessionId: ffi.sessionId, value: Int32List.fromList(displays), ); - ffi.ffiModel.switchToNewDisplay(i, ffi.sessionId, ffi.id, updateCursorPos); + ffi.ffiModel.switchToNewDisplay(i, ffi.sessionId, ffi.id, updateCursorPos: updateCursorPos); } // Open new tab or window to show this monitor. diff --git a/flutter/lib/desktop/widgets/remote_toolbar.dart b/flutter/lib/desktop/widgets/remote_toolbar.dart index 5017f72b0..08d89f51a 100644 --- a/flutter/lib/desktop/widgets/remote_toolbar.dart +++ b/flutter/lib/desktop/widgets/remote_toolbar.dart @@ -820,8 +820,7 @@ class _MonitorMenu extends StatelessWidget { if (isChooseDisplayToOpenInNewWindow(pi, ffi.sessionId)) { openMonitorInNewTabOrWindow(i, ffi.id, pi); } else { - final updateCursorPos = !isMulti; - openMonitorInTheSameTab(i, ffi, pi, updateCursorPos); + openMonitorInTheSameTab(i, ffi, pi, updateCursorPos: !isMulti); } } } diff --git a/flutter/lib/mobile/pages/remote_page.dart b/flutter/lib/mobile/pages/remote_page.dart index 459d66feb..1e36e49b2 100644 --- a/flutter/lib/mobile/pages/remote_page.dart +++ b/flutter/lib/mobile/pages/remote_page.dart @@ -787,7 +787,7 @@ void showOptions( children.add(InkWell( onTap: () { if (i == cur) return; - openMonitorInTheSameTab(i, gFFI, pi, true); + openMonitorInTheSameTab(i, gFFI, pi); gFFI.dialogManager.dismissAll(); }, child: Ink( diff --git a/flutter/lib/models/model.dart b/flutter/lib/models/model.dart index 6cb553cda..d7e6265fa 100644 --- a/flutter/lib/models/model.dart +++ b/flutter/lib/models/model.dart @@ -915,7 +915,7 @@ class FfiModel with ChangeNotifier { if (_pi.isSupportMultiUiSession) { // If the peer supports multi-ui-session, no switch display message will be send back. // We need to update the display manually. - switchToNewDisplay(newDisplay, sessionId, peerId, true); + switchToNewDisplay(newDisplay, sessionId, peerId); } } else { msgBox(sessionId, 'nocancel-error', 'Prompt', 'No Displays', '', @@ -955,12 +955,8 @@ class FfiModel with ChangeNotifier { } // Directly switch to the new display without waiting for the response. - switchToNewDisplay( - int display, - SessionID sessionId, - String peerId, - bool updateCursorPos, - ) { + switchToNewDisplay(int display, SessionID sessionId, String peerId, + {bool updateCursorPos = true}) { // VideoHandler creation is upon when video frames are received, so either caching commands(don't know next width/height) or stopping recording when switching displays. parent.target?.recordingModel.onClose(); // no need to wait for the response