Qt: Add option to hide main window when game running

This commit is contained in:
Connor McLaughlin 2022-06-28 21:37:30 +10:00 committed by refractionpcsx2
parent 1f3f70a642
commit b6f748ad8f
8 changed files with 81 additions and 32 deletions

View File

@ -108,7 +108,7 @@ void EmuThread::startVM(std::shared_ptr<VMBootParameters> boot_params)
// create the display, this may take a while...
m_is_fullscreen = boot_params->fullscreen.value_or(Host::GetBaseBoolSettingValue("UI", "StartFullscreen", false));
m_is_rendering_to_main = Host::GetBaseBoolSettingValue("UI", "RenderToMainWindow", true);
m_is_rendering_to_main = !Host::GetBaseBoolSettingValue("UI", "RenderToSeparateWindow", false);
m_is_surfaceless = false;
m_save_state_on_shutdown = false;
if (!VMManager::Initialize(*boot_params))
@ -433,7 +433,7 @@ void EmuThread::checkForSettingChanges()
if (VMManager::HasValidVM())
{
const bool render_to_main = Host::GetBaseBoolSettingValue("UI", "RenderToMainWindow", true);
const bool render_to_main = !Host::GetBaseBoolSettingValue("UI", "RenderToSeparateWindow", false);
if (!m_is_fullscreen && m_is_rendering_to_main != render_to_main)
{
m_is_rendering_to_main = render_to_main;

View File

@ -43,6 +43,7 @@ public:
__fi QEventLoop* getEventLoop() const { return m_event_loop; }
__fi bool isFullscreen() const { return m_is_fullscreen; }
__fi bool isRenderingToMain() const { return m_is_rendering_to_main; }
bool isOnEmuThread() const;

View File

@ -728,6 +728,16 @@ void MainWindow::updateWindowTitle()
}
}
void MainWindow::updateWindowVisibility()
{
// Need to test both valid and display widget because of startup (vm invalid while window is created).
const bool hide_window = !g_emu_thread->isRenderingToMain() && Host::GetBaseBoolSettingValue("UI", "HideMainWindowWhenRunning", false);
const bool new_state = !hide_window || (!m_vm_valid && !m_display_widget);
if (isVisible() != new_state)
setVisible(new_state);
}
void MainWindow::setProgressBar(int current, int total)
{
m_status_progress_widget->setValue(current);
@ -847,7 +857,7 @@ void MainWindow::runOnUIThread(const std::function<void()>& func)
bool MainWindow::requestShutdown(bool allow_confirm /* = true */, bool allow_save_to_state /* = true */, bool block_until_done /* = false */)
{
if (!VMManager::HasValidVM())
if (!m_vm_valid)
return true;
// If we don't have a crc, we can't save state.
@ -880,6 +890,15 @@ bool MainWindow::requestShutdown(bool allow_confirm /* = true */, bool allow_sav
lock.cancelResume();
}
// This is a little bit annoying. Qt will close everything down if we don't have at least one window visible,
// but we might not be visible because the user is using render-to-separate and hide. We don't want to always
// reshow the main window during display updates, because otherwise fullscreen transitions and renderer switches
// would briefly show and then hide the main window. So instead, we do it on shutdown, here. Except if we're in
// batch mode, when we're going to exit anyway.
if (!isRenderingToMain() && isHidden() && !QtHost::InBatchMode())
show();
// Now we can actually shut down the VM.
g_emu_thread->shutdownVM(save_state);
if (block_until_done || QtHost::InBatchMode())
@ -911,6 +930,8 @@ void MainWindow::checkForSettingChanges()
{
if (m_display_widget)
m_display_widget->updateRelativeMode(m_vm_valid && !m_vm_paused);
updateWindowVisibility();
}
void Host::InvalidateSaveStateCache()
@ -1405,6 +1426,7 @@ void MainWindow::onVMStopped()
m_last_fps_status = QString();
updateEmulationActions(false, false);
updateWindowTitle();
updateWindowVisibility();
updateStatusBarWidgetVisibility();
if (m_display_widget)
@ -1586,8 +1608,9 @@ DisplayWidget* MainWindow::createDisplay(bool fullscreen, bool render_to_main)
setDisplayFullscreen(fullscreen_mode);
updateWindowTitle();
m_display_widget->setFocus();
updateWindowVisibility();
m_display_widget->setFocus();
m_display_widget->setShouldHideCursor(shouldHideMouseCursor());
m_display_widget->updateRelativeMode(m_vm_valid && !m_vm_paused);
m_display_widget->updateCursor(m_vm_valid && !m_vm_paused);
@ -1718,6 +1741,8 @@ DisplayWidget* MainWindow::updateDisplay(bool fullscreen, bool render_to_main, b
setDisplayFullscreen(fullscreen_mode);
updateWindowTitle();
updateWindowVisibility();
m_display_widget->setFocus();
m_display_widget->setShouldHideCursor(shouldHideMouseCursor());
m_display_widget->updateRelativeMode(m_vm_valid && !m_vm_paused);
@ -1752,9 +1777,10 @@ void MainWindow::displayResizeRequested(qint32 width, qint32 height)
void MainWindow::destroyDisplay()
{
// Now we can safely destroy the display window.
destroyDisplayWidget();
// switch back to game list view, we're not going back to display, so we can't use switchToGameListView().
// Switch back to game list view, we're not going back to display, so we can't use switchToGameListView().
if (centralWidget() != m_game_list_widget)
{
takeCentralWidget();

View File

@ -179,6 +179,7 @@ private:
void updateEmulationActions(bool starting, bool running);
void updateStatusBarWidgetVisibility();
void updateWindowTitle();
void updateWindowVisibility();
void setProgressBar(int current, int total);
void clearProgressBar();

View File

@ -30,8 +30,7 @@ static const char* THEME_NAMES[] = {
QT_TRANSLATE_NOOP("InterfaceSettingsWidget", "Baby Pastel (Pink) [Light]"),
QT_TRANSLATE_NOOP("InterfaceSettingsWidget", "PCSX2 (White/Blue) [Light]"),
QT_TRANSLATE_NOOP("InterfaceSettingsWidget", "Scarlet Devil (Red/Purple) [Dark]"),
nullptr
};
nullptr};
static const char* THEME_VALUES[] = {
"",
@ -42,8 +41,7 @@ static const char* THEME_VALUES[] = {
"BabyPastel",
"PCSX2Blue",
"ScarletDevilRed",
nullptr
};
nullptr};
InterfaceSettingsWidget::InterfaceSettingsWidget(SettingsDialog* dialog, QWidget* parent)
: QWidget(parent)
@ -62,7 +60,9 @@ InterfaceSettingsWidget::InterfaceSettingsWidget(SettingsDialog* dialog, QWidget
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.doubleClickTogglesFullscreen, "UI", "DoubleClickTogglesFullscreen",
true);
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.hideMouseCursor, "UI", "HideMouseCursor", false);
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.renderToMainWindow, "UI", "RenderToMainWindow", true);
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.renderToSeparateWindow, "UI", "RenderToSeparateWindow", false);
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.hideMainWindow, "UI", "HideMainWindowWhenRunning", false);
connect(m_ui.renderToSeparateWindow, &QCheckBox::stateChanged, this, &InterfaceSettingsWidget::onRenderToSeparateWindowChanged);
SettingWidgetBinder::BindWidgetToEnumSetting(sif, m_ui.theme, "UI", "Theme", THEME_NAMES, THEME_VALUES,
MainWindow::DEFAULT_THEME_NAME);
@ -109,15 +109,24 @@ InterfaceSettingsWidget::InterfaceSettingsWidget(SettingsDialog* dialog, QWidget
dialog->registerWidgetHelp(m_ui.hideMouseCursor, tr("Hide Cursor In Fullscreen"), tr("Checked"),
tr("Hides the mouse pointer/cursor when the emulator is in fullscreen mode."));
dialog->registerWidgetHelp(
m_ui.renderToMainWindow, tr("Render To Main Window"), tr("Checked"),
tr("Renders the display of the simulated console to the main window of the application, over "
"the game list. If unchecked, the display will render in a separate window."));
m_ui.renderToSeparateWindow, tr("Render To Separate Window"), tr("Unchecked"),
tr("Renders the game to a separate window, instead of the main window. If unchecked, the game will display over the top of the game list."));
dialog->registerWidgetHelp(
m_ui.hideMainWindow, tr("Hide Main Window When Running"), tr("Unchecked"),
tr("Hides the main window (with the game list) when a game is running, requires Render To Separate Window to be enabled."));
// Not yet used, disable the options
m_ui.pauseOnStart->setDisabled(true);
m_ui.pauseOnFocusLoss->setDisabled(true);
m_ui.disableWindowResizing->setDisabled(true);
m_ui.language->setDisabled(true);
onRenderToSeparateWindowChanged();
}
InterfaceSettingsWidget::~InterfaceSettingsWidget() = default;
void InterfaceSettingsWidget::onRenderToSeparateWindowChanged()
{
m_ui.hideMainWindow->setEnabled(m_ui.renderToSeparateWindow->isChecked());
}

