flutter_desktop: remote window mid commit

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2022-08-13 15:08:17 +08:00
parent c38c9d275b
commit af2e555e41
3 changed files with 57 additions and 25 deletions

View File

@ -14,7 +14,6 @@ import 'package:wakelock/wakelock.dart';
// import 'package:window_manager/window_manager.dart'; // import 'package:window_manager/window_manager.dart';
import '../../common.dart'; import '../../common.dart';
import '../../consts.dart';
import '../../mobile/widgets/dialog.dart'; import '../../mobile/widgets/dialog.dart';
import '../../mobile/widgets/overlay.dart'; import '../../mobile/widgets/overlay.dart';
import '../../models/model.dart'; import '../../models/model.dart';
@ -275,7 +274,6 @@ class _RemotePageState extends State<RemotePage>
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
super.build(context); super.build(context);
_ffi.canvasModel.tabBarHeight = super.widget.tabBarHeight;
return WillPopScope( return WillPopScope(
onWillPop: () async { onWillPop: () async {
clientClose(_ffi.dialogManager); clientClose(_ffi.dialogManager);
@ -631,6 +629,9 @@ class _RemotePageState extends State<RemotePage>
} }
}(); }();
} else if (value == 'enter_os_password') { } 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"); var password = await bind.getSessionOption(id: id, arg: "os-password");
if (password != null) { if (password != null) {
bind.sessionInputOsPassword(id: widget.id, value: password); bind.sessionInputOsPassword(id: widget.id, value: password);
@ -862,23 +863,48 @@ class ImagePaint extends StatelessWidget {
child: SingleChildScrollView( child: SingleChildScrollView(
controller: _horizontal, controller: _horizontal,
scrollDirection: Axis.horizontal, scrollDirection: Axis.horizontal,
child: SizedBox( child: buildListener(SizedBox(
width: c.getDisplayWidth() * s, width: c.getDisplayWidth() * s,
height: c.getDisplayHeight() * s, height: c.getDisplayHeight() * s,
child: CustomPaint( child: CustomPaint(
painter: new ImagePainter( painter: new ImagePainter(
image: m.image, x: 0, y: 0, scale: s), image: m.image, x: 0, y: 0, scale: s),
))), )))),
), ),
)), )),
)); ));
} else { } else {
return CustomPaint( return buildListener(CustomPaint(
painter: painter:
new ImagePainter(image: m.image, x: c.x / s, y: c.y / s, scale: s), 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 { class CursorPaint extends StatelessWidget {
@ -942,8 +968,6 @@ void showOptions(String id, OverlayDialogManager dialogManager) async {
await bind.getSessionOption(id: id, arg: 'view-style') ?? ''; await bind.getSessionOption(id: id, arg: 'view-style') ?? '';
String scrollStyle = String scrollStyle =
await bind.getSessionOption(id: id, arg: 'scroll-style') ?? ''; await bind.getSessionOption(id: id, arg: 'scroll-style') ?? '';
ffi(id).canvasModel.setScrollStyle(scrollStyle);
var displays = <Widget>[]; var displays = <Widget>[];
final pi = ffi(id).ffiModel.pi; final pi = ffi(id).ffiModel.pi;
final image = ffi(id).ffiModel.getConnectionImage(); final image = ffi(id).ffiModel.getConnectionImage();

View File

@ -735,6 +735,9 @@ class _RemotePageState extends State<RemotePage> {
} }
}(); }();
} else if (value == 'enter_os_password') { } 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"); var password = await bind.getSessionOption(id: id, arg: "os-password");
if (password != null) { if (password != null) {
bind.sessionInputOsPassword(id: widget.id, value: password); bind.sessionInputOsPassword(id: widget.id, value: password);

View File

@ -387,8 +387,9 @@ class ImageModel with ChangeNotifier {
void update(ui.Image? image, double tabBarHeight) { void update(ui.Image? image, double tabBarHeight) {
if (_image == null && image != null) { if (_image == null && image != null) {
if (isWebDesktop) { if (isWebDesktop || isDesktop) {
parent.target?.canvasModel.updateViewStyle(); parent.target?.canvasModel.updateViewStyle();
parent.target?.canvasModel.updateScrollStyle();
} else { } else {
final size = MediaQueryData.fromWindow(ui.window).size; final size = MediaQueryData.fromWindow(ui.window).size;
final canvasWidth = size.width; final canvasWidth = size.width;
@ -447,7 +448,7 @@ class CanvasModel with ChangeNotifier {
double _scale = 1.0; double _scale = 1.0;
double _tabBarHeight = 0.0; double _tabBarHeight = 0.0;
String id = ""; // TODO multi canvas model String id = ""; // TODO multi canvas model
ScrollStyle _scrollStyle = ScrollStyle.scrollbar; ScrollStyle _scrollStyle = ScrollStyle.scrollauto;
WeakReference<FFI> parent; WeakReference<FFI> parent;
@ -470,12 +471,14 @@ class CanvasModel with ChangeNotifier {
double get tabBarHeight => _tabBarHeight; double get tabBarHeight => _tabBarHeight;
void updateViewStyle() async { void updateViewStyle() async {
final s = await bind.getSessionOption(id: id, arg: 'view-style'); final style = await bind.getSessionOption(id: id, arg: 'view-style');
if (s == null) { if (style == null) {
return; return;
} }
final s1 = size.width / (parent.target?.ffiModel.display.width ?? 720); final s1 = size.width / (parent.target?.ffiModel.display.width ?? 720);
final s2 = size.height / (parent.target?.ffiModel.display.height ?? 1280); final s2 = size.height / (parent.target?.ffiModel.display.height ?? 1280);
// Closure to perform shrink operation. // Closure to perform shrink operation.
final shrinkOp = () { final shrinkOp = () {
final s = s1 < s2 ? s1 : s2; final s = s1 < s2 ? s1 : s2;
@ -502,9 +505,9 @@ class CanvasModel with ChangeNotifier {
defaultOp(); defaultOp();
// } // }
if (s == 'shrink') { if (style == 'shrink') {
shrinkOp(); shrinkOp();
} else if (s == 'stretch') { } else if (style == 'stretch') {
stretchOp(); stretchOp();
} }
@ -514,19 +517,15 @@ class CanvasModel with ChangeNotifier {
} }
updateScrollStyle() async { updateScrollStyle() async {
final s = await bind.getSessionOption(id: id, arg: 'scroll-style'); final style = await bind.getSessionOption(id: id, arg: 'scroll-style');
setScrollStyle(s); if (style == 'scrollbar') {
notifyListeners();
}
setScrollStyle(String? style) {
if (style == 'scrollauto') {
_scrollStyle = ScrollStyle.scrollauto;
} else {
_scrollStyle = ScrollStyle.scrollbar; _scrollStyle = ScrollStyle.scrollbar;
_scrollX = 0.0; _scrollX = 0.0;
_scrollY = 0.0; _scrollY = 0.0;
} else {
_scrollStyle = ScrollStyle.scrollauto;
} }
notifyListeners();
} }
void update(double x, double y, double scale) { void update(double x, double y, double scale) {
@ -1130,6 +1129,14 @@ class FFI {
final imageHeight = d.height * canvasModel.scale; final imageHeight = d.height * canvasModel.scale;
x += imageWidth * canvasModel.scrollX; x += imageWidth * canvasModel.scrollX;
y += imageHeight * canvasModel.scrollY; 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 { } else {
x -= canvasModel.x; x -= canvasModel.x;
y -= canvasModel.y; y -= canvasModel.y;
@ -1138,10 +1145,8 @@ class FFI {
if (!isMove && (x < 0 || x > d.width || y < 0 || y > d.height)) { if (!isMove && (x < 0 || x > d.width || y < 0 || y > d.height)) {
return; return;
} }
x /= canvasModel.scale; x /= canvasModel.scale;
y /= canvasModel.scale; y /= canvasModel.scale;
x += d.x; x += d.x;
y += d.y; y += d.y;
if (type != '') { if (type != '') {