Wayland: Work around window scale ambiguity#113656
Merged
akien-mga merged 1 commit intogodotengine:masterfrom Dec 16, 2025
Merged
Wayland: Work around window scale ambiguity#113656akien-mga merged 1 commit intogodotengine:masterfrom
akien-mga merged 1 commit intogodotengine:masterfrom
Conversation
bruvzg
approved these changes
Dec 16, 2025
Member
|
Thanks! |
This was referenced Feb 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Windownode.Whenever a
Windownodehide()s andshow()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, inwindow.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
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. ↩
MacOS has its own workarounds that don't apply in our case. I'll omit them for brevity. ↩
Yes, I'm aware that
FEATURE_SELF_ADJUSTING_WINDOWSis 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. ↩