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

BrowserWindow.getContentSize() does not behave the same as expected #25295

Open
3 tasks done
XMLHexagram opened this issue Sep 3, 2020 · 18 comments
Open
3 tasks done
Labels
10-x-y 12-x-y bug 🪲 component/BrowserWindow has-repro-gist Issue can be reproduced with code at https://gist.github.com/ platform/windows status/confirmed A maintainer reproduced the bug or agreed with the feature

Comments

@XMLHexagram
Copy link

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:
    • 10.1.0
  • Operating System:
    • windows 10
  • Last Known Working Electron version:
    • 9.0.x

In some cases,I need to change the height of the windwo and keep the width the same.
when I use

let win = BrowserWindow.getAllWindows()[0]
let size = win.getContentSize() //or let size = win.getSize()
win.setSize(Math.floor(size[0]),1000)

then width will excatly +1 when I call these code
(in another case,the height will excatly +1 also)

It looks the getContentSize always get 1px more then window.

Even though I can simply -1 after I get the size of the window,I still want kown why

Expected Behavior

window.getContentSize() should return the excat px of the window

Actual Behavior

window.getContentSize() get 1px more on both width and height

To Reproduce

Screenshots

image
image

Additional Information

getSize() will behave the same as getContentSize()

@ColorfulHorse
Copy link

same problem when I use setPosition or setBounds change window position

@ColorfulHorse
Copy link

the window width is 850, but window.getSize return 851

this.win = new BrowserWindow({
            maximizable: false,
            fullscreen: false,
            frame: false,
            transparent: true,
            focusable: true,
            width: 850,
            height: 200,
            resizable: true,
            movable: true,
            closable: true,
            skipTaskbar: true,
            webPreferences: {
                nodeIntegration: Boolean(process.env.ELECTRON_NODE_INTEGRATION),
                nodeIntegrationInWorker: true,
                enableRemoteModule: true,
                webSecurity: false
            },
            show: false
        })
mounted() {
    const win = remote.BrowserWindow.getFocusedWindow()
    if (win) {
      const { width, height } = win.getSize() // width = 851
    }
}

@mlaurencin
Copy link
Contributor

@lmx-Hexagram and @ColorfulHorse I am having a bit of trouble recreating your issues. Could you try running this Fiddle gist and confirm whether or not you are experiencing the same thing?: Gist
If not, if you could create and link your own gist, that would be very helpful.
(I housed both of your examples in the same gist, so the code under "IPC Method" can be commented out in favor of "Remote Method" and vice versa. )

@XMLHexagram
Copy link
Author

i will create a gist as soon as possiable

@XMLHexagram
Copy link
Author

I am sorry that I am not very good at using gist,
so I fork electron-quick-start and Recurring this bug on it
the link is HERE
I just add few code in main.js, and after you use yarn run start and wait a few seconds the window will get few px larger
(it will become weird when I change getsize() to getContentSize())
image

@mlaurencin
Copy link
Contributor

mlaurencin commented Oct 27, 2020

That's no problem, I was able to use your electron-quick-start fork. (And if anyone else wants to take a look, here is another gist repro: gist)

Unfortunately, I still cannot recreate the issue on my end. Perhaps see if you made any other changes when upgrading from version 9 to version 10?

Concerning it becoming weird when you change from getSize() to getContentSize() that is because they are referring to two different areas. You can find an explanation of the difference between them (along with their set counterparts) here. Essentially, the first refers to the size of the overall window while the second only a subset of it. However, if your window has no frame, they will return the same size.

@mlaurencin mlaurencin added the has-repro-gist Issue can be reproduced with code at https://gist.github.com/ label Oct 27, 2020
@ColorfulHorse
Copy link

this problem disappeared after upgrade version 9.0.2 to 10.1.1, but i still dont know why

@pushkin-
Copy link

pushkin- commented Mar 14, 2021

I can still repro with 10.1.1 using the gist mlaurencin linked above.

[ 800, 600 ]
[ 800, 600 ]
[ 800, 600 ]
[800, 601 ]
[800, 603 ]
[800, 604 ]
[ 801, 604 ]
[803, 604 ]
[804, 604 ]
[805, 605 ]
[806, 606 ]
[807, 607 ]
[808, 608 ]
[808, 608 ]
[809, 609 ]
[810, 610 ]
[811, 611 ]
[812, 612 ]
[812, 612 ]
[812, 612 ]
[813, 613 ]

Can repro with 12.0.1 as well. In both cases, I have to move the window a little to trigger it. Possibly related to this

@ColorfulHorse
Copy link

@mlaurencin @lmx-Hexagram @pushkin- I recreate the issue after change system layout scale to 125%
Meanwhile, if BrowserWindow maxWidth/maxHeight fixed, layout scale not affect
image

this.win = new BrowserWindow({
            maximizable: false,
            fullscreen: false,
            frame: false,
            transparent: true,
            // focusable: true,
            width: this.width,
            height: this.height,
            minWidth: this.width,
            minHeight: this.height,
            // maxWidth: this.width, 
            // maxHeight: this.height,
            resizable: true,
            movable: true,
            closable: true,
            skipTaskbar: true,
            x: (width - this.width) / 2,
            y: height - this.height,
            webPreferences: {
                nodeIntegration: Boolean(process.env.ELECTRON_NODE_INTEGRATION),
                nodeIntegrationInWorker: true,
                enableRemoteModule: true,
                webSecurity: false
            },
            show: false
        })

@github-actions
Copy link
Contributor

github-actions bot commented Oct 7, 2022

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

@github-actions github-actions bot added the stale label Oct 7, 2022
@pushkin-
Copy link

pushkin- commented Oct 7, 2022

Repros on Electron 21, though I feel like this issue is a dupe of another one.

@github-actions github-actions bot removed the stale label Oct 8, 2022
@github-actions
Copy link
Contributor

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

@github-actions github-actions bot added the stale label Jan 10, 2023
@pushkin-
Copy link

repros in v22

@github-actions github-actions bot removed the stale label Jan 12, 2023
@github-actions
Copy link
Contributor

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

@github-actions github-actions bot added the stale label Apr 13, 2023
@pushkin-
Copy link

bump

@github-actions github-actions bot removed the stale label Apr 14, 2023
@github-actions
Copy link
Contributor

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

@github-actions github-actions bot added the stale label Jul 13, 2023
@pushkin-
Copy link

bump

@github-actions github-actions bot removed the stale label Jul 14, 2023
@electron-issue-triage
Copy link

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

@dsanders11 dsanders11 added status/confirmed A maintainer reproduced the bug or agreed with the feature and removed stale labels Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
10-x-y 12-x-y bug 🪲 component/BrowserWindow has-repro-gist Issue can be reproduced with code at https://gist.github.com/ platform/windows status/confirmed A maintainer reproduced the bug or agreed with the feature
Projects
None yet
Development

No branches or pull requests

7 participants