From 1acb64c35d2720c532d1b9a470c39c7c20fd10a7 Mon Sep 17 00:00:00 2001 From: open-trade Date: Mon, 21 Dec 2020 17:26:23 +0800 Subject: [PATCH] new keyboard offset and scroll --- flutter_hbb/lib/model.dart | 6 ++++-- flutter_hbb/lib/remote_page.dart | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/flutter_hbb/lib/model.dart b/flutter_hbb/lib/model.dart index 3c38865e1..9133283ce 100644 --- a/flutter_hbb/lib/model.dart +++ b/flutter_hbb/lib/model.dart @@ -319,10 +319,12 @@ class CursorModel with ChangeNotifier { } double adjustForKeyboard() { - var keyboardHeight = MediaQueryData.fromWindow(ui.window).viewInsets.bottom; + final m = MediaQueryData.fromWindow(ui.window); + var keyboardHeight = m.viewInsets.bottom; + final size = m.size; if (keyboardHeight < 100) return 0; final s = FFI.canvasModel.scale; - final thresh = 120; + final thresh = (size.height - keyboardHeight) / 2; var h = (_y - getVisibleRect().top) * s; // local physical display height return h - thresh; } diff --git a/flutter_hbb/lib/remote_page.dart b/flutter_hbb/lib/remote_page.dart index d4fbf7b7f..6cb968e0a 100644 --- a/flutter_hbb/lib/remote_page.dart +++ b/flutter_hbb/lib/remote_page.dart @@ -28,6 +28,8 @@ class _RemotePageState extends State { String _value = ''; double _xOffset = 0; double _yOffset = 0; + double _xOffset0 = 0; + double _yOffset0 = 0; double _scale = 1; bool _mouseTools = false; var _drag = false; @@ -258,8 +260,8 @@ class _RemotePageState extends State { }, onScaleStart: (details) { _scale = 1; - _xOffset = details.focalPoint.dx; - _yOffset = details.focalPoint.dy; + _xOffset = _xOffset0 = details.focalPoint.dx; + _yOffset = _yOffset0 = details.focalPoint.dy; if (_drag) { FFI.sendMouse('down', 'left'); } @@ -275,6 +277,9 @@ class _RemotePageState extends State { FFI.cursorModel.updatePan(dx, dy); _xOffset = x; _yOffset = y; + } else { + _xOffset = details.focalPoint.dx; + _yOffset = details.focalPoint.dy; } } else if (!_drag && !_scroll) { FFI.canvasModel.updateScale(scale / _scale); @@ -285,8 +290,12 @@ class _RemotePageState extends State { if (_drag) { FFI.sendMouse('up', 'left'); } else if (_scroll) { - FFI.scroll( - details.velocity.pixelsPerSecond.dy > 0 ? -1 : 1); + var dy = (_yOffset - _yOffset0) / 10; + if (dy.abs() > 0.1) { + if (dy > 0 && dy < 1) dy = 1; + if (dy < 0 && dy > -1) dy = -1; + FFI.scroll(dy); + } } }, child: Container(