mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-05-11 10:26:19 +02:00
fix: mobile input, touch mode, in display (#9827)
Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
parent
a4bd23c9de
commit
5cfd1701fb
2 changed files with 120 additions and 10 deletions
|
@ -9,6 +9,7 @@ import 'package:desktop_multi_window/desktop_multi_window.dart';
|
|||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_hbb/common/widgets/peers_view.dart';
|
||||
import 'package:flutter_hbb/consts.dart';
|
||||
import 'package:flutter_hbb/models/ab_model.dart';
|
||||
|
@ -2040,16 +2041,56 @@ class CursorModel with ChangeNotifier {
|
|||
return false;
|
||||
}
|
||||
_lastIsBlocked = false;
|
||||
moveLocal(x, y, adjust: parent.target?.canvasModel.getAdjustY() ?? 0);
|
||||
if (!_moveLocalIfInRemoteRect(x, y)) {
|
||||
return false;
|
||||
}
|
||||
parent.target?.inputModel.moveMouse(_x, _y);
|
||||
return true;
|
||||
}
|
||||
|
||||
moveLocal(double x, double y, {double adjust = 0}) {
|
||||
bool isInRemoteRect(Offset offset) {
|
||||
return getRemotePosInRect(offset) != null;
|
||||
}
|
||||
|
||||
Offset? getRemotePosInRect(Offset offset) {
|
||||
final adjust = parent.target?.canvasModel.getAdjustY() ?? 0;
|
||||
final newPos = _getNewPos(offset.dx, offset.dy, adjust);
|
||||
final visibleRect = getVisibleRect();
|
||||
if (!isPointInRect(newPos, visibleRect)) {
|
||||
return null;
|
||||
}
|
||||
final rect = parent.target?.ffiModel.rect;
|
||||
if (rect != null) {
|
||||
if (!isPointInRect(newPos, rect)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return newPos;
|
||||
}
|
||||
|
||||
Offset _getNewPos(double x, double y, double adjust) {
|
||||
final xoffset = parent.target?.canvasModel.x ?? 0;
|
||||
final yoffset = parent.target?.canvasModel.y ?? 0;
|
||||
_x = (x - xoffset) / scale + _displayOriginX;
|
||||
_y = (y - yoffset - adjust) / scale + _displayOriginY;
|
||||
final newX = (x - xoffset) / scale + _displayOriginX;
|
||||
final newY = (y - yoffset - adjust) / scale + _displayOriginY;
|
||||
return Offset(newX, newY);
|
||||
}
|
||||
|
||||
bool _moveLocalIfInRemoteRect(double x, double y) {
|
||||
final newPos = getRemotePosInRect(Offset(x, y));
|
||||
if (newPos == null) {
|
||||
return false;
|
||||
}
|
||||
_x = newPos.dx;
|
||||
_y = newPos.dy;
|
||||
notifyListeners();
|
||||
return true;
|
||||
}
|
||||
|
||||
moveLocal(double x, double y, {double adjust = 0}) {
|
||||
final newPos = _getNewPos(x, y, adjust);
|
||||
_x = newPos.dx;
|
||||
_y = newPos.dy;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
|
@ -2182,9 +2223,44 @@ class CursorModel with ChangeNotifier {
|
|||
}
|
||||
}
|
||||
if (!isMoved) {
|
||||
final rect = parent.target?.ffiModel.rect;
|
||||
if (rect == null) {
|
||||
// unreachable
|
||||
return;
|
||||
}
|
||||
|
||||
Offset? movementInRect(double x, double y, Rect r) {
|
||||
final isXInRect = x >= r.left && x <= r.right;
|
||||
final isYInRect = y >= r.top && y <= r.bottom;
|
||||
if (!(isXInRect || isYInRect)) {
|
||||
return null;
|
||||
}
|
||||
if (x < r.left) {
|
||||
x = r.left;
|
||||
} else if (x > r.right) {
|
||||
x = r.right;
|
||||
}
|
||||
if (y < r.top) {
|
||||
y = r.top;
|
||||
} else if (y > r.bottom) {
|
||||
y = r.bottom;
|
||||
}
|
||||
return Offset(x, y);
|
||||
}
|
||||
|
||||
final scale = parent.target?.canvasModel.scale ?? 1.0;
|
||||
_x += delta.dx / scale;
|
||||
_y += delta.dy / scale;
|
||||
var movement =
|
||||
movementInRect(_x + delta.dx / scale, _y + delta.dy / scale, rect);
|
||||
if (movement == null) {
|
||||
return;
|
||||
}
|
||||
movement = movementInRect(movement.dx, movement.dy, getVisibleRect());
|
||||
if (movement == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
_x = movement.dx;
|
||||
_y = movement.dy;
|
||||
parent.target?.inputModel.moveMouse(_x, _y);
|
||||
}
|
||||
notifyListeners();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue