diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart index b776e2c32..adbfabc78 100644 --- a/flutter/lib/common.dart +++ b/flutter/lib/common.dart @@ -55,6 +55,12 @@ var isMobile = isAndroid || isIOS; var version = ''; int androidVersion = 0; +// Only used on Linux. +// `windowManager.setResizable(false)` will reset the window size to the default size on Linux. +// https://stackoverflow.com/questions/8193613/gtk-window-resize-disable-without-going-back-to-default +// So we need to use this flag to enable/disable resizable. +bool _linuxWindowResizable = true; + /// only available for Windows target int windowsBuildNumber = 0; DesktopType? desktopType; @@ -1572,7 +1578,7 @@ Future saveWindowPosition(WindowType type, {int? windowId}) async { // `await windowManager.isMaximized()` will always return true // if is not resizable. The reason is unknown. // - // `windowManager.setResizable(!bind.isIncomingOnly());` in main.dart + // `setResizable(!bind.isIncomingOnly());` in main.dart isMaximized = bind.isIncomingOnly() ? false : await windowManager.isMaximized(); position = await windowManager.getPosition(); @@ -3234,7 +3240,9 @@ Widget buildVirtualWindowFrame(BuildContext context, Widget child) { return Obx( () => Container( decoration: BoxDecoration( - color: isMainDesktopWindow ? Colors.transparent : Theme.of(context).colorScheme.background, + color: isMainDesktopWindow + ? Colors.transparent + : Theme.of(context).colorScheme.background, border: Border.all( color: Theme.of(context).dividerColor, width: stateGlobal.windowBorderWidth.value, @@ -3258,4 +3266,18 @@ Widget buildVirtualWindowFrame(BuildContext context, Widget child) { ); } -get windowEdgeSize => isLinux && bind.isIncomingOnly() ? 0.0 : kWindowEdgeSize; +get windowEdgeSize => isLinux && _linuxWindowResizable ? 0.0 : kWindowEdgeSize; + +// `windowManager.setResizable(false)` will reset the window size to the default size on Linux and then set unresizable. +// See _linuxWindowResizable for more details. +// So we use `setResizable()` instead of `windowManager.setResizable()`. +// +// We can only call `windowManager.setResizable(false)` if we need the default size on Linux. +setResizable(bool resizable) { + if (isLinux) { + _linuxWindowResizable = resizable; + stateGlobal.refreshResizeEdgeSize(); + } else { + windowManager.setResizable(resizable); + } +} diff --git a/flutter/lib/consts.dart b/flutter/lib/consts.dart index 14f17fa29..926dd32af 100644 --- a/flutter/lib/consts.dart +++ b/flutter/lib/consts.dart @@ -154,6 +154,7 @@ const kDefaultScrollDuration = Duration(milliseconds: 50); const kDefaultMouseWheelThrottleDuration = Duration(milliseconds: 50); const kFullScreenEdgeSize = 0.0; const kMaximizeEdgeSize = 0.0; +// Do not use kWindowEdgeSize directly. Use `windowEdgeSize` in `common.dart` instead. final kWindowEdgeSize = isWindows ? 1.0 : 5.0; final kWindowBorderWidth = isLinux ? 1.0 : 0.0; const kDesktopMenuPadding = EdgeInsets.only(left: 12.0, right: 3.0); diff --git a/flutter/lib/desktop/pages/desktop_tab_page.dart b/flutter/lib/desktop/pages/desktop_tab_page.dart index 99a28206d..4c4b8b0f5 100644 --- a/flutter/lib/desktop/pages/desktop_tab_page.dart +++ b/flutter/lib/desktop/pages/desktop_tab_page.dart @@ -57,10 +57,10 @@ class _DesktopTabPageState extends State { tabController.onSelected = (key) { if (key == kTabLabelHomePage) { windowManager.setSize(getIncomingOnlyHomeSize()); - windowManager.setResizable(false); + setResizable(false); } else { windowManager.setSize(getIncomingOnlySettingsSize()); - windowManager.setResizable(true); + setResizable(true); } }; } diff --git a/flutter/lib/main.dart b/flutter/lib/main.dart index 69873fd9b..6c4c9f2bb 100644 --- a/flutter/lib/main.dart +++ b/flutter/lib/main.dart @@ -144,12 +144,8 @@ void runMainApp(bool startService) async { } windowManager.setOpacity(1); windowManager.setTitle(getWindowName()); - // `windowManager.setResizable(false)` will reset the window size to the default size on Linux. - // https://stackoverflow.com/questions/8193613/gtk-window-resize-disable-without-going-back-to-default - if (!isLinux) { - windowManager.setResizable(!bind.isIncomingOnly()); - } - // For Linux, we set the edge size to 0 to disable resize. See `get windowEdgeSize` in common.dart. + // Do not use `windowManager.setResizable()` here. + setResizable(!bind.isIncomingOnly()); }); } @@ -243,7 +239,7 @@ void runConnectionManagerScreen() async { } else { await showCmWindow(isStartup: true); } - windowManager.setResizable(false); + setResizable(false); // Start the uni links handler and redirect links to Native, not for Flutter. listenUniLinks(handleByFlutter: false); } diff --git a/flutter/lib/models/state_model.dart b/flutter/lib/models/state_model.dart index b3d6e00c1..a885eae8f 100644 --- a/flutter/lib/models/state_model.dart +++ b/flutter/lib/models/state_model.dart @@ -56,8 +56,7 @@ class StateGlobal { if (!_fullscreen.isTrue) { if (isMaximized.value != v) { isMaximized.value = v; - _resizeEdgeSize.value = - isMaximized.isTrue ? kMaximizeEdgeSize : windowEdgeSize; + refreshResizeEdgeSize(); } if (!isMacOS) { _windowBorderWidth.value = v ? 0 : kWindowBorderWidth; @@ -71,11 +70,7 @@ class StateGlobal { if (_fullscreen.value != v) { _fullscreen.value = v; _showTabBar.value = !_fullscreen.value; - _resizeEdgeSize.value = fullscreen.isTrue - ? kFullScreenEdgeSize - : isMaximized.isTrue - ? kMaximizeEdgeSize - : windowEdgeSize; + refreshResizeEdgeSize(); print( "fullscreen: $fullscreen, resizeEdgeSize: ${_resizeEdgeSize.value}"); _windowBorderWidth.value = fullscreen.isTrue ? 0 : kWindowBorderWidth; @@ -96,6 +91,12 @@ class StateGlobal { } } + refreshResizeEdgeSize() => _resizeEdgeSize.value = fullscreen.isTrue + ? kFullScreenEdgeSize + : isMaximized.isTrue + ? kMaximizeEdgeSize + : windowEdgeSize; + String getInputSource({bool force = false}) { if (force || _inputSource.isEmpty) { _inputSource = bind.mainGetInputSource();