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 '../../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<RemotePage>
@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<RemotePage>
}
}();
} 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 = <Widget>[];
final pi = ffi(id).ffiModel.pi;
final image = ffi(id).ffiModel.getConnectionImage();

View File

@ -735,6 +735,9 @@ class _RemotePageState extends State<RemotePage> {
}
}();
} 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);

View File

@ -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<FFI> 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 != '') {