flutter_desktop: fix canvas size in normal and fullscreen

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2022-10-04 21:19:31 +08:00
parent 589d366327
commit 126d92bf67
4 changed files with 26 additions and 13 deletions

View File

@ -31,6 +31,7 @@ const kDefaultScrollDuration = Duration(milliseconds: 50);
const kDefaultMouseWheelThrottleDuration = Duration(milliseconds: 50); const kDefaultMouseWheelThrottleDuration = Duration(milliseconds: 50);
const kFullScreenEdgeSize = 0.0; const kFullScreenEdgeSize = 0.0;
var kWindowEdgeSize = Platform.isWindows ? 1.0 : 5.0; var kWindowEdgeSize = Platform.isWindows ? 1.0 : 5.0;
const kWindowBorderWidth = 1.0;
const kInvalidValueStr = "InvalidValueStr"; const kInvalidValueStr = "InvalidValueStr";

View File

@ -27,10 +27,12 @@ class RemotePage extends StatefulWidget {
Key? key, Key? key,
required this.id, required this.id,
required this.tabBarHeight, required this.tabBarHeight,
required this.windowBorderWidth,
}) : super(key: key); }) : super(key: key);
final String id; final String id;
final double tabBarHeight; final double tabBarHeight;
final double windowBorderWidth;
@override @override
State<RemotePage> createState() => _RemotePageState(); State<RemotePage> createState() => _RemotePageState();
@ -54,6 +56,7 @@ class _RemotePageState extends State<RemotePage>
void _updateTabBarHeight() { void _updateTabBarHeight() {
_ffi.canvasModel.tabBarHeight = widget.tabBarHeight; _ffi.canvasModel.tabBarHeight = widget.tabBarHeight;
_ffi.canvasModel.windowBorderWidth = widget.windowBorderWidth;
} }
void _initStates(String id) { void _initStates(String id) {

View File

@ -42,11 +42,13 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
selectedIcon: selectedIcon, selectedIcon: selectedIcon,
unselectedIcon: unselectedIcon, unselectedIcon: unselectedIcon,
onTabCloseButton: () => handleTabCloseButton(peerId), onTabCloseButton: () => handleTabCloseButton(peerId),
page: RemotePage( page: Obx(() => RemotePage(
key: ValueKey(peerId), key: ValueKey(peerId),
id: peerId, id: peerId,
tabBarHeight: fullscreen.isTrue ? 0 : kDesktopRemoteTabBarHeight, tabBarHeight:
))); fullscreen.isTrue ? 0 : kDesktopRemoteTabBarHeight,
windowBorderWidth: fullscreen.isTrue ? 0 : kWindowBorderWidth,
))));
} }
} }
@ -74,11 +76,13 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
selectedIcon: selectedIcon, selectedIcon: selectedIcon,
unselectedIcon: unselectedIcon, unselectedIcon: unselectedIcon,
onTabCloseButton: () => handleTabCloseButton(id), onTabCloseButton: () => handleTabCloseButton(id),
page: RemotePage( page: Obx(() => RemotePage(
key: ValueKey(id), key: ValueKey(id),
id: id, id: id,
tabBarHeight: fullscreen.isTrue ? 0 : kDesktopRemoteTabBarHeight, tabBarHeight:
))); fullscreen.isTrue ? 0 : kDesktopRemoteTabBarHeight,
windowBorderWidth: fullscreen.isTrue ? 0 : kWindowBorderWidth,
))));
} else if (call.method == "onDestroy") { } else if (call.method == "onDestroy") {
tabController.clear(); tabController.clear();
} }
@ -90,7 +94,9 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
final RxBool fullscreen = Get.find(tag: 'fullscreen'); final RxBool fullscreen = Get.find(tag: 'fullscreen');
final tabWidget = Container( final tabWidget = Container(
decoration: BoxDecoration( decoration: BoxDecoration(
border: Border.all(color: MyTheme.color(context).border!)), border: Border.all(
color: MyTheme.color(context).border!,
width: kWindowBorderWidth)),
child: Scaffold( child: Scaffold(
backgroundColor: Theme.of(context).backgroundColor, backgroundColor: Theme.of(context).backgroundColor,
body: Obx(() => DesktopTab( body: Obx(() => DesktopTab(

View File

@ -298,7 +298,7 @@ class FfiModel with ChangeNotifier {
if (_pi.currentDisplay < _pi.displays.length) { if (_pi.currentDisplay < _pi.displays.length) {
_display = _pi.displays[_pi.currentDisplay]; _display = _pi.displays[_pi.currentDisplay];
} }
if (displays.length > 0) { if (displays.isNotEmpty) {
parent.target?.dialogManager.showLoading( parent.target?.dialogManager.showLoading(
translate('Connected, waiting for image...'), translate('Connected, waiting for image...'),
onCancel: closeConnection); onCancel: closeConnection);
@ -472,6 +472,8 @@ class CanvasModel with ChangeNotifier {
double _scale = 1.0; double _scale = 1.0;
// the tabbar over the image // the tabbar over the image
double tabBarHeight = 0.0; double tabBarHeight = 0.0;
// the window border's width
double windowBorderWidth = 0.0;
// remote id // remote id
String id = ''; String id = '';
// scroll offset x percent // scroll offset x percent
@ -559,7 +561,8 @@ class CanvasModel with ChangeNotifier {
Size get size { Size get size {
final size = MediaQueryData.fromWindow(ui.window).size; final size = MediaQueryData.fromWindow(ui.window).size;
return Size(size.width, size.height - tabBarHeight); return Size(size.width - windowBorderWidth * 2,
size.height - tabBarHeight - windowBorderWidth * 2);
} }
moveDesktopMouse(double x, double y) { moveDesktopMouse(double x, double y) {