fix: mobile, cursor mode, don't reset canvas (#9843)

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou 2024-11-06 21:59:23 +08:00 committed by GitHub
parent 78088360ca
commit faf97c770c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 22 deletions

View File

@ -542,7 +542,9 @@ class _RemotePageState extends State<RemotePage> with WidgetsBindingObserver {
right: 10,
child: QualityMonitor(gFFI.qualityMonitorModel),
),
KeyHelpTools(requestShow: (keyboardIsVisible || _showGestureHelp)),
KeyHelpTools(
keyboardIsVisible: keyboardIsVisible,
showGestureHelp: _showGestureHelp),
SizedBox(
width: 0,
height: 0,
@ -771,10 +773,14 @@ class _RemotePageState extends State<RemotePage> with WidgetsBindingObserver {
}
class KeyHelpTools extends StatefulWidget {
/// need to show by external request, etc [keyboardIsVisible] or [changeTouchMode]
final bool requestShow;
final bool keyboardIsVisible;
final bool showGestureHelp;
KeyHelpTools({required this.requestShow});
/// need to show by external request, etc [keyboardIsVisible] or [changeTouchMode]
bool get requestShow => keyboardIsVisible || showGestureHelp;
KeyHelpTools(
{required this.keyboardIsVisible, required this.showGestureHelp});
@override
State<KeyHelpTools> createState() => _KeyHelpToolsState();
@ -819,7 +825,8 @@ class _KeyHelpToolsState extends State<KeyHelpTools> {
final size = renderObject.size;
Offset pos = renderObject.localToGlobal(Offset.zero);
gFFI.cursorModel.keyHelpToolsVisibilityChanged(
Rect.fromLTWH(pos.dx, pos.dy, size.width, size.height));
Rect.fromLTWH(pos.dx, pos.dy, size.width, size.height),
widget.keyboardIsVisible);
}
}
@ -831,7 +838,8 @@ class _KeyHelpToolsState extends State<KeyHelpTools> {
inputModel.command;
if (!_pin && !hasModifierOn && !widget.requestShow) {
gFFI.cursorModel.keyHelpToolsVisibilityChanged(null);
gFFI.cursorModel
.keyHelpToolsVisibilityChanged(null, widget.keyboardIsVisible);
return Offstage();
}
final size = MediaQuery.of(context).size;

View File

@ -1515,12 +1515,8 @@ class CanvasModel with ChangeNotifier {
if (kIgnoreDpi && style == kRemoteViewStyleOriginal) {
_scale = 1.0 / _devicePixelRatio;
}
_x = (size.width - displayWidth * _scale) / 2;
_y = (size.height - displayHeight * _scale) / 2;
_resetCanvasOffset(displayWidth, displayHeight);
_imageOverflow.value = _x < 0 || y < 0;
if (isMobile && style == kRemoteViewStyleOriginal) {
_moveToCenterCursor();
}
if (notify) {
notifyListeners();
}
@ -1530,6 +1526,14 @@ class CanvasModel with ChangeNotifier {
tryUpdateScrollStyle(Duration.zero, style);
}
_resetCanvasOffset(int displayWidth, int displayHeight) {
_x = (size.width - displayWidth * _scale) / 2;
_y = (size.height - displayHeight * _scale) / 2;
if (isMobile && _lastViewStyle.style == kRemoteViewStyleOriginal) {
_moveToCenterCursor();
}
}
tryUpdateScrollStyle(Duration duration, String? style) async {
if (_scrollStyle != ScrollStyle.scrollbar) return;
style ??= await bind.sessionGetViewStyle(sessionId: sessionId);
@ -1640,8 +1644,7 @@ class CanvasModel with ChangeNotifier {
if (isWebDesktop) {
updateViewStyle();
} else {
_x = (size.width - getDisplayWidth() * _scale) / 2;
_y = (size.height - getDisplayHeight() * _scale) / 2;
_resetCanvasOffset(getDisplayWidth(), getDisplayHeight());
}
notifyListeners();
}
@ -1677,10 +1680,7 @@ class CanvasModel with ChangeNotifier {
if (kIgnoreDpi && _lastViewStyle.style == kRemoteViewStyleOriginal) {
_scale = 1.0 / _devicePixelRatio;
}
final displayWidth = getDisplayWidth();
final displayHeight = getDisplayHeight();
_x = (size.width - displayWidth * _scale) / 2;
_y = (size.height - displayHeight * _scale) / 2;
_resetCanvasOffset(getDisplayWidth(), getDisplayHeight());
bind.sessionSetViewStyle(sessionId: sessionId, value: _lastViewStyle.style);
notifyListeners();
}
@ -1937,9 +1937,10 @@ class CursorModel with ChangeNotifier {
// `lastIsBlocked` is only used in common/widgets/remote_input.dart -> _RawTouchGestureDetectorRegionState -> onDoubleTap()
// Because onDoubleTap() doesn't have the `event` parameter, we can't get the touch event's position.
bool _lastIsBlocked = false;
bool _lastKeyboardIsVisible = false;
Rect? get keyHelpToolsRect => _keyHelpToolsRect;
keyHelpToolsVisibilityChanged(Rect? r) {
keyHelpToolsVisibilityChanged(Rect? r, bool keyboardIsVisible) {
_keyHelpToolsRect = r;
if (r == null) {
_lastIsBlocked = false;
@ -1949,11 +1950,10 @@ class CursorModel with ChangeNotifier {
// `lastIsBlocked` will be set when the cursor is moving or touch somewhere else.
_lastIsBlocked = true;
}
if (isMobile) {
if (r != null || _lastIsBlocked) {
parent.target?.canvasModel.mobileFocusCanvasCursor();
}
if (isMobile && _lastKeyboardIsVisible != keyboardIsVisible) {
parent.target?.canvasModel.mobileFocusCanvasCursor();
}
_lastKeyboardIsVisible = keyboardIsVisible;
}
get lastIsBlocked => _lastIsBlocked;