touchpad, linux as the controlled side, better control

Signed-off-by: dignow <linlong1265@gmail.com>
This commit is contained in:
dignow 2023-06-28 23:00:29 +08:00
parent c8cd10b6de
commit 8deaf8807b

View File

@ -51,6 +51,9 @@ class InputModel {
var _fling = false;
Timer? _flingTimer;
final _flingBaseDelay = 30;
// trackpad, peer linux
final _trackpadSpeed = 0.06;
var _trackpadScrollUnsent = Offset.zero;
// mouse
final isPhysicalMouse = false.obs;
@ -332,16 +335,24 @@ class InputModel {
// https://docs.flutter.dev/release/breaking-changes/trackpad-gestures
// TODO(support zoom in/out)
void onPointerPanZoomUpdate(PointerPanZoomUpdateEvent e) {
final delta = e.panDelta;
var delta = e.panDelta;
_trackpadLastDelta = delta;
var x = delta.dx.toInt();
var y = delta.dy.toInt();
if (x == 0 && y == 0) {
final thr = 0.1;
if (delta.dx.abs() > delta.dy.abs()) {
x = delta.dx > thr ? 1 : (delta.dx < -thr ? -1 : 0);
} else {
y = delta.dy > thr ? 1 : (delta.dy < -thr ? -1 : 0);
if (parent.target?.ffiModel.pi.platform == kPeerPlatformLinux) {
_trackpadScrollUnsent += (delta * _trackpadSpeed);
x = _trackpadScrollUnsent.dx.truncate();
y = _trackpadScrollUnsent.dy.truncate();
_trackpadScrollUnsent -= Offset(x.toDouble(), y.toDouble());
} else {
if (x == 0 && y == 0) {
final thr = 0.1;
if (delta.dx.abs() > delta.dy.abs()) {
x = delta.dx > thr ? 1 : (delta.dx < -thr ? -1 : 0);
} else {
y = delta.dy > thr ? 1 : (delta.dy < -thr ? -1 : 0);
}
}
}
if (x != 0 || y != 0) {
@ -370,6 +381,11 @@ class InputModel {
// Try set delta (x,y) and delay.
var dx = x.toInt();
var dy = y.toInt();
if (parent.target?.ffiModel.pi.platform == kPeerPlatformLinux) {
dx = (x * _trackpadSpeed).toInt();
dy = (y * _trackpadSpeed).toInt();
}
var delay = _flingBaseDelay;
if (dx == 0 && dy == 0) {