electron: [Bug]: setBounds make BrowserWindows larger every time on Windows

Preflight Checklist

  • I have read the Contributing Guidelines for this project.
  • I agree to follow the Code of Conduct that this project adheres to.
  • I have searched the issue tracker for an issue that matches the one I want to file, without success.

Issue Details

  • Electron Version:
    • 11.2.3
  • Operating System:
    • Windows 10 20H2
  • Last Known Working Electron version:
    • unknow

Expected Behavior

setBounds to output of getBounds makes no effect to BrowserWindows size

Actual Behavior

setBounds to output of getBounds makes BrowserWindows size larger every time setBounds called

To Reproduce

main.js

const { app, BrowserWindow } = require('electron')

function createWindow () {
  const win = new BrowserWindow({
    width: 801,
    height: 601,
    webPreferences: {
      nodeIntegration: true
    }
  })

  win.loadFile('index.html')

  let bounds = null

  win.on('minimize', () => {
    bounds = win.getBounds()
  })

  win.on('restore', () => {
    win.setBounds(bounds)
    console.log(win.getBounds())
  })
}

app.whenReady().then(createWindow)

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit()
  }
})

app.on('activate', () => {
  if (BrowserWindow.getAllWindows().length === 0) {
    createWindow()
  }
})

index.html


<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Hello World!</title>
    <meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
</head>
<body style="background: white;">
    <h1>Hello World!</h1>
    <p>
        We are using node <script>document.write(process.versions.node)</script>,
        Chrome <script>document.write(process.versions.chrome)</script>,
        and Electron <script>document.write(process.versions.electron)</script>.
    </p>
</body>
</html>

Screenshots

image

Additional Information

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 2
  • Comments: 23 (4 by maintainers)

Most upvoted comments

It seems that this issue is related to the zoom factor of the system.

I tried 125%, 150%, 175%, 200% and 225% on a 3840x2160 monitor and all even numbers are fine but odd numbers are not.

Besides, macOS do not have this issue whild testing.

I think it might be a lead to locate the glitch.