We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4574

Summary: resizing a window on a mac via SDL_SetWindowSize isn't guaranteed to give you the requested dimensions, and SDL data gets out of sync (+patch)
Product: SDL Reporter: Kyle Rawlins <rawlins>
Component: videoAssignee: Alex Szpakowski <amaranth72>
Status: WAITING --- QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: 2.0.7   
Hardware: x86   
OS: macOS 10.12   
Attachments: patch for mac resize bug

Description Kyle Rawlins 2019-03-30 22:48:04 UTC
Created attachment 3718 [details]
patch for mac resize bug

When I resize a (non-fullscreen) window via `SDL_SetWindowSize`, OS X sometimes chooses a different size than the one I give to SDL. The main way that I know to trigger this is to have a dock on the lower part of the scren, and pick a window height that would exceed the usable space; the actual window height that OS X gives then is the maximum user height that the client area + window decorations will fit into. If this happens, then the dimensions on the SDL_Window object reflect what was passed to `SDL_SetWindowSize`, not the actual resulting size, and so calls to `SDL_GetWindowSize` return the wrong value. (Compounding things, calls to `SDL_GL_GetDrawableSize` seem to still be correct, though the value is in device pixels.) The only way I've found on the SDL user side is to manually resize the window, at which point things become in sync.

The attached patch fixes this problem for us (us = DCSS). I'm afraid that I don't know much about SDL internal best practices so you may well prefer to solve this a different way, e.g. by sending a resize message to the client when this happens. However, the SDL_SetWindowSize already does send a size changed message (and it is currently sending the wrong values too), so that would require some refactoring.

(I marked 2.0.7 because that is what we are using at the moment, and that is what this patch is against, but it doesn't appear that the relevant code has been touched more recently.)

Possibly related to https://bugzilla.libsdl.org/show_bug.cgi?id=2452?
Comment 1 Sam Lantinga 2019-06-12 03:12:07 UTC
Alex, can you check this?

Why would we get a size changed message with the wrong size and never get this corrected by the OS resize notifications?
Comment 2 Alex Szpakowski 2019-06-13 00:32:21 UTC
I just tried to reproduce this using the latest code from hg, but I wasn't able to.

If I call SDL_SetWindowSize on a window that wasn't created with the SDL_WINDOW_RESIZABLE flag, it seems to use my chosen size no matter what. If I call SetWindowSize on a window without that flag, the OS resizes my window to fit in the status bar, SDL_GetWindowSize immediately gives back the updated size, and I also get a resize event which gives the updated size as well.

Can you try the most recent possible SDL code or version and see if it still happens for you? If it does still happen, a small bit of code that can reproduce the issue would help as well.
Comment 3 Kyle Rawlins 2019-06-13 23:03:52 UTC
I can look at this again and try to create a MWE, but it will take me a few days to get back to it.