From 0ce2c88c50749026ff418c99b9a5f604d32039fe Mon Sep 17 00:00:00 2001 From: SoLongAndThanksForAllThePizza <103753680+SoLongAndThanksForAllThePizza@users.noreply.github.com> Date: Mon, 27 Jun 2022 16:50:02 +0800 Subject: [PATCH] feat: implemented remote control on desktop --- flutter/lib/desktop/pages/remote_page.dart | 38 +++++++-------- flutter/lib/models/model.dart | 57 +++++++++++++++------- 2 files changed, 58 insertions(+), 37 deletions(-) diff --git a/flutter/lib/desktop/pages/remote_page.dart b/flutter/lib/desktop/pages/remote_page.dart index 2e5c4a243..e0a4fa563 100644 --- a/flutter/lib/desktop/pages/remote_page.dart +++ b/flutter/lib/desktop/pages/remote_page.dart @@ -256,28 +256,28 @@ class _RemotePageState extends State child: getRawPointerAndKeyBody( keyboard, Scaffold( - // resizeToAvoidBottomInset: true, + // resizeToAvoidBottomInset: true, floatingActionButton: !showActionButton ? null : FloatingActionButton( - mini: !hideKeyboard, - child: Icon(hideKeyboard - ? Icons.expand_more - : Icons.expand_less), - backgroundColor: MyTheme.accent, - onPressed: () { - setState(() { - if (hideKeyboard) { - _showEdit = false; - _ffi.invokeMethod( - "enable_soft_keyboard", false); - _mobileFocusNode.unfocus(); - _physicalFocusNode.requestFocus(); - } else { - _showBar = !_showBar; - } - }); - }), + mini: !hideKeyboard, + child: Icon(hideKeyboard + ? Icons.expand_more + : Icons.expand_less), + backgroundColor: MyTheme.accent, + onPressed: () { + setState(() { + if (hideKeyboard) { + _showEdit = false; + _ffi.invokeMethod( + "enable_soft_keyboard", false); + _mobileFocusNode.unfocus(); + _physicalFocusNode.requestFocus(); + } else { + _showBar = !_showBar; + } + }); + }), bottomNavigationBar: _showBar && pi.displays.length > 0 ? getBottomAppBar(keyboard) : null, diff --git a/flutter/lib/models/model.dart b/flutter/lib/models/model.dart index a39940e9d..8d4737c5a 100644 --- a/flutter/lib/models/model.dart +++ b/flutter/lib/models/model.dart @@ -425,18 +425,35 @@ class CanvasModel with ChangeNotifier { final size = MediaQueryData.fromWindow(ui.window).size; final s1 = size.width / (parent.target?.ffiModel.display.width ?? 720); final s2 = size.height / (parent.target?.ffiModel.display.height ?? 1280); - if (s == 'shrink') { + // Closure to perform shrink operation. + final shrinkOp = () { final s = s1 < s2 ? s1 : s2; if (s < 1) { _scale = s; } - } else if (s == 'stretch') { + }; + // Closure to perform stretch operation. + final stretchOp = () { final s = s1 > s2 ? s1 : s2; if (s > 1) { _scale = s; } + }; + // Closure to perform default operation(set the scale to 1.0). + final defaultOp = () { + _scale = 1.0; + }; + if (s == 'shrink') { + shrinkOp(); + } else if (s == 'stretch') { + stretchOp(); } else { - _scale = 1; + // On desktop, shrink is the default behavior. + if (isDesktop) { + shrinkOp(); + } else { + defaultOp(); + } } _x = (size.width - getDisplayWidth() * _scale) / 2; _y = (size.height - getDisplayHeight() * _scale) / 2; @@ -459,21 +476,24 @@ class CanvasModel with ChangeNotifier { } void moveDesktopMouse(double x, double y) { - final size = MediaQueryData.fromWindow(ui.window).size; - final dw = getDisplayWidth() * _scale; - final dh = getDisplayHeight() * _scale; - var dxOffset = 0; - var dyOffset = 0; - if (dw > size.width) { - dxOffset = (x - dw * (x / size.width) - _x).toInt(); - } - if (dh > size.height) { - dyOffset = (y - dh * (y / size.height) - _y).toInt(); - } - _x += dxOffset; - _y += dyOffset; - if (dxOffset != 0 || dyOffset != 0) { - notifyListeners(); + // On mobile platforms, move the canvas with the cursor. + if (!isDesktop) { + final size = MediaQueryData.fromWindow(ui.window).size; + final dw = getDisplayWidth() * _scale; + final dh = getDisplayHeight() * _scale; + var dxOffset = 0; + var dyOffset = 0; + if (dw > size.width) { + dxOffset = (x - dw * (x / size.width) - _x).toInt(); + } + if (dh > size.height) { + dyOffset = (y - dh * (y / size.height) - _y).toInt(); + } + _x += dxOffset; + _y += dyOffset; + if (dxOffset != 0 || dyOffset != 0) { + notifyListeners(); + } } parent.target?.cursorModel.moveLocal(x, y); } @@ -714,6 +734,7 @@ class CursorModel with ChangeNotifier { } } + /// Update the cursor position. void updateCursorPosition(Map evt) { _x = double.parse(evt['x']); _y = double.parse(evt['y']);