Skip to content

Commit

Permalink
fix: Window sizing issue on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Losses committed Nov 22, 2024
1 parent d14a725 commit a7933d0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
8 changes: 6 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,13 @@ void main(List<String> arguments) async {
await settingsManager.getValue<String>(windowSizeKey) ?? 'normal';

doWhenWindowReady(() {
final windowSize = windowSizes[windowSizeSetting];
final firstView = WidgetsBinding.instance.platformDispatcher.views.first;

DesktopWindow.setWindowSize(windowSize!).then((_) {
final windowSize = Platform.isWindows
? windowSizes[windowSizeSetting]! * firstView.devicePixelRatio
: windowSizes[windowSizeSetting]!;

DesktopWindow.setWindowSize(windowSize).then((_) {
appWindow.alignment = Alignment.center;
appWindow.show();
});
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/settings_theme/constants/window_sizes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import 'package:fluent_ui/fluent_ui.dart';
const Map<String, Size> windowSizes = {
"normal": Size(1280, 720),
"slim": Size(340, 600),
"stocky": Size(720, 280),
"stocky": Size(720, 320),
};
9 changes: 7 additions & 2 deletions lib/screens/settings_theme/settings_theme.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:io';

import 'package:fluent_ui/fluent_ui.dart';
import 'package:desktop_window/desktop_window.dart';
import 'package:material_symbols_icons/symbols.dart';
Expand Down Expand Up @@ -111,8 +113,11 @@ class _SettingsThemeState extends State<SettingsTheme> {
}

void _updateWindowSize(String newWindowSize) async {
final size = windowSizes[newWindowSize];
if (size == null) return;
final firstView = WidgetsBinding.instance.platformDispatcher.views.first;

final size = Platform.isWindows
? windowSizes[newWindowSize]! * firstView.devicePixelRatio
: windowSizes[newWindowSize]!;

setState(() {
windowSize = newWindowSize;
Expand Down

0 comments on commit a7933d0

Please sign in to comment.