diff --git a/flutter/lib/common/widgets/remote_input.dart b/flutter/lib/common/widgets/remote_input.dart index 36fb45339..8eb0ecbc3 100644 --- a/flutter/lib/common/widgets/remote_input.dart +++ b/flutter/lib/common/widgets/remote_input.dart @@ -111,9 +111,13 @@ class _RawTouchGestureDetectorRegionState ); } + bool isNotTouchBasedDevice() { + return !kTouchBasedDeviceKinds.contains(lastDeviceKind); + } + onTapDown(TapDownDetails d) async { lastDeviceKind = d.kind; - if (lastDeviceKind != PointerDeviceKind.touch) { + if (isNotTouchBasedDevice()) { return; } if (handleTouch) { @@ -126,7 +130,7 @@ class _RawTouchGestureDetectorRegionState onTapUp(TapUpDetails d) async { final TapDownDetails? lastTapDownDetails = _lastTapDownDetails; _lastTapDownDetails = null; - if (lastDeviceKind != PointerDeviceKind.touch) { + if (isNotTouchBasedDevice()) { return; } if (handleTouch) { @@ -142,7 +146,7 @@ class _RawTouchGestureDetectorRegionState } onTap() async { - if (lastDeviceKind != PointerDeviceKind.touch) { + if (isNotTouchBasedDevice()) { return; } if (!handleTouch) { @@ -153,7 +157,7 @@ class _RawTouchGestureDetectorRegionState onDoubleTapDown(TapDownDetails d) async { lastDeviceKind = d.kind; - if (lastDeviceKind != PointerDeviceKind.touch) { + if (isNotTouchBasedDevice()) { return; } if (handleTouch) { @@ -163,7 +167,7 @@ class _RawTouchGestureDetectorRegionState } onDoubleTap() async { - if (lastDeviceKind != PointerDeviceKind.touch) { + if (isNotTouchBasedDevice()) { return; } if (ffiModel.touchMode && ffi.cursorModel.lastIsBlocked) { @@ -179,7 +183,7 @@ class _RawTouchGestureDetectorRegionState onLongPressDown(LongPressDownDetails d) async { lastDeviceKind = d.kind; - if (lastDeviceKind != PointerDeviceKind.touch) { + if (isNotTouchBasedDevice()) { return; } if (handleTouch) { @@ -198,7 +202,7 @@ class _RawTouchGestureDetectorRegionState } onLongPressUp() async { - if (lastDeviceKind != PointerDeviceKind.touch) { + if (isNotTouchBasedDevice()) { return; } if (handleTouch) { @@ -208,7 +212,7 @@ class _RawTouchGestureDetectorRegionState // for mobiles onLongPress() async { - if (lastDeviceKind != PointerDeviceKind.touch) { + if (isNotTouchBasedDevice()) { return; } if (!ffi.ffiModel.isPeerMobile) { @@ -228,7 +232,7 @@ class _RawTouchGestureDetectorRegionState } onLongPressMoveUpdate(LongPressMoveUpdateDetails d) async { - if (!ffiModel.isPeerMobile || lastDeviceKind != PointerDeviceKind.touch) { + if (!ffiModel.isPeerMobile || isNotTouchBasedDevice()) { return; } if (handleTouch) { @@ -241,7 +245,7 @@ class _RawTouchGestureDetectorRegionState onDoubleFinerTapDown(TapDownDetails d) async { lastDeviceKind = d.kind; - if (lastDeviceKind != PointerDeviceKind.touch) { + if (isNotTouchBasedDevice()) { return; } _doubleFinerTapPosition = d.localPosition; @@ -250,7 +254,7 @@ class _RawTouchGestureDetectorRegionState onDoubleFinerTap(TapDownDetails d) async { lastDeviceKind = d.kind; - if (lastDeviceKind != PointerDeviceKind.touch) { + if (isNotTouchBasedDevice()) { return; } @@ -266,7 +270,7 @@ class _RawTouchGestureDetectorRegionState onHoldDragStart(DragStartDetails d) async { lastDeviceKind = d.kind; - if (lastDeviceKind != PointerDeviceKind.touch) { + if (isNotTouchBasedDevice()) { return; } if (!handleTouch) { @@ -275,7 +279,7 @@ class _RawTouchGestureDetectorRegionState } onHoldDragUpdate(DragUpdateDetails d) async { - if (lastDeviceKind != PointerDeviceKind.touch) { + if (isNotTouchBasedDevice()) { return; } if (!handleTouch) { @@ -284,7 +288,7 @@ class _RawTouchGestureDetectorRegionState } onHoldDragEnd(DragEndDetails d) async { - if (lastDeviceKind != PointerDeviceKind.touch) { + if (isNotTouchBasedDevice()) { return; } if (!handleTouch) { @@ -296,7 +300,7 @@ class _RawTouchGestureDetectorRegionState final TapDownDetails? lastTapDownDetails = _lastTapDownDetails; _lastTapDownDetails = null; lastDeviceKind = d.kind ?? lastDeviceKind; - if (lastDeviceKind != PointerDeviceKind.touch) { + if (isNotTouchBasedDevice()) { return; } if (handleTouch) { @@ -342,7 +346,7 @@ class _RawTouchGestureDetectorRegionState } onOneFingerPanUpdate(DragUpdateDetails d) async { - if (lastDeviceKind != PointerDeviceKind.touch) { + if (isNotTouchBasedDevice()) { return; } if (ffi.cursorModel.shouldBlock(d.localPosition.dx, d.localPosition.dy)) { @@ -356,7 +360,7 @@ class _RawTouchGestureDetectorRegionState onOneFingerPanEnd(DragEndDetails d) async { _touchModePanStarted = false; - if (lastDeviceKind != PointerDeviceKind.touch) { + if (isNotTouchBasedDevice()) { return; } if (isDesktop || isWebDesktop) { @@ -370,13 +374,13 @@ class _RawTouchGestureDetectorRegionState // scale + pan event onTwoFingerScaleStart(ScaleStartDetails d) { _lastTapDownDetails = null; - if (lastDeviceKind != PointerDeviceKind.touch) { + if (isNotTouchBasedDevice()) { return; } } onTwoFingerScaleUpdate(ScaleUpdateDetails d) async { - if (lastDeviceKind != PointerDeviceKind.touch) { + if (isNotTouchBasedDevice()) { return; } if ((isDesktop || isWebDesktop)) { @@ -401,7 +405,7 @@ class _RawTouchGestureDetectorRegionState } onTwoFingerScaleEnd(ScaleEndDetails d) async { - if (lastDeviceKind != PointerDeviceKind.touch) { + if (isNotTouchBasedDevice()) { return; } if ((isDesktop || isWebDesktop)) { diff --git a/flutter/lib/consts.dart b/flutter/lib/consts.dart index d608df83a..ef42318f0 100644 --- a/flutter/lib/consts.dart +++ b/flutter/lib/consts.dart @@ -1,3 +1,4 @@ +import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter_hbb/common.dart'; import 'package:flutter_hbb/models/state_model.dart'; @@ -336,6 +337,12 @@ const kRemoteImageQualityCustom = 'custom'; const kIgnoreDpi = true; +const Set kTouchBasedDeviceKinds = { + PointerDeviceKind.touch, + PointerDeviceKind.stylus, + PointerDeviceKind.invertedStylus, +}; + // ================================ mobile ================================ // Magic numbers, maybe need to avoid it or use a better way to get them.