From af2e555e41a71e830b4a9928e0aab66a62e5325f Mon Sep 17 00:00:00 2001 From: fufesou Date: Sat, 13 Aug 2022 15:08:17 +0800 Subject: [PATCH] flutter_desktop: remote window mid commit Signed-off-by: fufesou --- flutter/lib/desktop/pages/remote_page.dart | 40 +++++++++++++++++----- flutter/lib/mobile/pages/remote_page.dart | 3 ++ flutter/lib/models/model.dart | 39 ++++++++++++--------- 3 files changed, 57 insertions(+), 25 deletions(-) diff --git a/flutter/lib/desktop/pages/remote_page.dart b/flutter/lib/desktop/pages/remote_page.dart index 46605821f..5eb6993f9 100644 --- a/flutter/lib/desktop/pages/remote_page.dart +++ b/flutter/lib/desktop/pages/remote_page.dart @@ -14,7 +14,6 @@ import 'package:wakelock/wakelock.dart'; // import 'package:window_manager/window_manager.dart'; import '../../common.dart'; -import '../../consts.dart'; import '../../mobile/widgets/dialog.dart'; import '../../mobile/widgets/overlay.dart'; import '../../models/model.dart'; @@ -275,7 +274,6 @@ class _RemotePageState extends State @override Widget build(BuildContext context) { super.build(context); - _ffi.canvasModel.tabBarHeight = super.widget.tabBarHeight; return WillPopScope( onWillPop: () async { clientClose(_ffi.dialogManager); @@ -631,6 +629,9 @@ class _RemotePageState extends State } }(); } else if (value == 'enter_os_password') { + // FIXME: + // null means no session of id + // empty string means no password var password = await bind.getSessionOption(id: id, arg: "os-password"); if (password != null) { bind.sessionInputOsPassword(id: widget.id, value: password); @@ -862,23 +863,48 @@ class ImagePaint extends StatelessWidget { child: SingleChildScrollView( controller: _horizontal, scrollDirection: Axis.horizontal, - child: SizedBox( + child: buildListener(SizedBox( width: c.getDisplayWidth() * s, height: c.getDisplayHeight() * s, child: CustomPaint( painter: new ImagePainter( image: m.image, x: 0, y: 0, scale: s), - ))), + )))), ), )), )); } else { - return CustomPaint( + return buildListener(CustomPaint( painter: new ImagePainter(image: m.image, x: c.x / s, y: c.y / s, scale: s), - ); + )); } } + + Widget buildListener(Widget child) { + return Listener( + onPointerHover: (e) { + debugPrint( + 'REMOVE ME ======================== 4444 onPointerHover ${e.position}'); + }, + onPointerDown: (e) { + debugPrint( + 'REMOVE ME ======================== 4444 onPointerDown ${e.position}'); + }, + onPointerUp: (e) { + debugPrint( + 'REMOVE ME ======================== 4444 onPointerUp ${e.position}'); + }, + onPointerMove: (e) { + debugPrint( + 'REMOVE ME ======================== 4444 onPointerMove ${e.position}'); + }, + onPointerSignal: (e) { + debugPrint( + 'REMOVE ME ======================== 3333 onPointerSignal ${e.position}'); + }, + child: child); + } } class CursorPaint extends StatelessWidget { @@ -942,8 +968,6 @@ void showOptions(String id, OverlayDialogManager dialogManager) async { await bind.getSessionOption(id: id, arg: 'view-style') ?? ''; String scrollStyle = await bind.getSessionOption(id: id, arg: 'scroll-style') ?? ''; - ffi(id).canvasModel.setScrollStyle(scrollStyle); - var displays = []; final pi = ffi(id).ffiModel.pi; final image = ffi(id).ffiModel.getConnectionImage(); diff --git a/flutter/lib/mobile/pages/remote_page.dart b/flutter/lib/mobile/pages/remote_page.dart index 14bdfa833..3e826705f 100644 --- a/flutter/lib/mobile/pages/remote_page.dart +++ b/flutter/lib/mobile/pages/remote_page.dart @@ -735,6 +735,9 @@ class _RemotePageState extends State { } }(); } else if (value == 'enter_os_password') { + // FIXME: + // null means no session of id + // empty string means no password var password = await bind.getSessionOption(id: id, arg: "os-password"); if (password != null) { bind.sessionInputOsPassword(id: widget.id, value: password); diff --git a/flutter/lib/models/model.dart b/flutter/lib/models/model.dart index 016bc370c..c297141de 100644 --- a/flutter/lib/models/model.dart +++ b/flutter/lib/models/model.dart @@ -387,8 +387,9 @@ class ImageModel with ChangeNotifier { void update(ui.Image? image, double tabBarHeight) { if (_image == null && image != null) { - if (isWebDesktop) { + if (isWebDesktop || isDesktop) { parent.target?.canvasModel.updateViewStyle(); + parent.target?.canvasModel.updateScrollStyle(); } else { final size = MediaQueryData.fromWindow(ui.window).size; final canvasWidth = size.width; @@ -447,7 +448,7 @@ class CanvasModel with ChangeNotifier { double _scale = 1.0; double _tabBarHeight = 0.0; String id = ""; // TODO multi canvas model - ScrollStyle _scrollStyle = ScrollStyle.scrollbar; + ScrollStyle _scrollStyle = ScrollStyle.scrollauto; WeakReference parent; @@ -470,12 +471,14 @@ class CanvasModel with ChangeNotifier { double get tabBarHeight => _tabBarHeight; void updateViewStyle() async { - final s = await bind.getSessionOption(id: id, arg: 'view-style'); - if (s == null) { + final style = await bind.getSessionOption(id: id, arg: 'view-style'); + if (style == null) { return; } + final s1 = size.width / (parent.target?.ffiModel.display.width ?? 720); final s2 = size.height / (parent.target?.ffiModel.display.height ?? 1280); + // Closure to perform shrink operation. final shrinkOp = () { final s = s1 < s2 ? s1 : s2; @@ -502,9 +505,9 @@ class CanvasModel with ChangeNotifier { defaultOp(); // } - if (s == 'shrink') { + if (style == 'shrink') { shrinkOp(); - } else if (s == 'stretch') { + } else if (style == 'stretch') { stretchOp(); } @@ -514,19 +517,15 @@ class CanvasModel with ChangeNotifier { } updateScrollStyle() async { - final s = await bind.getSessionOption(id: id, arg: 'scroll-style'); - setScrollStyle(s); - notifyListeners(); - } - - setScrollStyle(String? style) { - if (style == 'scrollauto') { - _scrollStyle = ScrollStyle.scrollauto; - } else { + final style = await bind.getSessionOption(id: id, arg: 'scroll-style'); + if (style == 'scrollbar') { _scrollStyle = ScrollStyle.scrollbar; _scrollX = 0.0; _scrollY = 0.0; + } else { + _scrollStyle = ScrollStyle.scrollauto; } + notifyListeners(); } void update(double x, double y, double scale) { @@ -1130,6 +1129,14 @@ class FFI { final imageHeight = d.height * canvasModel.scale; x += imageWidth * canvasModel.scrollX; y += imageHeight * canvasModel.scrollY; + + // boxed size is a center widget + if (canvasModel.size.width > imageWidth) { + x -= ((canvasModel.size.width - imageWidth) / 2); + } + if (canvasModel.size.height > imageHeight) { + y -= ((canvasModel.size.height - imageHeight) / 2); + } } else { x -= canvasModel.x; y -= canvasModel.y; @@ -1138,10 +1145,8 @@ class FFI { if (!isMove && (x < 0 || x > d.width || y < 0 || y > d.height)) { return; } - x /= canvasModel.scale; y /= canvasModel.scale; - x += d.x; y += d.y; if (type != '') {