diff --git a/BBGE/Core.cpp b/BBGE/Core.cpp index d25dff0..a4e6ae0 100644 --- a/BBGE/Core.cpp +++ b/BBGE/Core.cpp @@ -1063,7 +1063,6 @@ void Core::run(float runTime) { if (isWindowFocus()) { - _hasFocus = true; if (wasInactive) { debugLog("WINDOW ACTIVE"); @@ -1073,37 +1072,33 @@ void Core::run(float runTime) } else { - if (_hasFocus) + if (!wasInactive) + debugLog("WINDOW INACTIVE"); + + wasInactive = true; + updateInputGrab(); + sound->pause(); + + while (!isWindowFocus()) { - if (!wasInactive) - debugLog("WINDOW INACTIVE"); + pollEvents(dt); - wasInactive = true; - _hasFocus = false; - updateInputGrab(); - sound->pause(); - - while (!isWindowFocus()) - { - pollEvents(dt); - - onBackgroundUpdate(); - - resetTimer(); - } - - debugLog("app back in focus"); + onBackgroundUpdate(); resetTimer(); - - sound->resume(); - - resetTimer(); - - SDL_ShowCursor(SDL_DISABLE); - - continue; } + + debugLog("app back in focus"); + + resetTimer(); + + sound->resume(); + + resetTimer(); + + SDL_ShowCursor(SDL_DISABLE); + + continue; } } #endif diff --git a/BBGE/Window_SDL1.cpp b/BBGE/Window_SDL1.cpp index 88ce0dd..a107e2c 100644 --- a/BBGE/Window_SDL1.cpp +++ b/BBGE/Window_SDL1.cpp @@ -123,6 +123,9 @@ void Window::_onEventImpl(const SDL_Event& ev) case SDL_VIDEORESIZE: onResize(ev.resize.w, ev.resize.h); break; + + case SDL_ACTIVEEVENT: + _hasFocus = ev.active.state; } }