View File

@ -32,6 +32,9 @@ public:
Q_SIGNALS:
void themeChanged();
private Q_SLOTS:
void onRenderToSeparateWindowChanged();
private:
Ui::InterfaceSettingsWidget m_ui;
};

View File

@ -78,6 +78,13 @@
<layout class="QFormLayout" name="formLayout_3">
<item row="0" column="0" colspan="2">
<layout class="QGridLayout" name="gridLayout_3">
<item row="2" column="0">
<widget class="QCheckBox" name="disableWindowResizing">
<property name="text">
<string>Disable Window Resizing</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="startFullscreen">
<property name="text">
@ -85,20 +92,6 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="hideMouseCursor">
<property name="text">
<string>Hide Cursor In Fullscreen</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="renderToMainWindow">
<property name="text">
<string>Render To Main Window</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="doubleClickTogglesFullscreen">
<property name="text">
@ -106,10 +99,24 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="disableWindowResizing">
<item row="1" column="0">
<widget class="QCheckBox" name="renderToSeparateWindow">
<property name="text">
<string>Disable Window Resizing</string>
<string>Render To Separate Window</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="hideMouseCursor">
<property name="text">
<string>Hide Cursor In Fullscreen</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="hideMainWindow">
<property name="text">
<string>Hide Main Window When Running</string>
</property>
</widget>
</item>

View File

@ -325,7 +325,9 @@
<QtMoc Include="Tools\InputRecording\NewInputRecordingDlg.h">
<Filter>Tools\Input Recording</Filter>
</QtMoc>
<QtMoc Include="Settings\FolderSettingsWidget.h" />
<QtMoc Include="Settings\FolderSettingsWidget.h">
<Filter>Settings</Filter>
</QtMoc>
</ItemGroup>
<ItemGroup>
<QtResource Include="resources\resources.qrc">