mirror of
https://github.com/citra-emu/citra.git
synced 2024-11-25 09:40:15 +00:00
Implement pause on focus lost for SDL frontend
This commit is contained in:
parent
40d59f085f
commit
4e097e05d2
@ -150,6 +150,10 @@ int main(int argc, char **argv) {
|
||||
|
||||
while (emu_window->IsOpen()) {
|
||||
Core::RunLoop();
|
||||
|
||||
// Pause on focus lost
|
||||
if (!emu_window->HasFocus())
|
||||
emu_window->WaitForFocus();
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -50,6 +50,10 @@ bool EmuWindow_SDL2::IsOpen() const {
|
||||
return is_open;
|
||||
}
|
||||
|
||||
bool EmuWindow_SDL2::HasFocus() const {
|
||||
return has_focus;
|
||||
}
|
||||
|
||||
void EmuWindow_SDL2::OnResize() {
|
||||
int width, height;
|
||||
|
||||
@ -58,6 +62,24 @@ void EmuWindow_SDL2::OnResize() {
|
||||
NotifyFramebufferLayoutChanged(EmuWindow::FramebufferLayout::DefaultScreenLayout(width, height));
|
||||
}
|
||||
|
||||
void EmuWindow_SDL2::WaitForFocus() {
|
||||
while(!has_focus) {
|
||||
SDL_Event event;
|
||||
SDL_WaitEvent(&event);
|
||||
if(event.type == SDL_WINDOWEVENT) {
|
||||
switch (event.window.event) {
|
||||
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
||||
has_focus=true;
|
||||
break;
|
||||
case SDL_WINDOWEVENT_CLOSE:
|
||||
has_focus=true;
|
||||
is_open = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EmuWindow_SDL2::EmuWindow_SDL2() {
|
||||
keyboard_id = KeyMap::NewDeviceId();
|
||||
|
||||
@ -136,6 +158,12 @@ void EmuWindow_SDL2::PollEvents() {
|
||||
case SDL_WINDOWEVENT_MINIMIZED:
|
||||
OnResize();
|
||||
break;
|
||||
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
||||
has_focus = true;
|
||||
break;
|
||||
case SDL_WINDOWEVENT_FOCUS_LOST:
|
||||
has_focus = false;
|
||||
break;
|
||||
case SDL_WINDOWEVENT_CLOSE:
|
||||
is_open = false;
|
||||
break;
|
||||
|
@ -30,6 +30,12 @@ public:
|
||||
/// Whether the window is still open, and a close request hasn't yet been sent
|
||||
bool IsOpen() const;
|
||||
|
||||
/// Whether the window has focus
|
||||
bool HasFocus() const;
|
||||
|
||||
/// Wait for the window to gain focus
|
||||
void WaitForFocus();
|
||||
|
||||
/// Load keymap from configuration
|
||||
void ReloadSetKeymaps() override;
|
||||
|
||||
@ -52,6 +58,9 @@ private:
|
||||
/// Is the window still open?
|
||||
bool is_open = true;
|
||||
|
||||
/// Is the window has focus
|
||||
bool has_focus = true;
|
||||
|
||||
/// Internal SDL2 render window
|
||||
SDL_Window* render_window;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user