[rcore][GLFW] Fix window landing off-screen when it's bigger than the monitor workarea - #6015
Open
Gooh456 wants to merge 1 commit into
Open
[rcore][GLFW] Fix window landing off-screen when it's bigger than the monitor workarea#6015Gooh456 wants to merge 1 commit into
Gooh456 wants to merge 1 commit into
Conversation
…nitor workarea InitPlatform() centers the window with monitorX + (monitorWidth - width)/2, with no check for the window being bigger than the monitor. If it is (landscape window on a portrait primary monitor, or any window wider/taller than the workarea), that division goes negative and the window gets placed outside the virtual desktop. On Windows this doesn't just look off-center, glfwSetWindowPos/GetWindowPos come back with garbage coordinates and the window can end up invisible until you drag it back with win+shift+arrow. SetWindowMonitor() already guards against this by anchoring to the workarea origin when the window doesn't fit, so apply the same check here. Repro: request InitWindow() with a size wider than the monitor and read GetWindowPosition() right after. Before the fix this returns a huge bogus x value instead of a small negative one. After the fix it's anchored to the monitor origin. Verified on Windows 11 with a single monitor (couldn't test the original portrait multi-monitor report from raysan5#6002 directly, don't have that hardware, but the position math is the same code path). Fixes raysan5#6002 Signed-off-by: Kyue <164024549+Gooh456@users.noreply.github.com>
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 #6002.
InitPlatform()centers the window withmonitorX + (monitorWidth - width)/2. There's no check for the window being wider or taller than the monitor. When it is, that goes negative and the window gets placed outside the virtual desktop. On Windows this isn't just "off-center",glfwSetWindowPos/GetWindowPositioncome back with garbage coordinates and the window can stay invisible until you drag it back with win+shift+arrow, which matches what's described in #6002 (portrait primary monitor, landscape window, window vanishes,SetWindowPosition(0,0)right afterInitWindow()"fixes" it).SetWindowMonitor()already handles this correctly, it anchors to the workarea origin instead of centering when the window doesn't fit. This PR just applies the same guard inInitPlatform().How I checked it: wrote a small repro that calls
InitWindow()with a width bigger than my monitor and readsGetWindowPosition()right after.Before:
After:
Also checked a normal window size still centers the same as before (800x450 on a 1920x1032 workarea gives x=560 y=291, matches the math).
I don't have a real portrait-monitor multi-display setup to reproduce the exact report in #6002, only a single landscape monitor here, so I forced the same code path by requesting a window wider than my monitor instead. Same math, same branch, just couldn't test the literal portrait-monitor case.