fix, use RxBool to sync fullscreen state (remote toolbar)

Signed-off-by: dignow <linlong1265@gmail.com>
This commit is contained in:
dignow 2023-10-17 14:29:14 +08:00
parent f1d3a553d1
commit f9f463e799
4 changed files with 21 additions and 22 deletions

View File

@ -1494,7 +1494,7 @@ Future<void> saveWindowPosition(WindowType type, {int? windowId}) async {
late Offset position;
late Size sz;
late bool isMaximized;
bool isFullscreen = stateGlobal.fullscreen ||
bool isFullscreen = stateGlobal.fullscreen.isTrue ||
(Platform.isMacOS && stateGlobal.closeOnFullscreen);
setFrameIfMaximized() {
if (isMaximized) {
@ -2710,7 +2710,7 @@ tryMoveToScreenAndSetFullscreen(Rect? screenRect) async {
final curFrame = await wc.getFrame();
final frame =
Rect.fromLTWH(screenRect.left + 30, screenRect.top + 30, 600, 400);
if (stateGlobal.fullscreen &&
if (stateGlobal.fullscreen.isTrue &&
curFrame.left <= frame.left &&
curFrame.top <= frame.top &&
curFrame.width >= frame.width &&

View File

@ -3,6 +3,7 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_hbb/common.dart';
import 'package:flutter_hbb/models/state_model.dart';
import 'package:get/get.dart';
const double kDesktopRemoteTabBarHeight = 28.0;
const int kInvalidWindowId = -1;
@ -88,7 +89,7 @@ const double kDesktopFileTransferHeaderHeight = 25.0;
EdgeInsets get kDragToResizeAreaPadding =>
!kUseCompatibleUiMode && Platform.isLinux
? stateGlobal.fullscreen || stateGlobal.isMaximized.value
? stateGlobal.fullscreen.isTrue || stateGlobal.isMaximized.value
? EdgeInsets.zero
: EdgeInsets.all(5.0)
: EdgeInsets.zero;

View File

@ -351,7 +351,6 @@ class _RemoteToolbarState extends State<RemoteToolbar> {
int get windowId => stateGlobal.windowId;
bool get isFullscreen => stateGlobal.fullscreen;
void _setFullscreen(bool v) {
stateGlobal.setFullscreen(v);
setState(() {});
@ -797,7 +796,7 @@ class ScreenAdjustor {
required this.cbExitFullscreen,
});
bool get isFullscreen => stateGlobal.fullscreen;
bool get isFullscreen => stateGlobal.fullscreen.isTrue;
int get windowId => stateGlobal.windowId;
adjustWindow(BuildContext context) {
@ -951,7 +950,6 @@ class _DisplayMenuState extends State<_DisplayMenu> {
cbExitFullscreen: () => widget.setFullscreen(false),
);
bool get isFullscreen => stateGlobal.fullscreen;
int get windowId => stateGlobal.windowId;
Map<String, bool> get perms => widget.ffi.ffiModel.permissions;
PeerInfo get pi => widget.ffi.ffiModel.pi;
@ -2060,21 +2058,21 @@ class _DraggableShowHideState extends State<_DraggableShowHide> {
mainAxisSize: MainAxisSize.min,
children: [
_buildDraggable(context),
TextButton(
Obx(()=>TextButton(
onPressed: () {
widget.setFullscreen(!isFullscreen);
widget.setFullscreen(!isFullscreen.value);
setState(() {});
},
child: Tooltip(
message: translate(isFullscreen ? 'Exit Fullscreen' : 'Fullscreen'),
message: translate(isFullscreen.isTrue ? 'Exit Fullscreen' : 'Fullscreen'),
child: Icon(
isFullscreen ? Icons.fullscreen_exit : Icons.fullscreen,
isFullscreen.isTrue ? Icons.fullscreen_exit : Icons.fullscreen,
size: iconSize,
),
),
),
)),
Offstage(
offstage: !isFullscreen,
offstage: !isFullscreen.value,
child: TextButton(
onPressed: () => widget.setMinimize(),
child: Tooltip(

View File

@ -11,7 +11,7 @@ enum SvcStatus { notReady, connecting, ready }
class StateGlobal {
int _windowId = -1;
bool grabKeyboard = false;
bool _fullscreen = false;
RxBool _fullscreen = false.obs;
bool _isMinimized = false;
final RxBool isMaximized = false.obs;
final RxBool _showTabBar = true.obs;
@ -26,9 +26,9 @@ class StateGlobal {
final Map<String, Map<int, String?>> _lastResolutionGroupValues = {};
int get windowId => _windowId;
bool get fullscreen => _fullscreen;
RxBool get fullscreen => _fullscreen;
bool get isMinimized => _isMinimized;
double get tabBarHeight => fullscreen ? 0 : kDesktopRemoteTabBarHeight;
double get tabBarHeight => fullscreen.isTrue ? 0 : kDesktopRemoteTabBarHeight;
RxBool get showTabBar => _showTabBar;
RxDouble get resizeEdgeSize => _resizeEdgeSize;
RxDouble get windowBorderWidth => _windowBorderWidth;
@ -51,7 +51,7 @@ class StateGlobal {
setWindowId(int id) => _windowId = id;
setMaximized(bool v) {
if (!_fullscreen) {
if (!_fullscreen.isTrue) {
if (isMaximized.value != v) {
isMaximized.value = v;
_resizeEdgeSize.value =
@ -66,20 +66,20 @@ class StateGlobal {
setMinimized(bool v) => _isMinimized = v;
setFullscreen(bool v, {bool procWnd = true}) {
if (_fullscreen != v) {
_fullscreen = v;
_showTabBar.value = !_fullscreen;
_resizeEdgeSize.value = fullscreen
if (_fullscreen.value != v) {
_fullscreen.value = v;
_showTabBar.value = !_fullscreen.value;
_resizeEdgeSize.value = fullscreen.isTrue
? kFullScreenEdgeSize
: isMaximized.isTrue
? kMaximizeEdgeSize
: kWindowEdgeSize;
print(
"fullscreen: $fullscreen, resizeEdgeSize: ${_resizeEdgeSize.value}");
_windowBorderWidth.value = fullscreen ? 0 : kWindowBorderWidth;
_windowBorderWidth.value = fullscreen.isTrue ? 0 : kWindowBorderWidth;
if (procWnd) {
final wc = WindowController.fromWindowId(windowId);
wc.setFullscreen(_fullscreen).then((_) {
wc.setFullscreen(_fullscreen.isTrue).then((_) {
// https://github.com/leanflutter/window_manager/issues/131#issuecomment-1111587982
if (Platform.isWindows && !v) {
Future.delayed(Duration.zero, () async {