wailsapp / wails

Create beautiful applications using Go
https://wails.io
MIT License
25.03k stars 1.2k forks source link

Window size incorrect on Windows #3260

Open stevenwithaph opened 8 months ago

stevenwithaph commented 8 months ago

Description

The actual window is smaller on when including the frame. I've attached a screenshot of the application, the dimensions of both width and height should be 1024x768, but according to the screenshot it's 1010x761.

Setting frameless seems to render the application at the correct size.

To Reproduce

  1. Create new app
  2. Measure screen size
  3. See incorrect values

Expected behaviour

Correct screen size

Screenshots

incorrect

Attempted Fixes

No response

System Details

# Wails
Version | v2.8.0

# System
┌────────────────────────────────────────────────────────────────────────┐
| OS           | Windows 10 Home                                         |
| Version      | 2009 (Build: 22621)                                     |
| ID           | 22H2                                                    |
| Go Version   | go1.22.0                                                |
| Platform     | windows                                                 |
| Architecture | amd64                                                   |
| CPU          | 11th Gen Intel(R) Core(TM) i5-11600K @ 3.90GHz          |
| GPU          | NVIDIA GeForce RTX 2060 (NVIDIA) - Driver: 31.0.15.3699 |
| Memory       | 16GB                                                    |
└────────────────────────────────────────────────────────────────────────┘

# Dependencies
┌────────────────────────────────────────────────────────┐
| Dependency | Package Name | Status    | Version        |
| WebView2   | N/A          | Installed | 121.0.2277.112 |
| Nodejs     | N/A          | Installed | 21.6.1         |
| npm        | N/A          | Installed | 10.2.4         |
| *upx       | N/A          | Available |                |
| *nsis      | N/A          | Available |                |
└─────────────── * - Optional Dependency ────────────────┘

# Diagnosis
Optional package(s) installation details:
  - upx : Available at https://upx.github.io/
  - nsis : More info at https://wails.io/docs/guides/windows-installer/

Additional context

No response

stffabi commented 8 months ago

Thanks for using Wails and reporting this.

The sizes specified are always the size of the Window and not the size of the WebView. So IMHO this is correct that the WebView's size is smaller due to titlebar and borders.

IMHO this is also too late to change such a fundamental behaviour in v2 anymore, but might be revisited for v3. IIRC there was already somewhere a discussion how this should work in v3 and the consense was to keep the v2 behaviour.

stevenwithaph commented 8 months ago

Understandable, but it feels incorrect to me.

Is there anywhere this is being tracked? I included this feature into my own branch and the change was trivial. If wanted I could look into fixing this.

leaanthony commented 8 months ago

The window size isn't incorrect, it's set to what you give it. The content is a different size for sure. Electron also uses size for the window not the web view. They use the concept of "content size". I did a poll when I started v2 as to whether people wanted the value to be content or window and the vast majority said window. We could add content size for sure but you're the only person who has asked for it so far 😄 Windows has an extra nuance where the menu is included in the client rect size, making the content even smaller. The same is probably true for linux.

We would welcome a PR for this! The things to consider:

  1. Adding a bool in the config, like SizeIsContentSize
  2. Calculating the correct window size based on the content size, which needs to take into consideration if there are menus in the window
  3. Adding GetContentSize and SetContentSize to the runtime
  4. Determine how desktop scaling affects calculations
  5. Determine how DPI affects calculations

This would need to be done on all 3 platforms. How far along is your branch with these considerations in mind?