libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
9.53k stars 1.77k forks source link

SDL_GetWindowSize & SDL_GetWindowPosition with SDL_BORDERLESS_RESIZABLE_STYLE hint reports inaccurate(?) values #6564

Open takase1121 opened 1 year ago

takase1121 commented 1 year ago

When SDL_BORDERLESS_RESIZABLE_STYLE is enabled and the window is maximized, the coordinates reported by SDL_GetWindowPosition and the size reported by SDL_GetWindowsSize is offsetted. This might be related to how Windows deals with borderless mode as mentioned in this post and the issue #4043. For instance, on my 1920x1080 screen, a maximized window should be (0, 0, 1920, 1050) (as taskbar is 30px tall), but with SDL_BORDERLESS_RESIZABLE_STYLE the values reported are (-9, -9, 1938, 1048), 1938-1920 = 18 = 9 * 2 which might hint at some kind of border being clipped out of the screen.

jonmortiboy commented 10 months ago

Just thought I'd chime in, I posted the original issue described in #4043. This does indeed seem to be part of the same issue I was having. That issue got closed as completed. I'm not sure specifically what was fixed, but I can confirm in the latest version of SDL2 (2.28.5) the problem I described is still there.

I ended up not using the borderless resizable hint in my project and totally forgot I made that bug report after it got migrated from the old bug tracker. I've just come to a new project and decided to try it out again but found it still to be broken. I think this means it's not possible to make an application with SDL2 which has a custom titlebar and window decorations on Windows without delving into either the SDL2 source or using the Win32 API, as maximising the window will cause the rendering within the window to be offset/clipped and this black bar issue on the second monitor as mentioned in #4043.

I did some more testing, and it seems the window pos and size are reported correctly in every case apart from when maximised. If you drag a borderless resizable window to one of the left/right aero snap positions, it works absolutely fine. But as soon as you drag to the top to maximise, you will get these issues. I'm still on Windows 10 so can't check the behaviour on Windows 11, but there may be other considerations that need to be made with the rounded window corners on 11.