Skip to content
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

Window size not preserved correctly when multiple displays use different screen scaling (devicePixelRatio) #80

Open
Marcus10110 opened this issue Jan 27, 2023 · 1 comment

Comments

@Marcus10110
Copy link

Configuration:
Windows 10
2 monitors, side-by-side configuration.
Left monitor scaling set to 150%.
Right monitor scaling set to 200%.
Left monitor is primary display.
(other scale factors should produce the same results, as long as the two displays have different scale factors)

Steps to reproduce:

  1. open electron application, move to any location on the right monitor.
  2. close & re-open application

Problem description:
The X & Y location of the software is preserved correctly. However, the width and height of the application is now larger than it was when closed. The width and height were both scaled up by 33%.

Expected behavior:
The width and height are restored correctly.

This seems like a per-display scaling awareness problem, but I'm not sure if it's an issue with electron-window-state, or with the electron BrowserWindow constructor width & height arguments. It does seem likely however that the problem could be corrected in electron-window-state.

@SslTomH
Copy link

SslTomH commented May 23, 2023

Adding this line after constructing the window seemed to result in the correct window size for me:

window.setBounds(mainWindowState);

All this does is re-apply the stored size after the window has already been placed on the correct monitor, which somehow results in the scale applying correctly.

@Marcus10110 I reckon your hunch about it being a bug with the BrowserWindow constructor is correct, though I'm less certain how electron-window-state could reliably fix this on its own. Perhaps the size could be re-applied when mainWindowState.manage() is called...

EDIT: may need some more safety for the mainWindowState first time through, as x and y can be undefined (even though the types indicate otherwise).

    const bounds: Partial<Rectangle> = {
        height: mainWindowState.height,
        width: mainWindowState.width,
    };
    window.setBounds(bounds);

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

2 participants