From 03e041001cb60b4e54fde8cb95b0365d5cd26eaa Mon Sep 17 00:00:00 2001 From: fufesou Date: Tue, 8 Nov 2022 11:07:20 +0800 Subject: [PATCH 1/3] fix_cm: show window before set size or alignment Signed-off-by: fufesou --- flutter/lib/models/chat_model.dart | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/flutter/lib/models/chat_model.dart b/flutter/lib/models/chat_model.dart index bc6582617..18a0be279 100644 --- a/flutter/lib/models/chat_model.dart +++ b/flutter/lib/models/chat_model.dart @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_hbb/models/platform_model.dart'; import 'package:window_manager/window_manager.dart'; +import '../consts.dart'; import '../common.dart'; import '../common/widgets/overlay.dart'; import 'model.dart'; @@ -183,8 +184,11 @@ class ChatModel with ChangeNotifier { if (_isShowCMChatPage) { _isShowCMChatPage = !_isShowCMChatPage; notifyListeners(); - await windowManager.setSizeAlignment(Size(300, 400), Alignment.topRight); + await windowManager.show(); + await windowManager.setSizeAlignment( + kConnectionManagerWindowSize, Alignment.topRight); } else { + await windowManager.show(); await windowManager.setSizeAlignment(Size(600, 400), Alignment.topRight); _isShowCMChatPage = !_isShowCMChatPage; notifyListeners(); From 8984d16c75d661235aa8b568b7c95e2e2cb7ba7d Mon Sep 17 00:00:00 2001 From: fufesou Date: Tue, 8 Nov 2022 12:01:51 +0800 Subject: [PATCH 2/3] desktop get mouse control by big distance Signed-off-by: fufesou --- flutter/lib/models/input_model.dart | 19 +++++++++++++++++-- flutter/lib/models/model.dart | 4 ++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/flutter/lib/models/input_model.dart b/flutter/lib/models/input_model.dart index 280c72e79..ed7e5309a 100644 --- a/flutter/lib/models/input_model.dart +++ b/flutter/lib/models/input_model.dart @@ -42,6 +42,7 @@ class InputModel { // mouse final isPhysicalMouse = false.obs; int _lastMouseDownButtons = 0; + Offset last_mouse_pos = Offset.zero; get id => parent.target?.id ?? ""; @@ -303,6 +304,22 @@ class InputModel { } void handleMouse(Map evt) { + double x = evt['x']; + double y = max(0.0, evt['y']); + final cursorModel = parent.target!.cursorModel; + + if (!cursorModel.got_mouse_control) { + bool self_get_control = (x - last_mouse_pos.dx).abs() > 12 || + (y - last_mouse_pos.dy).abs() > 12; + if (self_get_control) { + cursorModel.got_mouse_control = true; + } else { + last_mouse_pos = ui.Offset(x, y); + return; + } + } + last_mouse_pos = ui.Offset(x, y); + var type = ''; var isMove = false; switch (evt['type']) { @@ -319,8 +336,6 @@ class InputModel { return; } evt['type'] = type; - double x = evt['x']; - double y = max(0.0, evt['y']); if (isDesktop) { y = y - stateGlobal.tabBarHeight; } diff --git a/flutter/lib/models/model.dart b/flutter/lib/models/model.dart index d8fdca2bc..41b3d056e 100644 --- a/flutter/lib/models/model.dart +++ b/flutter/lib/models/model.dart @@ -740,6 +740,7 @@ class CursorModel with ChangeNotifier { double _hoty = 0; double _displayOriginX = 0; double _displayOriginY = 0; + bool got_mouse_control = true; String id = ''; WeakReference parent; @@ -748,13 +749,11 @@ class CursorModel with ChangeNotifier { CursorData? get defaultCache => _getDefaultCache(); double get x => _x - _displayOriginX; - double get y => _y - _displayOriginY; Offset get offset => Offset(_x, _y); double get hotx => _hotx; - double get hoty => _hoty; CursorModel(this.parent); @@ -981,6 +980,7 @@ class CursorModel with ChangeNotifier { /// Update the cursor position. updateCursorPosition(Map evt, String id) async { + got_mouse_control = false; _x = double.parse(evt['x']); _y = double.parse(evt['y']); try { From 8fb664cce9900b674de701c11c0c3f328a0761e2 Mon Sep 17 00:00:00 2001 From: fufesou Date: Tue, 8 Nov 2022 13:37:08 +0800 Subject: [PATCH 3/3] desktop mouse better control Signed-off-by: fufesou --- flutter/lib/consts.dart | 8 +++++++- flutter/lib/models/input_model.dart | 10 ++++++++-- flutter/lib/models/model.dart | 11 +++++++++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/flutter/lib/consts.dart b/flutter/lib/consts.dart index ea1142033..8287378e9 100644 --- a/flutter/lib/consts.dart +++ b/flutter/lib/consts.dart @@ -21,7 +21,7 @@ const String kTabLabelSettingPage = "Settings"; const String kWindowPrefix = "wm_"; -// the executable name of the portable version +// the executable name of the portable version const String kEnvPortableExecutable = "RUSTDESK_APPNAME"; const Color kColorWarn = Color.fromARGB(255, 245, 133, 59); @@ -60,6 +60,12 @@ const kInvalidValueStr = "InvalidValueStr"; const kMobilePageConstraints = BoxConstraints(maxWidth: 600); +/// [kMouseControlDistance] indicates the distance that self-side move to get control of mouse. +const kMouseControlDistance = 12; + +/// [kMouseControlTimeoutMSec] indicates the timeout (in milliseconds) that self-side can get control of mouse. +const kMouseControlTimeoutMSec = 1000; + /// flutter/packages/flutter/lib/src/services/keyboard_key.dart -> _keyLabels /// see [LogicalKeyboardKey.keyLabel] const Map logicalKeyMap = { diff --git a/flutter/lib/models/input_model.dart b/flutter/lib/models/input_model.dart index ed7e5309a..30a01cda7 100644 --- a/flutter/lib/models/input_model.dart +++ b/flutter/lib/models/input_model.dart @@ -308,9 +308,15 @@ class InputModel { double y = max(0.0, evt['y']); final cursorModel = parent.target!.cursorModel; + if (cursorModel.is_peer_control_protected) { + last_mouse_pos = ui.Offset(x, y); + return; + } + if (!cursorModel.got_mouse_control) { - bool self_get_control = (x - last_mouse_pos.dx).abs() > 12 || - (y - last_mouse_pos.dy).abs() > 12; + bool self_get_control = + (x - last_mouse_pos.dx).abs() > kMouseControlDistance || + (y - last_mouse_pos.dy).abs() > kMouseControlDistance; if (self_get_control) { cursorModel.got_mouse_control = true; } else { diff --git a/flutter/lib/models/model.dart b/flutter/lib/models/model.dart index 41b3d056e..be97b41ff 100644 --- a/flutter/lib/models/model.dart +++ b/flutter/lib/models/model.dart @@ -741,6 +741,8 @@ class CursorModel with ChangeNotifier { double _displayOriginX = 0; double _displayOriginY = 0; bool got_mouse_control = true; + DateTime _last_peer_mouse = DateTime.now() + .subtract(Duration(milliseconds: 2 * kMouseControlTimeoutMSec)); String id = ''; WeakReference parent; @@ -756,6 +758,10 @@ class CursorModel with ChangeNotifier { double get hotx => _hotx; double get hoty => _hoty; + bool get is_peer_control_protected => + DateTime.now().difference(_last_peer_mouse).inMilliseconds < + kMouseControlTimeoutMSec; + CursorModel(this.parent); Set get cachedKeys => _cacheKeys; @@ -917,7 +923,7 @@ class CursorModel with ChangeNotifier { if (parent.target?.id != pid) return; _image = image; _images[id] = Tuple3(image, _hotx, _hoty); - await _updateCacheLinux(image, id, width, height); + await _updateCache(image, id, width, height); try { // my throw exception, because the listener maybe already dispose notifyListeners(); @@ -926,7 +932,7 @@ class CursorModel with ChangeNotifier { } } - _updateCacheLinux(ui.Image image, int id, int w, int h) async { + _updateCache(ui.Image image, int id, int w, int h) async { Uint8List? data; img2.Image? image2; if (Platform.isWindows) { @@ -981,6 +987,7 @@ class CursorModel with ChangeNotifier { /// Update the cursor position. updateCursorPosition(Map evt, String id) async { got_mouse_control = false; + _last_peer_mouse = DateTime.now(); _x = double.parse(evt['x']); _y = double.parse(evt['y']); try {