From 8f39a0f15446cde2988ebf5d8c50a89f96659f99 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Thu, 12 Mar 2020 13:53:58 +1000 Subject: [PATCH] Qt: Properly implement "Start Fullscreen" --- src/core/host_interface.cpp | 2 +- src/core/settings.cpp | 4 +-- src/core/settings.h | 2 +- src/duckstation-qt/consolesettingswidget.cpp | 1 + src/duckstation-qt/consolesettingswidget.ui | 9 ++++++- src/duckstation-qt/gpusettingswidget.cpp | 1 - src/duckstation-qt/gpusettingswidget.ui | 7 ----- src/duckstation-qt/mainwindow.cpp | 5 ++++ src/duckstation-qt/qthostinterface.cpp | 26 +++++++++++-------- src/duckstation-sdl/sdl_host_interface.cpp | 6 ++--- src/frontend-common/common_host_interface.cpp | 23 ++++++++++++---- src/frontend-common/common_host_interface.h | 3 +++ 12 files changed, 56 insertions(+), 33 deletions(-) diff --git a/src/core/host_interface.cpp b/src/core/host_interface.cpp index c5f480e9e..8f861ab0b 100644 --- a/src/core/host_interface.cpp +++ b/src/core/host_interface.cpp @@ -113,7 +113,7 @@ bool HostInterface::BootSystem(const SystemBootParameters& parameters) void HostInterface::PauseSystem(bool paused) { - if (paused == m_paused) + if (paused == m_paused || !m_system) return; m_paused = paused; diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 27bf23e45..c9ca7c9c8 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -13,6 +13,7 @@ void Settings::Load(SettingsInterface& si) speed_limiter_enabled = si.GetBoolValue("Main", "SpeedLimiterEnabled", true); increase_timer_resolution = si.GetBoolValue("Main", "IncreaseTimerResolution", true); start_paused = si.GetBoolValue("Main", "StartPaused", false); + start_fullscreen = si.GetBoolValue("Main", "StartFullscreen", false); save_state_on_exit = si.GetBoolValue("Main", "SaveStateOnExit", true); confim_power_off = si.GetBoolValue("Main", "ConfirmPowerOff", true); @@ -32,7 +33,6 @@ void Settings::Load(SettingsInterface& si) .value_or(DisplayCropMode::None); display_force_progressive_scan = si.GetBoolValue("Display", "ForceProgressiveScan", true); display_linear_filtering = si.GetBoolValue("Display", "LinearFiltering", true); - display_fullscreen = si.GetBoolValue("Display", "Fullscreen", false); video_sync_enabled = si.GetBoolValue("Display", "VSync", true); cdrom_read_thread = si.GetBoolValue("CDROM", "ReadThread", true); @@ -71,6 +71,7 @@ void Settings::Save(SettingsInterface& si) const si.SetBoolValue("Main", "SpeedLimiterEnabled", speed_limiter_enabled); si.SetBoolValue("Main", "IncreaseTimerResolution", increase_timer_resolution); si.SetBoolValue("Main", "StartPaused", start_paused); + si.SetBoolValue("Main", "StartFullscreen", start_fullscreen); si.SetBoolValue("Main", "SaveStateOnExit", save_state_on_exit); si.SetBoolValue("Main", "ConfirmPowerOff", confim_power_off); @@ -85,7 +86,6 @@ void Settings::Save(SettingsInterface& si) const si.SetBoolValue("Display", "ForceProgressiveScan", display_force_progressive_scan); si.SetBoolValue("Display", "LinearFiltering", display_linear_filtering); - si.SetBoolValue("Display", "Fullscreen", display_fullscreen); si.SetBoolValue("Display", "VSync", video_sync_enabled); si.SetBoolValue("CDROM", "ReadThread", cdrom_read_thread); diff --git a/src/core/settings.h b/src/core/settings.h index bc7af795c..0bbf0bfa0 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -41,6 +41,7 @@ struct Settings bool speed_limiter_enabled = true; bool increase_timer_resolution = true; bool start_paused = false; + bool start_fullscreen = false; bool save_state_on_exit = true; bool confim_power_off = true; @@ -53,7 +54,6 @@ struct Settings DisplayCropMode display_crop_mode = DisplayCropMode::None; bool display_force_progressive_scan = false; bool display_linear_filtering = true; - bool display_fullscreen = false; bool video_sync_enabled = true; bool cdrom_read_thread = true; diff --git a/src/duckstation-qt/consolesettingswidget.cpp b/src/duckstation-qt/consolesettingswidget.cpp index d32f79b46..181a33a12 100644 --- a/src/duckstation-qt/consolesettingswidget.cpp +++ b/src/duckstation-qt/consolesettingswidget.cpp @@ -26,6 +26,7 @@ ConsoleSettingsWidget::ConsoleSettingsWidget(QtHostInterface* host_interface, QW SettingWidgetBinder::BindWidgetToNormalizedSetting(m_host_interface, m_ui.emulationSpeed, "Main/EmulationSpeed", 100.0f); SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.pauseOnStart, "Main/StartPaused"); + SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.startFullscreen, "Main/StartFullscreen"); SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.saveStateOnExit, "Main/SaveStateOnExit"); SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.confirmPowerOff, "Main/ConfirmPowerOff"); SettingWidgetBinder::BindWidgetToEnumSetting(m_host_interface, m_ui.cpuExecutionMode, "CPU/ExecutionMode", diff --git a/src/duckstation-qt/consolesettingswidget.ui b/src/duckstation-qt/consolesettingswidget.ui index 2f4e65ed9..03ad78461 100644 --- a/src/duckstation-qt/consolesettingswidget.ui +++ b/src/duckstation-qt/consolesettingswidget.ui @@ -154,13 +154,20 @@ + + + Start Fullscreen + + + + Save State On Exit - + Confirm Power Off diff --git a/src/duckstation-qt/gpusettingswidget.cpp b/src/duckstation-qt/gpusettingswidget.cpp index c97def9bc..3ac7026b4 100644 --- a/src/duckstation-qt/gpusettingswidget.cpp +++ b/src/duckstation-qt/gpusettingswidget.cpp @@ -18,7 +18,6 @@ GPUSettingsWidget::GPUSettingsWidget(QtHostInterface* host_interface, QWidget* p "Display/ForceProgressiveScan"); SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.displayLinearFiltering, "Display/LinearFiltering"); - SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.startFullscreen, "Display/Fullscreen"); SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.vsync, "Display/VSync"); SettingWidgetBinder::BindWidgetToIntSetting(m_host_interface, m_ui.resolutionScale, "GPU/ResolutionScale"); SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.trueColor, "GPU/TrueColor"); diff --git a/src/duckstation-qt/gpusettingswidget.ui b/src/duckstation-qt/gpusettingswidget.ui index 8273db9ab..2f0bd235f 100644 --- a/src/duckstation-qt/gpusettingswidget.ui +++ b/src/duckstation-qt/gpusettingswidget.ui @@ -83,13 +83,6 @@ - - - Start Fullscreen - - - - VSync diff --git a/src/duckstation-qt/mainwindow.cpp b/src/duckstation-qt/mainwindow.cpp index 48ab401ef..30ac66ff1 100644 --- a/src/duckstation-qt/mainwindow.cpp +++ b/src/duckstation-qt/mainwindow.cpp @@ -10,6 +10,7 @@ #include "qtsettingsinterface.h" #include "settingsdialog.h" #include "settingwidgetbinder.h" +#include #include #include #include @@ -38,6 +39,7 @@ MainWindow::~MainWindow() void MainWindow::reportError(const QString& message) { QMessageBox::critical(this, tr("DuckStation"), message, QMessageBox::Ok); + focusDisplayWidget(); } void MainWindow::reportMessage(const QString& message) @@ -88,6 +90,9 @@ void MainWindow::destroyDisplayWindow() void MainWindow::setFullscreen(bool fullscreen) { + if (fullscreen == m_display_widget->isFullScreen()) + return; + if (fullscreen) { m_ui.mainContainer->setCurrentIndex(0); diff --git a/src/duckstation-qt/qthostinterface.cpp b/src/duckstation-qt/qthostinterface.cpp index 3bfb99216..927d3f93c 100644 --- a/src/duckstation-qt/qthostinterface.cpp +++ b/src/duckstation-qt/qthostinterface.cpp @@ -48,7 +48,11 @@ void QtHostInterface::ReportError(const char* message) { HostInterface::ReportError(message); + emit setFullscreenRequested(false); emit errorReported(QString::fromLocal8Bit(message)); + + if (m_settings.start_fullscreen) + emit setFullscreenRequested(true); } void QtHostInterface::ReportMessage(const char* message) @@ -60,7 +64,14 @@ void QtHostInterface::ReportMessage(const char* message) bool QtHostInterface::ConfirmMessage(const char* message) { - return messageConfirmed(QString::fromLocal8Bit(message)); + emit setFullscreenRequested(false); + + const bool result = messageConfirmed(QString::fromLocal8Bit(message)); + + if (m_settings.start_fullscreen) + emit setFullscreenRequested(true); + + return result; } QVariant QtHostInterface::getSettingValue(const QString& name, const QVariant& default_value) @@ -251,7 +262,7 @@ std::optional QtHostInterface::GetHostKeyCode( void QtHostInterface::OnSystemCreated() { - HostInterface::OnSystemCreated(); + CommonHostInterface::OnSystemCreated(); wakeThread(); destroyBackgroundControllerPollTimer(); @@ -261,7 +272,7 @@ void QtHostInterface::OnSystemCreated() void QtHostInterface::OnSystemPaused(bool paused) { - HostInterface::OnSystemPaused(paused); + CommonHostInterface::OnSystemPaused(paused); emit emulationPaused(paused); @@ -392,14 +403,7 @@ void QtHostInterface::pauseSystem(bool paused) return; } - if (!m_system) - return; - - m_paused = paused; - m_audio_stream->PauseOutput(paused); - if (!paused) - wakeThread(); - emit emulationPaused(paused); + CommonHostInterface::PauseSystem(paused); } void QtHostInterface::changeDisc(const QString& new_disc_filename) diff --git a/src/duckstation-sdl/sdl_host_interface.cpp b/src/duckstation-sdl/sdl_host_interface.cpp index 07a21da43..1fe305351 100644 --- a/src/duckstation-sdl/sdl_host_interface.cpp +++ b/src/duckstation-sdl/sdl_host_interface.cpp @@ -301,7 +301,7 @@ std::unique_ptr SDLHostInterface::Create() INISettingsInterface si(intf->GetSettingsFileName().c_str()); intf->m_settings_copy.Load(si); intf->m_settings = intf->m_settings_copy; - intf->m_fullscreen = intf->m_settings_copy.display_fullscreen; + intf->m_fullscreen = intf->m_settings_copy.start_fullscreen; if (!intf->CreateSDLWindow()) { @@ -1105,6 +1105,7 @@ void SDLHostInterface::DrawSettingsWindow() settings_changed |= ImGui::Checkbox("Enable Speed Limiter", &m_settings_copy.speed_limiter_enabled); settings_changed |= ImGui::Checkbox("Increase Timer Resolution", &m_settings_copy.increase_timer_resolution); settings_changed |= ImGui::Checkbox("Pause On Start", &m_settings_copy.start_paused); + settings_changed |= ImGui::Checkbox("Start Fullscreen", &m_settings_copy.start_fullscreen); settings_changed |= ImGui::Checkbox("Save State On Exit", &m_settings_copy.save_state_on_exit); } @@ -1246,9 +1247,6 @@ void SDLHostInterface::DrawSettingsWindow() settings_changed = true; } - if (ImGui::Checkbox("Start Fullscreen", &m_settings_copy.display_fullscreen)) - settings_changed = true; - settings_changed |= ImGui::Checkbox("Use Debug Device", &m_settings_copy.gpu_use_debug_device); settings_changed |= ImGui::Checkbox("Linear Filtering", &m_settings_copy.display_linear_filtering); settings_changed |= ImGui::Checkbox("VSync", &m_settings_copy.video_sync_enabled); diff --git a/src/frontend-common/common_host_interface.cpp b/src/frontend-common/common_host_interface.cpp index 1c097996e..8d4be880e 100644 --- a/src/frontend-common/common_host_interface.cpp +++ b/src/frontend-common/common_host_interface.cpp @@ -47,6 +47,24 @@ std::unique_ptr CommonHostInterface::CreateAudioStream(AudioBackend } } +void CommonHostInterface::OnSystemCreated() +{ + HostInterface::OnSystemCreated(); + + if (m_settings.start_fullscreen) + SetFullscreen(true); +} + +void CommonHostInterface::OnSystemPaused(bool paused) +{ + HostInterface::OnSystemPaused(paused); + + if (paused) + SetFullscreen(false); + else if (m_settings.start_fullscreen) + SetFullscreen(true); +} + void CommonHostInterface::SetDefaultSettings(SettingsInterface& si) { HostInterface::SetDefaultSettings(si); @@ -319,17 +337,12 @@ void CommonHostInterface::RegisterGeneralHotkeys() { if (m_settings.confim_power_off) { - SetFullscreen(false); - SmallString confirmation_message("Are you sure you want to stop emulation?"); if (m_settings.save_state_on_exit) confirmation_message.AppendString("\n\nThe current state will be saved."); if (!ConfirmMessage(confirmation_message)) { - if (m_settings.display_fullscreen) - SetFullscreen(true); - m_system->ResetPerformanceCounters(); return; } diff --git a/src/frontend-common/common_host_interface.h b/src/frontend-common/common_host_interface.h index 54437765c..6afdeb3b1 100644 --- a/src/frontend-common/common_host_interface.h +++ b/src/frontend-common/common_host_interface.h @@ -41,6 +41,9 @@ protected: virtual std::unique_ptr CreateAudioStream(AudioBackend backend) override; + virtual void OnSystemCreated() override; + virtual void OnSystemPaused(bool paused) override; + virtual void SetDefaultSettings(SettingsInterface& si) override; virtual std::optional GetHostKeyCode(const std::string_view key_code) const;