NoGUI/SDL: Implement pause on focus loss

This commit is contained in:
Connor McLaughlin 2021-05-11 15:14:03 +10:00
parent ab0364eb8f
commit 8e9fbf63a3
2 changed files with 35 additions and 5 deletions

View file

@ -1,4 +1,5 @@
#include "sdl_host_interface.h" #include "sdl_host_interface.h"
#include "core/system.h"
#include "frontend-common/controller_interface.h" #include "frontend-common/controller_interface.h"
#include "frontend-common/fullscreen_ui.h" #include "frontend-common/fullscreen_ui.h"
#include "frontend-common/icon.h" #include "frontend-common/icon.h"
@ -276,13 +277,41 @@ void SDLHostInterface::HandleSDLEvent(const SDL_Event* event)
{ {
case SDL_WINDOWEVENT: case SDL_WINDOWEVENT:
{ {
if (event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED) switch (event->window.event)
{
case SDL_WINDOWEVENT_SIZE_CHANGED:
{ {
s32 window_width, window_height; s32 window_width, window_height;
SDL_GetWindowSize(m_window, &window_width, &window_height); SDL_GetWindowSize(m_window, &window_width, &window_height);
m_display->ResizeRenderWindow(window_width, window_height); m_display->ResizeRenderWindow(window_width, window_height);
OnHostDisplayResized(); OnHostDisplayResized();
} }
break;
case SDL_WINDOWEVENT_FOCUS_LOST:
{
if (!m_was_paused_by_focus_loss && !System::IsPaused())
{
PauseSystem(true);
m_was_paused_by_focus_loss = true;
}
}
break;
case SDL_WINDOWEVENT_FOCUS_GAINED:
{
if (m_was_paused_by_focus_loss)
{
if (System::IsPaused())
PauseSystem(false);
m_was_paused_by_focus_loss = false;
}
}
break;
default:
break;
}
} }
break; break;

View file

@ -34,4 +34,5 @@ private:
SDL_Window* m_window = nullptr; SDL_Window* m_window = nullptr;
bool m_fullscreen = false; bool m_fullscreen = false;
bool m_was_paused_by_focus_loss = false;
}; };