Skip to content
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

Difficult to set desired window size after leaving full screen #958

Closed
SDLBugzilla opened this issue Feb 10, 2021 · 0 comments
Closed

Difficult to set desired window size after leaving full screen #958

SDLBugzilla opened this issue Feb 10, 2021 · 0 comments

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

Reported in version: 2.0.0
Reported for operating system, platform: All, All

Comments on the original bug report:

On 2013-07-12 22:56:49 +0000, wrote:

This bug is the (hopefully) real issue started in bug # 1899. It occurs in both Windows and OSX, but sometimes not in Linux (and I can't figure out why).

This is what happens. First some facts:

  • SDL_SetWindowFullscreen() internally sends a SDL_WINDOWEVENT_RESIZED event with the data1 and data2 being the fullscreen window with window decorations
  • SDL_SetWindowSize() does not send the SDL_WINDOWEVENT_RESIZED event (by design) and resizes the window immediately

With those findings, this is roughly the flow of how the problem manifests itself when coming out of full screen mode like so:

SDL_SetWindowFullscreen(window, FALSE);
SDL_SetWindowSize(window, width, height);

The flow:

  1. SDL_SetWindowFullscreen(window, FALSE) comes out of fullscreen and adds SDL_WINDOWEVENT_RESIZED to event queue
  2. SDL_SetWindowSize(window, width, height) changes our window to a desired resolution
  3. The SDL_WINDOWEVENT_RESIZED in the event queue is now triggered in our Event loop.
  4. We listen for the above event and call SDL_SetWindowSize() to handle the new size given in the event
  5. The size given in this event, since it was triggered from SDL_SetWindowFullscreen(), is some default size, slightly less than full screen, and overrides our previously set desired size in step # 2

With all of this together, it makes it difficult to set the window size in a logical manner from within the program.

Is there some proper way to set a desired window size directly after coming out of full screen? I may be missing something...

Thank you

On 2013-07-12 23:46:30 +0000, Ryan C. Gordon wrote:

Tagging this bug with target-2.0.0, Priority 2.

--ryan.

On 2013-07-14 08:16:15 +0000, wrote:

I'm not sure about this, but may it be related to the following bug report by chance? (Sample code is currently attached there.)

https://bugzilla.libsdl.org/show_bug.cgi?id=1868

On 2013-07-16 12:36:58 +0000, David Gow wrote:

It's a bit late at night here, so I might be missing something, but why are you calling SDL_SetWindowSize in response to SDL_WINDOWEVENT_RESIZED events? By the time you've got the message, the window should be set up with the correct size.

If you need to update state based on the window's size changing, you can always listen for both SDL_WINDOWEVENT_RESIZED and SDL_WINDOWEVENT_SIZE_CHANGED to get the new size. You'll get a SIZE_CHANGED event even when you call SDL_SetWindowSize.

-- David

On 2013-07-16 12:52:53 +0000, wrote:

I admit I may be doing something wrong, but I thought SDL_WINDOWEVENT_RESIZED was triggered like the old SDL 1.2 SDL_VIDEORESIZE event: when a window manager was resized the event was sent and you were supposed to use SDL_SetVideoMode() on the new size given in the event.

Similarly I've been using the SDL2 event and call SDL_SetWindowSize() on the new size. Are you saying that this is not the case anymore?

On 2013-07-16 13:00:37 +0000, David Gow wrote:

I'm far from an expert on the SDL2 render API, but you certainly don't need to do anything other than change your viewport when using OpenGL. I suspect the Render API will handle everything for you (if not, it has a SDL_RenderSetViewport function, which is probably the right thing to call), though if you're using SDL_GetWindowSurface, I think you'll need to call that every time the window is resized as you might get a new surface.

Try it and see!

-- David

On 2013-10-22 14:42:05 +0000, Alex Szpakowski wrote:

Indeed, SDL_WINDOWEVENT_RESIZED is (in theory) only triggered when the window actually resizes. Calling SDL_SetWindowSize in response to that event is (in theory) redundant.

There's a bug exclusive to Windows when exiting fullscreen where the window won't resize back to its original size properly, even though it still sends an SDL_WINDOWEVENT_RESIZED event: https://bugzilla.libsdl.org/show_bug.cgi?id=2067
But that's just a bug, and it doesn't happen on other platforms.

On 2013-10-22 15:17:14 +0000, wrote:

The problem is that I have an OpenGL game and if the window manager resizes the window (and thus triggers that event), I need to scale everything inside in response (because the resize was not triggered by the game, rather the WM).

Are you saying I'm not supposed to use SDL_WINDOWEVENT_RESIZED? I need to get the dimensions of the newly resized window somehow (which end up being wrong on Windows/OSX).

I understand that this would be unnecessary if the game video mode was only changeable within the game (completely controlled from the game), but our game is scalable and users use the window manager outline to set the size - which is a nice feature for a pure-OpenGL game.

On 2013-10-22 15:23:55 +0000, Alex Szpakowski wrote:

You should definitely use SDL_WINDOWEVENT_RESIZED to change your game's behaviour to match the new window size, e.g. call glViewport again and re-create resources (textures used as render targets and such) at the appropriate size.

You shouldn't call SDL_SetWindowSize in response to SDL_WINDOWEVENT_RESIZED, because a window size change is what triggers the event in the first place. SDL is telling you "the window has been resized", not "the window should be resized".

On 2013-10-22 18:56:29 +0000, wrote:

I guess the assumption is that you don't need an event if you're the one calling SDL_SetWindowSize. You already know what the window size is going to be. The outdated resized event is a bit irritating, I guess.

Like mentioned above, if you always want an event, use SDL_WINDOWEVENT_SIZE_CHANGED.

This got a lot more complicated with the window limits that got added sometime before the 2.0.0 release and I think the logic in SDL_SetWindowSize has to be looked at again. It would also be helpful if there's some guideline if this function always overrides the window limits (user-set and/or system defaults) or if it has to respect them.

On 2013-11-11 01:29:30 +0000, Sam Lantinga wrote:

Just to recap, you should listen to SDL_WINDOWEVENT_SIZE_CHANGED if you just want to update your OpenGL state whenever the window size changes for any reason.

I just added code to respect the window min/max size in the SDL_SetWindowSize() call, and you can call it to change the windowed size anytime.

On 2013-11-15 06:38:21 +0000, wrote:

Yes. OK.

I finally figured out the discrepancy-

We support both SDL 1.2 and 2.0 (because of trying to be compatible with most Linux distros). Because of this, we handle the special case of resizing a window in window mode via SDL_VIDEORESIZE (in 1.2); however, I had thought that I could do the same with SDL_WINDOWEVENT_RESIZED (in 2.0), but it turns out that this new event is triggered much more frequently, not just in the case of resizing a windowed window.

To make it more like the 1.2 behavior, we now call SDL_FlushEvent(SDL_WINDOWEVENT) whenever we call SDL_SetWindowSize to go to full screen, so it doesn't trigger the SDL_WINDOWEVENT_RESIZED event, which is now triggered only on manually resizing a window.

When we do move to SDL 2.0-only, I'll consolidate the logic appropriately to use SDL_WINDOWEVENT_SIZE_CHANGED.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant