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
[rcore_desktop] Window sizes and position with multiple monitor configurations #3693
Comments
Hi there, @SelfReflection31 - While I can not yet fully explain what is happening (nor properly reproduce your issue), while trying to reproduce your issue, I found some odd behaviour on my machine. I am adding my findings to help further pin down the issue. My setup: MS Windows 11, One UHD monitor (3840x2160) as the main display; To the right (top) of that, an FHD monitor (1920x1080) - see layout here: I used the example binary created by When I start the created binary from an explorer window on the UHD monitor, the created window is centred on this monitor: However, when I start the binary with file browser on the FHD monitor, the created window still appears on the UHD monitor, the window is shifted, has a different size and even different centre alignment for its content: The position of the FHD monitor relative to the UHD monitor does not change this (top-aligned, bottom-aligned, center-aligned; left-of, right-of). If I enable the third monitor (built-in one of laptop, resolution 2880x1920) and run the application from this one, the resulting window has yet another location (still on UHD) and size. Hence, I suspect different resolutions of the monitors seem to have a role in this. However, it may also be relevant what functions @SelfReflection31 , may I ask for your desktop layout and involved monitor resolutions? And if you have extra time, perhaps let your application write a text file with the results of the mentioned |
Addendum: After changing the linked line in
This places the window at the centre of the monitor where file explorer was running. Fullscreen mode is unaffected by this change, and always shows up the window on the primary monitor, regardless of this change, and regardless from where the app is started. However, I don't know the intent of the library. With fullscreen apps always starting on primary monitor, should this be the case also for windowed apps? If so, then the size/position calculation is wrong. If not, then monitor position needs to be taken into account. |
Apparently, this is a deeper issue.. 👁️ not even raylib but with msi/glfw. I found a fix so far aka shutting down this "Nahimic" service. It was blocking it. looking it up, it seems this has been an ongoing issue with glfw windows or more. with your problem, you already found the fix I thinks :P |
Cool - so with that service stopped, the window opens centred in the respective monitor you started the application on? |
oh my apologies, starting the application, the window opens only on the primary monitor. It even with the offset like you showed...so yes. |
OK, thank you for clarifying - so this issue still remains for all. Meanwhile I could also figure out why (with the position fix) a "borderless fullscreen" window would open up with a wrong size on my third monitor even if started on the second. Short: Long:
What to change? Core question remains: With fullscreen windows opened on the primary monitor exclusively, which monitor should be taken for regular windows, and which one for borderless fullscreen windows? Regular windows: As mentioned before, they either need the positioning fix for the right monitor, or a sizing fix for the primary monitor. About borderless fullscreen ones I am not sure: In summary: This positioning stuff is confusing from users perspective, yet affects "only" those with multiple monitors which furthermore have different resolutions - AND the app needs to be started from explorer on a different monitor... . How to proceed? |
@dertseha @SelfReflection31 Thank you very much for investigating this issue and the detailed report!
That code was added lately by a contributor and personally I'm not sure if that's the best approach... Would it help removing it and avoid that extra step?
Yes, I'm afraid it is, there are too many possible combinations and dealing with HighDPI and non-HighDPI and multiple resolutions on multiple monitors could be quite tricky. Still maybe the issue could be minimized? About the questions:
No, fullscreen borderless scales the application resolution to the monitor resolution and hides window borders (actually it's a windowed mode). Fullscreen tries to scale the application to the the closest fullscreen-resolution available on the monitor and changes monitor resolution, it's like an exclusive mode.
Yes, that's the most logical behaviour.
It can be removed.
No, it shouldn't start on a different monitor. |
Thank you for your reply. This then means,
My proposal for 2 is an extension to the existing Meaning, I'll try this out in my fork and report back. A side note regarding comparing "borderless fullscreen" and "regular fullscreen" - I wasn't clear what I meant with "similar". I understand the difference in how the draw surface is created. What I meant with "similar" was: If I want a "borderless fullscreen" window, would I want it to behave like a regular "fullscreen" app and always be on the primary monitor? However, as I understand you now: both windows and "borderless fullscreen" windows should open up on the monitor where they were started. Should this also count for "fullscreen" apps, or should they always go on the primary monitor? |
Addendum - please clarify, because I realize I might misinterpret your statement:
Do you mean all cases should start on the primary monitor, or did you mean "if I start the app on monitor 2, it shouldn't show on monitor 3, and instead should show on monitor 2" ? |
@dertseha Per mi understanding, the app should start in the monitor you start it. If you are on monitor 2 and you start an app there, it should be displayed in monitor 2. |
Thank you for the clarification. Incidentally, I finally found time today to tackle this. I have found a way to implement all (most?) requirements, yet with some open questions. Branch here: https://github.com/dertseha/raylib/tree/proposal-3693-initial-window-geometry Tested under MS Win11, with What this branch does:
Either way, non-fullscreen applications will be centred on the monitor where they are created. They way this solution does this is by querying the monitor after creating the window, and then derive necessary sizes. This also needed a special case of implicit-monitor-sized windows to be created with an initial size of 1x1 pixels, as GLFW prohibits using 0x0. However, this procedure has two open points: The change now has the effect that, should the user have had specified the explicit monitor dimensions to achieve a non-fullscreen explicit-monitor-sized window, then this solution now no longer removes that hint. This solution does not know the monitor before creating the window, so it can not know its resolution to set the hint. 2) Error cases (However, the previous code was also wrong to assume primary monitor, so this could be used as the fallback?) Code in question (my proposal) here. Furthermore, I tested this only on MS Win11 (three monitors of different resolutions), and only with GLFW. SDL might have different behaviour. The issues regarding querying states, as well as some difficulties with some behaviour, let me second guess the original (unwritten & assumed) requirements:
If these two requirements were dropped, then the code might get simpler for the library:
Yet, I'm not sure if truly much code could be dropped - it still needs OR, and this could be a completely different approach, all paths use the primary monitor, exclusively. If there is the demand for a different monitor, then the library needs a new function to pre-set the target monitor before |
@dertseha Excuse my late response. Thank you very much for the detailed report and the proposed solutions, they look great to me and if they work in a configuration like yours it's enough testing for me, I don't have that kind of configuration and I think is really support many use cases. Feel free to send a PR with the proposed changes. Note that window centering code was updated recently. About your questions:
It would be nice to support it, flag
raylib adopted this convention since its first version and I personally like it. Recently it was reviewed to avoid top-left window corner out of monitor in cases the window resolution is bigger than monitor resolution. Please, let me know if you review this issue or send a PR, I'll be quicker to review it and asnwer, I'd like to close this issue. NOTE: I didn't mention it but monitor High-DPI could also influence the window/framebuffer size (as seen in one of the shared screenshots) and it's also very dependant on OS and GPU/drivers. It could be tricky. |
@raysan5 Thank you for your response. Thank you also for answering questions about requirements. For the change, however, there are two open points to clarify, in section "However, this procedure has two open points" of my previous comment. |
Please, before submitting a new issue verify and check:
using current raylib v5.0 release
Issue description
I'm having this odd issue where if the game is in a release configuration aka
Windows (/SUBSYSTEM:WINDOWS), /ENTRY: mainCRTStartup
If I start the game on my primary monitor it behaves as expected but if I try to open the game while on a different monitor, the game is running but there is no window... yet if I drag the raylib.dll over the exe to open it will trigger the window.doing it with the console works.
Environment
Windows 11, OpenGL 3.3.0 , RTX 3080
Issue Screenshot
example.mp4
Code Example
Just a really simple example.
The text was updated successfully, but these errors were encountered: