Skip to content

[Windows] setWindowPosition incorrect position or size with second monitor and scale factor #536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Fenekhu opened this issue Mar 7, 2025 · 2 comments

Comments

@Fenekhu
Copy link

Fenekhu commented Mar 7, 2025

I'm trying to make my app return to its last position after closing and opening. To do this, I save the position returned by getWindowPosition to persistent storage, and then use this code to restore its position when launching:

  WindowOptions windowOptions = WindowOptions(
    size: app_settings.windowSize,
    skipTaskbar: false,
  );

  await windowManager.waitUntilReadyToShow(windowOptions, () async {
    await windowManager.setMaximizable(false);
    await windowManager.setTitleBarStyle(TitleBarStyle.hidden);
    await windowManager.setPosition(app_settings.windowPos);
    await windowManager.show();
    await windowManager.focus();
  });

The position is restored correctly on my primary monitor, but wrongly on my other monitors. This is my monitor setup:
Image
My main monitor has a scale factor of 175%, and it seems that when it restores onto my other monitor, its being placed at a position thats (1.75*correct x, 1.75*correct y).

Placing it on monitor 3, position before closing:
Image
Position after reopening and nudging it:
Image

I am currently using v0.4.3

UPDATE:
Without changing anything, it now usually positions correctly but sizes incorrectly. Here is the value of the Size its being set to vs the size from windowManager.getSize():

[log] app_settings.windowSize: Size(288.0, 416.0)
[log] window size: Size(164.6, 237.7)
@Fenekhu
Copy link
Author

Fenekhu commented Mar 7, 2025

I tried to build window_manager locally so I could figure out what the issue is, but using the latest state of main, the positioning works fine, but the application is incorrectly sized (probably 1/1.75 times too small), having made no changes to the code. I don't see changes in any of the commits since v0.4.3 that I would expect to make this behave differently either.

Update: Even after switching back to the pub version, it was still wrong size, right place. Even after restarting, still wrong size right place. Then today (the next day), I ran the executable directly (the same from yesterday), and it was right size, wrong positioning. I rebuilt it and wrong size right place again from VSCode and the direct executable.
So it seems to be inconsistent which one behaves correctly, but it seems to usually be wrong size right position usually.

@Fenekhu Fenekhu changed the title [Windows] setWindowPosition incorrect position with second monitor and scale factor [Windows] setWindowPosition incorrect position or size with second monitor and scale factor Mar 10, 2025
@Fenekhu
Copy link
Author

Fenekhu commented Mar 10, 2025

My current workaround is to multiply the dimensions beforehand using the screen_retriever package (which window_manager is already dependent on), based on the workaround for #456

Display display = await screenRetriever.getPrimaryDisplay();
WindowOptions windowOptions = WindowOptions(
  size: app_settings.windowSize * (display.scaleFactor?.toDouble() ?? 1),
  skipTaskbar: false,
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant