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 3395

Summary: SDL_WINDOWEVENT_FOCUS_GAINED not fired at startup on iOS
Product: SDL Reporter: mlunar
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: amaranth72
Version: 2.0.4   
Hardware: iPhone/iPod touch   
OS: iOS (All)   

Description mlunar 2016-07-26 00:05:53 UTC
Windows, Android and OS X all fire the `SDL_WINDOWEVENT_FOCUS_GAINED` event when the app first opens, however this isn't the case on iOS.

SDL correctly hooks the `applicationDidBecomeActive` iOS event for it in `SDL_uikitappdelegate.m`, however the iOS event gets fired very soon in the startup procedure, before `SDL_GetVideoDevice()` returns a valid video device and before any windows exist. Since SDL needs both to fire the event, it simply doesn't fire it, making it inconsistent with the other tested platforms.

If this is expected behavior, it would be good to document it, however I would prefer making it consistent with the others.

I don't know enough about SDL internals to say whether there's an easy fix for this, but the iOS event could either be remembered and then an SDL event would be fired when a window first becomes available or the SDL event could be manually fired on startup. I don't particularly like either of these solutions, maybe a reordering of some code would help.

A workaround to this issue is listening to the `SDL_APP_DIDENTERFOREGROUND` and `SDL_APP_WILLENTERBACKGROUND` events instead of `SDL_WINDOWEVENT_FOCUS_GAINED` and `SDL_WINDOWEVENT_FOCUS_LOST` on iOS, since they get fired from the same events and aren't conditional on the window or video device existing.
Comment 1 Alex Szpakowski 2016-09-24 23:13:45 UTC
https://hg.libsdl.org/SDL/rev/e88a4e5539e5 should fix this. Thanks for the report!