SDLApplication: fix inconsistent setting of inBackground flag when dispatching WINDOW_DEACTIVATE and WINDOW_ACTIVATE (closes openfl/openfl#2645)

On SDL_APP_WILLENTERBACKGROUND and SDL_APP_DIDENTERFOREGROUND, inBackground was being toggled, but it was not toggled on SDL_WINDOWEVENT_SHOWN and SDL_WINDOWEVENT_HIDDEN. However, both pairs were dispatching WINDOW_DEACTIVATE and WINDOW_ACTIVATE from C++ to Haxe. When inBackground wasn't toggled, the UPDATE ApplicationEvent continued being dispatched from the C++, but the Haxe assumed that it wouldn't be. This meant that timers were still updated after WINDOW_DEACTIVATE for SDL_WINDOWEVENT_HIDDEN, but then they were still "advanced" as if paused on WINDOW_ACTIVATE for SDL_WINDOWEVENT_SHOWN. The next update time would be some time in the future, roughly equal to how long the Haxe thought the timers were paused. This could make it seem like the timers completed stopped updating, especially if they should have been paused for a long time. They would eventually continue, but they should have paused on WINDOW_DEACTIVATE and continued immediately on WINDOW_ACTIVATE.
This commit is contained in:
Josh Tynjala
2023-06-05 14:22:16 -07:00
parent 5634ad72d2
commit 0918ee2381

View File

@@ -766,7 +766,12 @@ namespace lime {
case SDL_WINDOWEVENT_SHOWN: windowEvent.type = WINDOW_ACTIVATE; break;
case SDL_WINDOWEVENT_CLOSE: windowEvent.type = WINDOW_CLOSE; break;
case SDL_WINDOWEVENT_HIDDEN: windowEvent.type = WINDOW_DEACTIVATE; break;
case SDL_WINDOWEVENT_HIDDEN:
inBackground = true;
windowEvent.type = WINDOW_DEACTIVATE;
break;
case SDL_WINDOWEVENT_ENTER: windowEvent.type = WINDOW_ENTER; break;
case SDL_WINDOWEVENT_FOCUS_GAINED: windowEvent.type = WINDOW_FOCUS_IN; break;
case SDL_WINDOWEVENT_FOCUS_LOST: windowEvent.type = WINDOW_FOCUS_OUT; break;
@@ -796,6 +801,15 @@ namespace lime {
windowEvent.windowID = event->window.windowID;
WindowEvent::Dispatch (&windowEvent);
switch (event->window.event) {
case SDL_WINDOWEVENT_SHOWN:
inBackground = false;
break;
}
}
}