desktop mouse better control

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2022-11-08 13:37:08 +08:00
parent 8984d16c75
commit 8fb664cce9
3 changed files with 24 additions and 5 deletions

View File

@ -60,6 +60,12 @@ const kInvalidValueStr = "InvalidValueStr";
const kMobilePageConstraints = BoxConstraints(maxWidth: 600); 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 /// flutter/packages/flutter/lib/src/services/keyboard_key.dart -> _keyLabels
/// see [LogicalKeyboardKey.keyLabel] /// see [LogicalKeyboardKey.keyLabel]
const Map<int, String> logicalKeyMap = <int, String>{ const Map<int, String> logicalKeyMap = <int, String>{

View File

@ -308,9 +308,15 @@ class InputModel {
double y = max(0.0, evt['y']); double y = max(0.0, evt['y']);
final cursorModel = parent.target!.cursorModel; final cursorModel = parent.target!.cursorModel;
if (cursorModel.is_peer_control_protected) {
last_mouse_pos = ui.Offset(x, y);
return;
}
if (!cursorModel.got_mouse_control) { if (!cursorModel.got_mouse_control) {
bool self_get_control = (x - last_mouse_pos.dx).abs() > 12 || bool self_get_control =
(y - last_mouse_pos.dy).abs() > 12; (x - last_mouse_pos.dx).abs() > kMouseControlDistance ||
(y - last_mouse_pos.dy).abs() > kMouseControlDistance;
if (self_get_control) { if (self_get_control) {
cursorModel.got_mouse_control = true; cursorModel.got_mouse_control = true;
} else { } else {

View File

@ -741,6 +741,8 @@ class CursorModel with ChangeNotifier {
double _displayOriginX = 0; double _displayOriginX = 0;
double _displayOriginY = 0; double _displayOriginY = 0;
bool got_mouse_control = true; bool got_mouse_control = true;
DateTime _last_peer_mouse = DateTime.now()
.subtract(Duration(milliseconds: 2 * kMouseControlTimeoutMSec));
String id = ''; String id = '';
WeakReference<FFI> parent; WeakReference<FFI> parent;
@ -756,6 +758,10 @@ class CursorModel with ChangeNotifier {
double get hotx => _hotx; double get hotx => _hotx;
double get hoty => _hoty; double get hoty => _hoty;
bool get is_peer_control_protected =>
DateTime.now().difference(_last_peer_mouse).inMilliseconds <
kMouseControlTimeoutMSec;
CursorModel(this.parent); CursorModel(this.parent);
Set<String> get cachedKeys => _cacheKeys; Set<String> get cachedKeys => _cacheKeys;
@ -917,7 +923,7 @@ class CursorModel with ChangeNotifier {
if (parent.target?.id != pid) return; if (parent.target?.id != pid) return;
_image = image; _image = image;
_images[id] = Tuple3(image, _hotx, _hoty); _images[id] = Tuple3(image, _hotx, _hoty);
await _updateCacheLinux(image, id, width, height); await _updateCache(image, id, width, height);
try { try {
// my throw exception, because the listener maybe already dispose // my throw exception, because the listener maybe already dispose
notifyListeners(); 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; Uint8List? data;
img2.Image? image2; img2.Image? image2;
if (Platform.isWindows) { if (Platform.isWindows) {
@ -981,6 +987,7 @@ class CursorModel with ChangeNotifier {
/// Update the cursor position. /// Update the cursor position.
updateCursorPosition(Map<String, dynamic> evt, String id) async { updateCursorPosition(Map<String, dynamic> evt, String id) async {
got_mouse_control = false; got_mouse_control = false;
_last_peer_mouse = DateTime.now();
_x = double.parse(evt['x']); _x = double.parse(evt['x']);
_y = double.parse(evt['y']); _y = double.parse(evt['y']);
try { try {