X Tutup
Skip to content

Wayland: Work around window scale ambiguity#113656

Merged
akien-mga merged 1 commit intogodotengine:masterfrom
deralmas:gray-goo-scenario
Dec 16, 2025
Merged

Wayland: Work around window scale ambiguity#113656
akien-mga merged 1 commit intogodotengine:masterfrom
deralmas:gray-goo-scenario

Conversation

@deralmas
Copy link
Contributor

@deralmas deralmas commented Dec 6, 2025

Fixes #110643.

This is a workaround to a very annoying problem, and I'm really not sure how to explain it in simple terms1.

On Godot, each window's size is exactly that of the underlying buffer (let's call it an "absolute size").

On Wayland and MacOS, windows have a dpi-independent "logical size". If the system scale factor isn't 1, the underlying buffer grows/shrinks to accommodate that.

This difference causes some very annoying issues which currently require workarounds2.

The biggest issue here is that, since the engine uses absolute units, there's no way to tell the reason behind the resize. This means that whenever the buffer changes size to account for scaling, that is effectively treated as the actual window size (as if the user resized it themselves) and stored e.g. in the Window node.

Whenever a Window node hide()s and show()s, the size will be adjusted and fed back, meaning that the effective window will grow more and more.

While it may be possible to make the Wayland backend "buffer-centric" it's discouraged to as the API is really not built for that and it would cause bad user UX. Additionally, after some discussion it looks like there's no way around it, with "logical size" being a concept we need for good engine-wide per-viewport dynamic DPI scaling anyways, so I'm proposing the following workaround in the meantime:

  • Add a new (unbound) method in DS: window_get_scale. By default, it returns the window's screen scale, but on Wayland it returns the actual per-window scale.

  • Only on platforms with FEATURE_SELF_ADJUSTING_WINDOWS3, in window.cpp, we "unscale" the window rect whenever the window is unmapped.

  • [Editor specific] Additionally, on platforms with the above flag, we also use the default position and screen whenever it is restored from memory. That system is already, as is, very limited on Wayland anyways, being limited to storing the size. Perhaps a more proper fix would be to do the adjusting every time the window size is saved, but I tried to be as little invasive as possible.

Footnotes

  1. This is also, despite my habits, why I didn't put comments or stuff like that. I have no idea how to put it into words decently, as this is some very annoying and specific stuff. Any tip is appreciated.

  2. MacOS has its own workarounds that don't apply in our case. I'll omit them for brevity.

  3. Yes, I'm aware that FEATURE_SELF_ADJUSTING_WINDOWS is becoming the "Wayland" flag and that's another pet peeve of mine that we should eventually discuss. Personally I'd keep the feature flag check instead of hardcoding the DS name simply because and hypothetical custom platform/ds could benefit from this too. If that's too broad, we could do the hardcoded check, I'm fine with both options.

@akien-mga akien-mga merged commit 5d5db07 into godotengine:master Dec 16, 2025
20 checks passed
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Closing and reopening popups on Wayland causes them to grow

3 participants

X Tutup