fix: touch input, ensure message orders (#9855)

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou
2024-11-07 21:23:41 +08:00
committed by GitHub
parent 69277dd16b
commit d0ef52e418
3 changed files with 70 additions and 63 deletions

View File

@@ -768,22 +768,22 @@ class InputModel {
}
/// Send a mouse tap event(down and up).
void tap(MouseButtons button) {
sendMouse('down', button);
sendMouse('up', button);
Future<void> tap(MouseButtons button) async {
await sendMouse('down', button);
await sendMouse('up', button);
}
void tapDown(MouseButtons button) {
sendMouse('down', button);
Future<void> tapDown(MouseButtons button) async {
await sendMouse('down', button);
}
void tapUp(MouseButtons button) {
sendMouse('up', button);
Future<void> tapUp(MouseButtons button) async {
await sendMouse('up', button);
}
/// Send scroll event with scroll distance [y].
void scroll(int y) {
bind.sessionSendMouse(
Future<void> scroll(int y) async {
await bind.sessionSendMouse(
sessionId: sessionId,
msg: json
.encode(modify({'id': id, 'type': 'wheel', 'y': y.toString()})));
@@ -804,9 +804,9 @@ class InputModel {
}
/// Send mouse press event.
void sendMouse(String type, MouseButtons button) {
Future<void> sendMouse(String type, MouseButtons button) async {
if (!keyboardPerm) return;
bind.sessionSendMouse(
await bind.sessionSendMouse(
sessionId: sessionId,
msg: json.encode(modify({'type': type, 'buttons': button.value})));
}
@@ -830,11 +830,11 @@ class InputModel {
}
/// Send mouse movement event with distance in [x] and [y].
void moveMouse(double x, double y) {
Future<void> moveMouse(double x, double y) async {
if (!keyboardPerm) return;
var x2 = x.toInt();
var y2 = y.toInt();
bind.sessionSendMouse(
await bind.sessionSendMouse(
sessionId: sessionId,
msg: json.encode(modify({'x': '$x2', 'y': '$y2'})));
}

View File

@@ -2038,7 +2038,7 @@ class CursorModel with ChangeNotifier {
}
// For touch mode
move(double x, double y) {
Future<bool> move(double x, double y) async {
if (shouldBlock(x, y)) {
_lastIsBlocked = true;
return false;
@@ -2047,7 +2047,7 @@ class CursorModel with ChangeNotifier {
if (!_moveLocalIfInRemoteRect(x, y)) {
return false;
}
parent.target?.inputModel.moveMouse(_x, _y);
await parent.target?.inputModel.moveMouse(_x, _y);
return true;
}
@@ -2105,9 +2105,9 @@ class CursorModel with ChangeNotifier {
notifyListeners();
}
updatePan(Offset delta, Offset localPosition, bool touchMode) {
updatePan(Offset delta, Offset localPosition, bool touchMode) async {
if (touchMode) {
_handleTouchMode(delta, localPosition);
await _handleTouchMode(delta, localPosition);
return;
}
double dx = delta.dx;
@@ -2205,7 +2205,7 @@ class CursorModel with ChangeNotifier {
return x >= 0 && y >= 0 && x <= w && y <= h;
}
_handleTouchMode(Offset delta, Offset localPosition) {
_handleTouchMode(Offset delta, Offset localPosition) async {
bool isMoved = false;
if (_remoteWindowCoords.isNotEmpty &&
_windowRect != null &&
@@ -2221,7 +2221,7 @@ class CursorModel with ChangeNotifier {
coords.canvas.scale;
x2 += coords.cursor.offset.dx;
y2 += coords.cursor.offset.dy;
parent.target?.inputModel.moveMouse(x2, y2);
await parent.target?.inputModel.moveMouse(x2, y2);
isMoved = true;
}
}
@@ -2264,7 +2264,7 @@ class CursorModel with ChangeNotifier {
_x = movement.dx;
_y = movement.dy;
parent.target?.inputModel.moveMouse(_x, _y);
await parent.target?.inputModel.moveMouse(_x, _y);
}
notifyListeners();
}