From 11e8a91e3049ed32e56e93abd58f6cd7aca82986 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sun, 5 Apr 2020 22:58:54 +1000 Subject: [PATCH] CommonHostInterface: Simplify fullscreen toggle --- src/duckstation-qt/qthostinterface.cpp | 18 +++++++++--------- src/duckstation-qt/qthostinterface.h | 4 ++-- src/frontend-common/common_host_interface.cpp | 19 ++++++++++--------- src/frontend-common/common_host_interface.h | 4 ++-- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/duckstation-qt/qthostinterface.cpp b/src/duckstation-qt/qthostinterface.cpp index 2a01e17ab..9e026c816 100644 --- a/src/duckstation-qt/qthostinterface.cpp +++ b/src/duckstation-qt/qthostinterface.cpp @@ -278,7 +278,7 @@ void QtHostInterface::toggleFullscreen() return; } - ToggleFullscreen(); + SetFullscreen(!m_is_fullscreen); } bool QtHostInterface::AcquireHostDisplay() @@ -317,19 +317,19 @@ void QtHostInterface::ReleaseHostDisplay() emit destroyDisplayWindowRequested(); } -void QtHostInterface::SetFullscreen(bool enabled) +bool QtHostInterface::IsFullscreen() const +{ + return m_is_fullscreen; +} + +bool QtHostInterface::SetFullscreen(bool enabled) { if (m_is_fullscreen == enabled) - return; + return true; m_is_fullscreen = enabled; emit updateDisplayWindowRequested(m_is_fullscreen, m_is_rendering_to_main); -} - -void QtHostInterface::ToggleFullscreen() -{ - m_is_fullscreen = !m_is_fullscreen; - emit updateDisplayWindowRequested(m_is_fullscreen, m_is_rendering_to_main); + return true; } std::optional QtHostInterface::GetHostKeyCode(const std::string_view key_code) const diff --git a/src/duckstation-qt/qthostinterface.h b/src/duckstation-qt/qthostinterface.h index b82115245..2c768c289 100644 --- a/src/duckstation-qt/qthostinterface.h +++ b/src/duckstation-qt/qthostinterface.h @@ -120,8 +120,8 @@ private Q_SLOTS: protected: bool AcquireHostDisplay() override; void ReleaseHostDisplay() override; - void SetFullscreen(bool enabled) override; - void ToggleFullscreen() override; + bool IsFullscreen() const override; + bool SetFullscreen(bool enabled) override; std::optional GetHostKeyCode(const std::string_view key_code) const override; diff --git a/src/frontend-common/common_host_interface.cpp b/src/frontend-common/common_host_interface.cpp index 32b0ed2fc..010f203dc 100644 --- a/src/frontend-common/common_host_interface.cpp +++ b/src/frontend-common/common_host_interface.cpp @@ -51,9 +51,15 @@ void CommonHostInterface::Shutdown() } } -void CommonHostInterface::SetFullscreen(bool enabled) {} +bool CommonHostInterface::IsFullscreen() const +{ + return false; +} -void CommonHostInterface::ToggleFullscreen() {} +bool CommonHostInterface::SetFullscreen(bool enabled) +{ + return false; +} std::unique_ptr CommonHostInterface::CreateAudioStream(AudioBackend backend) { @@ -88,19 +94,14 @@ std::unique_ptr CommonHostInterface::CreateControllerInterf void CommonHostInterface::OnSystemCreated() { HostInterface::OnSystemCreated(); - - if (m_settings.start_fullscreen) - SetFullscreen(true); } void CommonHostInterface::OnSystemPaused(bool paused) { HostInterface::OnSystemPaused(paused); - if (paused) + if (paused && IsFullscreen()) SetFullscreen(false); - else if (m_settings.start_fullscreen) - SetFullscreen(true); } void CommonHostInterface::OnControllerTypeChanged(u32 slot) @@ -375,7 +376,7 @@ void CommonHostInterface::RegisterGeneralHotkeys() RegisterHotkey(StaticString("General"), StaticString("ToggleFullscreen"), StaticString("Toggle Fullscreen"), [this](bool pressed) { if (!pressed) - ToggleFullscreen(); + SetFullscreen(!IsFullscreen()); }); RegisterHotkey(StaticString("General"), StaticString("TogglePause"), StaticString("Toggle Pause"), diff --git a/src/frontend-common/common_host_interface.h b/src/frontend-common/common_host_interface.h index 0128552dc..dafe2515d 100644 --- a/src/frontend-common/common_host_interface.h +++ b/src/frontend-common/common_host_interface.h @@ -46,8 +46,8 @@ protected: CommonHostInterface(); ~CommonHostInterface(); - virtual void SetFullscreen(bool enabled); - virtual void ToggleFullscreen(); + virtual bool IsFullscreen() const; + virtual bool SetFullscreen(bool enabled); virtual std::unique_ptr CreateAudioStream(AudioBackend backend) override; virtual std::unique_ptr CreateControllerInterface();