mirror of
https://github.com/stenzek/duckstation.git
synced 2026-02-04 05:04:33 +00:00
Qt: Pack main window local state in struct
This commit is contained in:
@@ -115,52 +115,59 @@ static constexpr char IMAGE_FILTER[] = QT_TRANSLATE_NOOP("MainWindow", "Images (
|
||||
MainWindow* g_main_window = nullptr;
|
||||
|
||||
// UI thread VM validity.
|
||||
static bool s_disable_window_rounded_corners = false;
|
||||
static bool s_system_starting = false;
|
||||
static bool s_system_valid = false;
|
||||
static bool s_system_paused = false;
|
||||
static bool s_achievements_hardcore_mode = false;
|
||||
static bool s_fullscreen_ui_started = false;
|
||||
static std::atomic_uint32_t s_system_locked{false};
|
||||
static QString s_current_game_title;
|
||||
static QString s_current_game_serial;
|
||||
static QString s_current_game_path;
|
||||
static QIcon s_current_game_icon;
|
||||
static std::optional<std::time_t> s_undo_state_timestamp;
|
||||
namespace {
|
||||
struct MainWindowLocals
|
||||
{
|
||||
QString current_game_title;
|
||||
QString current_game_serial;
|
||||
QString current_game_path;
|
||||
QIcon current_game_icon;
|
||||
std::optional<std::time_t> undo_state_timestamp;
|
||||
std::atomic_uint32_t system_locked{false};
|
||||
bool system_starting = false;
|
||||
bool system_valid = false;
|
||||
bool system_paused = false;
|
||||
bool achievements_hardcore_mode = false;
|
||||
bool fullscreen_ui_started = false;
|
||||
bool disable_window_rounded_corners = false;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
ALIGN_TO_CACHE_LINE static MainWindowLocals s_locals;
|
||||
|
||||
bool QtHost::IsSystemPaused()
|
||||
{
|
||||
return s_system_paused;
|
||||
return s_locals.system_paused;
|
||||
}
|
||||
|
||||
bool QtHost::IsSystemValid()
|
||||
{
|
||||
return s_system_valid;
|
||||
return s_locals.system_valid;
|
||||
}
|
||||
|
||||
bool QtHost::IsSystemValidOrStarting()
|
||||
{
|
||||
return (s_system_starting || s_system_valid);
|
||||
return (s_locals.system_starting || s_locals.system_valid);
|
||||
}
|
||||
|
||||
bool QtHost::IsFullscreenUIStarted()
|
||||
{
|
||||
return s_fullscreen_ui_started;
|
||||
return s_locals.fullscreen_ui_started;
|
||||
}
|
||||
|
||||
const QString& QtHost::GetCurrentGameTitle()
|
||||
{
|
||||
return s_current_game_title;
|
||||
return s_locals.current_game_title;
|
||||
}
|
||||
|
||||
const QString& QtHost::GetCurrentGameSerial()
|
||||
{
|
||||
return s_current_game_serial;
|
||||
return s_locals.current_game_serial;
|
||||
}
|
||||
|
||||
const QString& QtHost::GetCurrentGamePath()
|
||||
{
|
||||
return s_current_game_path;
|
||||
return s_locals.current_game_path;
|
||||
}
|
||||
|
||||
MainWindow::MainWindow() : QMainWindow(nullptr)
|
||||
@@ -268,7 +275,7 @@ std::optional<WindowInfo> MainWindow::acquireRenderWindow(RenderAPI render_api,
|
||||
bool exclusive_fullscreen, Error* error)
|
||||
{
|
||||
const bool render_to_main =
|
||||
QtHost::CanRenderToMainWindow() && !fullscreen && (s_system_locked.load(std::memory_order_relaxed) == 0);
|
||||
QtHost::CanRenderToMainWindow() && !fullscreen && (s_locals.system_locked.load(std::memory_order_relaxed) == 0);
|
||||
|
||||
DEV_LOG("acquireRenderWindow() fullscreen={} exclusive_fullscreen={}, render_to_main={}", fullscreen,
|
||||
exclusive_fullscreen, render_to_main);
|
||||
@@ -339,7 +346,7 @@ std::optional<WindowInfo> MainWindow::acquireRenderWindow(RenderAPI render_api,
|
||||
bool MainWindow::wantsDisplayWidget() const
|
||||
{
|
||||
// big picture or system created
|
||||
return (QtHost::IsSystemValidOrStarting() || s_fullscreen_ui_started);
|
||||
return (QtHost::IsSystemValidOrStarting() || s_locals.fullscreen_ui_started);
|
||||
}
|
||||
|
||||
bool MainWindow::hasDisplayWidget() const
|
||||
@@ -391,7 +398,7 @@ void MainWindow::createDisplayWidget(bool fullscreen, bool render_to_main)
|
||||
restoreDisplayWindowGeometryFromConfig();
|
||||
container->showNormal();
|
||||
|
||||
if (s_disable_window_rounded_corners)
|
||||
if (s_locals.disable_window_rounded_corners)
|
||||
PlatformMisc::SetWindowRoundedCornerState(reinterpret_cast<void*>(container->winId()), false);
|
||||
}
|
||||
else
|
||||
@@ -491,8 +498,8 @@ void MainWindow::updateDisplayWidgetCursor()
|
||||
if (!m_display_widget)
|
||||
return;
|
||||
|
||||
m_display_widget->updateRelativeMode(s_system_valid && !s_system_paused && m_relative_mouse_mode);
|
||||
m_display_widget->updateCursor(s_system_valid && !s_system_paused && shouldHideMouseCursor());
|
||||
m_display_widget->updateRelativeMode(s_locals.system_valid && !s_locals.system_paused && m_relative_mouse_mode);
|
||||
m_display_widget->updateCursor(s_locals.system_valid && !s_locals.system_paused && shouldHideMouseCursor());
|
||||
}
|
||||
|
||||
void MainWindow::updateDisplayRelatedActions()
|
||||
@@ -501,9 +508,10 @@ void MainWindow::updateDisplayRelatedActions()
|
||||
|
||||
// rendering to main, or switched to gamelist/grid
|
||||
m_ui.actionViewSystemDisplay->setEnabled(wantsDisplayWidget() && QtHost::CanRenderToMainWindow() &&
|
||||
!s_system_starting);
|
||||
m_ui.menuWindowSize->setEnabled(s_system_valid && !s_system_starting && m_display_widget && !fullscreen);
|
||||
m_ui.actionFullscreen->setEnabled(m_display_widget && !s_system_starting);
|
||||
!s_locals.system_starting);
|
||||
m_ui.menuWindowSize->setEnabled(s_locals.system_valid && !s_locals.system_starting && m_display_widget &&
|
||||
!fullscreen);
|
||||
m_ui.actionFullscreen->setEnabled(m_display_widget && !s_locals.system_starting);
|
||||
m_ui.actionFullscreen->setChecked(fullscreen);
|
||||
|
||||
updateGameListRelatedActions();
|
||||
@@ -512,7 +520,7 @@ void MainWindow::updateDisplayRelatedActions()
|
||||
void MainWindow::updateGameListRelatedActions()
|
||||
{
|
||||
const bool running = !isShowingGameList();
|
||||
const bool disable = (s_system_starting || (running && isRenderingToMain()));
|
||||
const bool disable = (s_locals.system_starting || (running && isRenderingToMain()));
|
||||
|
||||
const bool game_grid = m_game_list_widget->isShowingGameGrid();
|
||||
const bool game_list = m_game_list_widget->isShowingGameList();
|
||||
@@ -545,9 +553,9 @@ void MainWindow::onMouseModeRequested(bool relative_mode, bool hide_cursor)
|
||||
|
||||
void MainWindow::onSystemStarting()
|
||||
{
|
||||
s_system_starting = true;
|
||||
s_system_valid = false;
|
||||
s_system_paused = false;
|
||||
s_locals.system_starting = true;
|
||||
s_locals.system_valid = false;
|
||||
s_locals.system_paused = false;
|
||||
|
||||
switchToEmulationView();
|
||||
updateEmulationActions();
|
||||
@@ -557,8 +565,8 @@ void MainWindow::onSystemStarting()
|
||||
void MainWindow::onSystemStarted()
|
||||
{
|
||||
m_was_disc_change_request = false;
|
||||
s_system_starting = false;
|
||||
s_system_valid = true;
|
||||
s_locals.system_starting = false;
|
||||
s_locals.system_valid = true;
|
||||
|
||||
updateEmulationActions();
|
||||
updateDisplayRelatedActions();
|
||||
@@ -570,7 +578,7 @@ void MainWindow::onSystemStarted()
|
||||
void MainWindow::onSystemPaused()
|
||||
{
|
||||
m_ui.actionPause->setChecked(true);
|
||||
s_system_paused = true;
|
||||
s_locals.system_paused = true;
|
||||
updateStatusBarWidgetVisibility();
|
||||
m_ui.statusBar->showMessage(tr("Paused"));
|
||||
updateDisplayWidgetCursor();
|
||||
@@ -579,7 +587,7 @@ void MainWindow::onSystemPaused()
|
||||
void MainWindow::onSystemResumed()
|
||||
{
|
||||
m_ui.actionPause->setChecked(false);
|
||||
s_system_paused = false;
|
||||
s_locals.system_paused = false;
|
||||
m_was_disc_change_request = false;
|
||||
m_ui.statusBar->clearMessage();
|
||||
updateStatusBarWidgetVisibility();
|
||||
@@ -591,10 +599,10 @@ void MainWindow::onSystemResumed()
|
||||
void MainWindow::onSystemStopping()
|
||||
{
|
||||
m_ui.actionPause->setChecked(false);
|
||||
s_system_starting = false;
|
||||
s_system_valid = false;
|
||||
s_system_paused = false;
|
||||
s_undo_state_timestamp.reset();
|
||||
s_locals.system_starting = false;
|
||||
s_locals.system_valid = false;
|
||||
s_locals.system_paused = false;
|
||||
s_locals.undo_state_timestamp.reset();
|
||||
|
||||
updateEmulationActions();
|
||||
updateDisplayRelatedActions();
|
||||
@@ -621,10 +629,10 @@ void MainWindow::onSystemDestroyed()
|
||||
|
||||
void MainWindow::onSystemGameChanged(const QString& path, const QString& game_serial, const QString& game_title)
|
||||
{
|
||||
s_current_game_path = path;
|
||||
s_current_game_title = game_title;
|
||||
s_current_game_serial = game_serial;
|
||||
s_current_game_icon = getIconForGame(path);
|
||||
s_locals.current_game_path = path;
|
||||
s_locals.current_game_title = game_title;
|
||||
s_locals.current_game_serial = game_serial;
|
||||
s_locals.current_game_icon = getIconForGame(path);
|
||||
|
||||
updateWindowTitle();
|
||||
}
|
||||
@@ -632,9 +640,9 @@ void MainWindow::onSystemGameChanged(const QString& path, const QString& game_se
|
||||
void MainWindow::onSystemUndoStateAvailabilityChanged(bool available, quint64 timestamp)
|
||||
{
|
||||
if (!available)
|
||||
s_undo_state_timestamp.reset();
|
||||
s_locals.undo_state_timestamp.reset();
|
||||
else
|
||||
s_undo_state_timestamp = timestamp;
|
||||
s_locals.undo_state_timestamp = timestamp;
|
||||
}
|
||||
|
||||
void MainWindow::onMediaCaptureStarted()
|
||||
@@ -649,13 +657,13 @@ void MainWindow::onMediaCaptureStopped()
|
||||
|
||||
void MainWindow::onApplicationStateChanged(Qt::ApplicationState state)
|
||||
{
|
||||
if (!s_system_valid)
|
||||
if (!s_locals.system_valid)
|
||||
return;
|
||||
|
||||
const bool focus_loss = (state != Qt::ApplicationActive);
|
||||
if (focus_loss)
|
||||
{
|
||||
if (g_settings.pause_on_focus_loss && !m_was_paused_by_focus_loss && !s_system_paused)
|
||||
if (g_settings.pause_on_focus_loss && !m_was_paused_by_focus_loss && !s_locals.system_paused)
|
||||
{
|
||||
g_emu_thread->setSystemPaused(true);
|
||||
m_was_paused_by_focus_loss = true;
|
||||
@@ -670,7 +678,7 @@ void MainWindow::onApplicationStateChanged(Qt::ApplicationState state)
|
||||
{
|
||||
if (m_was_paused_by_focus_loss)
|
||||
{
|
||||
if (s_system_paused)
|
||||
if (s_locals.system_paused)
|
||||
g_emu_thread->setSystemPaused(false);
|
||||
m_was_paused_by_focus_loss = false;
|
||||
}
|
||||
@@ -740,7 +748,7 @@ void MainWindow::quit()
|
||||
}
|
||||
|
||||
// Big picture might still be active.
|
||||
if (s_fullscreen_ui_started)
|
||||
if (s_locals.fullscreen_ui_started)
|
||||
g_emu_thread->stopFullscreenUI();
|
||||
|
||||
// Ensure subwindows are removed before quitting. That way the log window cancelling
|
||||
@@ -803,7 +811,7 @@ void MainWindow::recreate()
|
||||
QtUtils::ProcessEventsWithSleep(QEventLoop::ExcludeUserInputEvents,
|
||||
[]() { return !g_main_window->hasDisplayWidget(); });
|
||||
g_main_window->updateEmulationActions();
|
||||
g_main_window->onFullscreenUIStartedOrStopped(s_fullscreen_ui_started);
|
||||
g_main_window->onFullscreenUIStartedOrStopped(s_locals.fullscreen_ui_started);
|
||||
}
|
||||
|
||||
// New window ready to go, close out the old one.
|
||||
@@ -888,7 +896,7 @@ void MainWindow::populateGameListContextMenu(const GameList::Entry* entry, QWidg
|
||||
action = load_state_menu->addAction(tr("Game Save %1 (%2)").arg(slot).arg(timestamp_str));
|
||||
}
|
||||
|
||||
action->setDisabled(s_achievements_hardcore_mode);
|
||||
action->setDisabled(s_locals.achievements_hardcore_mode);
|
||||
connect(action, &QAction::triggered, [this, game_path = entry->path, path = std::move(ssi.path)]() mutable {
|
||||
startFile(std::move(game_path), std::move(path), std::nullopt);
|
||||
});
|
||||
@@ -962,12 +970,12 @@ void MainWindow::populateLoadStateMenu(std::string_view game_serial, QMenu* menu
|
||||
g_emu_thread->loadState(path);
|
||||
});
|
||||
QAction* load_from_state =
|
||||
menu->addAction(s_undo_state_timestamp.has_value() ?
|
||||
menu->addAction(s_locals.undo_state_timestamp.has_value() ?
|
||||
tr("Undo Load State (%1)")
|
||||
.arg(QtHost::FormatNumber(Host::NumberFormatType::ShortDateTime,
|
||||
static_cast<s64>(s_undo_state_timestamp.value()))) :
|
||||
static_cast<s64>(s_locals.undo_state_timestamp.value()))) :
|
||||
tr("Undo Load State"));
|
||||
load_from_state->setEnabled(s_undo_state_timestamp.has_value());
|
||||
load_from_state->setEnabled(s_locals.undo_state_timestamp.has_value());
|
||||
connect(load_from_state, &QAction::triggered, g_emu_thread, &EmuThread::undoLoadState);
|
||||
menu->addSeparator();
|
||||
|
||||
@@ -1198,7 +1206,7 @@ void MainWindow::startFile(std::string path, std::optional<std::string> save_pat
|
||||
|
||||
void MainWindow::startFileOrChangeDisc(const QString& qpath)
|
||||
{
|
||||
if (s_system_valid)
|
||||
if (s_locals.system_valid)
|
||||
{
|
||||
// this is a disc change
|
||||
promptForDiscChange(qpath);
|
||||
@@ -1300,7 +1308,7 @@ void MainWindow::onChangeDiscMenuAboutToShow()
|
||||
m_ui.menuChangeDisc->addAction(m_ui.actionRemoveDisc);
|
||||
m_ui.menuChangeDisc->addSeparator();
|
||||
|
||||
if (!s_system_valid)
|
||||
if (!s_locals.system_valid)
|
||||
return;
|
||||
|
||||
// NOTE: This is terrible and a race condition. But nobody should be using m3u files anyway.
|
||||
@@ -1325,7 +1333,7 @@ void MainWindow::onChangeDiscMenuAboutToShow()
|
||||
QAction* action = m_ui.menuChangeDisc->addAction(QtUtils::StringViewToQString(title));
|
||||
QString path = QString::fromStdString(glentry->path);
|
||||
action->setCheckable(true);
|
||||
action->setChecked(path == s_current_game_path);
|
||||
action->setChecked(path == s_locals.current_game_path);
|
||||
connect(action, &QAction::triggered, [path = std::move(path)]() { g_emu_thread->changeDisc(path, false, true); });
|
||||
}
|
||||
}
|
||||
@@ -1333,12 +1341,12 @@ void MainWindow::onChangeDiscMenuAboutToShow()
|
||||
|
||||
void MainWindow::onLoadStateMenuAboutToShow()
|
||||
{
|
||||
populateLoadStateMenu(s_current_game_serial.toStdString(), m_ui.menuLoadState);
|
||||
populateLoadStateMenu(s_locals.current_game_serial.toStdString(), m_ui.menuLoadState);
|
||||
}
|
||||
|
||||
void MainWindow::onSaveStateMenuAboutToShow()
|
||||
{
|
||||
populateSaveStateMenu(s_current_game_serial.toStdString(), m_ui.menuSaveState);
|
||||
populateSaveStateMenu(s_locals.current_game_serial.toStdString(), m_ui.menuSaveState);
|
||||
}
|
||||
|
||||
void MainWindow::onStartFullscreenUITriggered()
|
||||
@@ -1351,7 +1359,7 @@ void MainWindow::onStartFullscreenUITriggered()
|
||||
|
||||
void MainWindow::onFullscreenUIStartedOrStopped(bool running)
|
||||
{
|
||||
s_fullscreen_ui_started = running;
|
||||
s_locals.fullscreen_ui_started = running;
|
||||
m_ui.actionStartFullscreenUI->setText(running ? tr("Stop Big Picture Mode") : tr("Start Big Picture Mode"));
|
||||
m_ui.actionStartFullscreenUI2->setText(running ? tr("Exit Big Picture") : tr("Big Picture"));
|
||||
}
|
||||
@@ -1373,10 +1381,10 @@ void MainWindow::onResetGameActionTriggered()
|
||||
|
||||
void MainWindow::onPauseActionTriggered(bool checked)
|
||||
{
|
||||
if (s_system_paused == checked)
|
||||
if (s_locals.system_paused == checked)
|
||||
return;
|
||||
|
||||
if (checked && s_achievements_hardcore_mode)
|
||||
if (checked && s_locals.achievements_hardcore_mode)
|
||||
{
|
||||
// Need to check restrictions.
|
||||
Host::RunOnCPUThread([]() {
|
||||
@@ -1543,7 +1551,7 @@ void MainWindow::onGameListEntryActivated()
|
||||
if (!entry)
|
||||
return;
|
||||
|
||||
if (s_system_valid)
|
||||
if (s_locals.system_valid)
|
||||
{
|
||||
// change disc on double click
|
||||
if (!entry->IsDisc())
|
||||
@@ -1612,7 +1620,7 @@ void MainWindow::onGameListEntryContextMenuRequested(const QPoint& point)
|
||||
|
||||
menu->addSeparator();
|
||||
|
||||
if (!s_system_valid)
|
||||
if (!s_locals.system_valid)
|
||||
{
|
||||
populateGameListContextMenu(entry, this, menu);
|
||||
menu->addSeparator();
|
||||
@@ -1896,8 +1904,8 @@ void MainWindow::setupAdditionalUi()
|
||||
new QShortcut(QKeySequence::ZoomOut, this, this, &MainWindow::onViewZoomOutActionTriggered);
|
||||
m_shortcuts.settings = new QShortcut(QKeySequence::Preferences, this, [this] { doSettings(); });
|
||||
|
||||
s_disable_window_rounded_corners = Host::GetBaseBoolSettingValue("Main", "DisableWindowRoundedCorners", false);
|
||||
if (s_disable_window_rounded_corners)
|
||||
s_locals.disable_window_rounded_corners = Host::GetBaseBoolSettingValue("Main", "DisableWindowRoundedCorners", false);
|
||||
if (s_locals.disable_window_rounded_corners)
|
||||
PlatformMisc::SetWindowRoundedCornerState(reinterpret_cast<void*>(winId()), false);
|
||||
|
||||
QtUtils::StyleChildMenus(this);
|
||||
@@ -1974,7 +1982,7 @@ void MainWindow::updateToolbarActions()
|
||||
|
||||
// only one of resume/poweroff should be present depending on system state
|
||||
QAction* action = (m_ui.*action_ptr);
|
||||
if (action == m_ui.actionCloseGame && !s_system_valid)
|
||||
if (action == m_ui.actionCloseGame && !s_locals.system_valid)
|
||||
action = m_ui.actionResumeLastState;
|
||||
|
||||
m_ui.toolBar->addAction(action);
|
||||
@@ -2130,10 +2138,10 @@ void MainWindow::onToolbarTopLevelChanged(bool top_level)
|
||||
|
||||
void MainWindow::updateEmulationActions()
|
||||
{
|
||||
const bool starting = s_system_starting;
|
||||
const bool starting_or_running = (starting || s_system_valid);
|
||||
const bool starting_or_not_running = (starting || !s_system_valid);
|
||||
const bool achievements_hardcore_mode = s_achievements_hardcore_mode;
|
||||
const bool starting = s_locals.system_starting;
|
||||
const bool starting_or_running = (starting || s_locals.system_valid);
|
||||
const bool starting_or_not_running = (starting || !s_locals.system_valid);
|
||||
const bool achievements_hardcore_mode = s_locals.achievements_hardcore_mode;
|
||||
m_ui.actionStartFile->setDisabled(starting_or_running);
|
||||
m_ui.actionStartDisc->setDisabled(starting_or_running);
|
||||
m_ui.actionStartBios->setDisabled(starting_or_running);
|
||||
@@ -2204,7 +2212,7 @@ void MainWindow::updateEmulationActions()
|
||||
|
||||
void MainWindow::updateShortcutActions()
|
||||
{
|
||||
const bool starting_or_running = s_system_starting || s_system_valid;
|
||||
const bool starting_or_running = s_locals.system_starting || s_locals.system_valid;
|
||||
const bool is_showing_game_list = isShowingGameList();
|
||||
|
||||
m_shortcuts.open_file->setEnabled(!starting_or_running);
|
||||
@@ -2230,26 +2238,26 @@ void MainWindow::updateStatusBarWidgetVisibility()
|
||||
}
|
||||
};
|
||||
|
||||
Update(m_status_renderer_widget, s_system_valid && !s_system_paused, 0);
|
||||
Update(m_status_resolution_widget, s_system_valid && !s_system_paused, 0);
|
||||
Update(m_status_fps_widget, s_system_valid && !s_system_paused, 0);
|
||||
Update(m_status_vps_widget, s_system_valid && !s_system_paused, 0);
|
||||
Update(m_status_renderer_widget, s_locals.system_valid && !s_locals.system_paused, 0);
|
||||
Update(m_status_resolution_widget, s_locals.system_valid && !s_locals.system_paused, 0);
|
||||
Update(m_status_fps_widget, s_locals.system_valid && !s_locals.system_paused, 0);
|
||||
Update(m_status_vps_widget, s_locals.system_valid && !s_locals.system_paused, 0);
|
||||
}
|
||||
|
||||
void MainWindow::updateWindowTitle()
|
||||
{
|
||||
QString suffix(QtHost::GetAppConfigSuffix());
|
||||
QString main_title(QtHost::GetAppNameAndVersion() + suffix);
|
||||
QString display_title(s_current_game_title + suffix);
|
||||
QString display_title(s_locals.current_game_title + suffix);
|
||||
|
||||
if (!s_system_valid || s_current_game_title.isEmpty())
|
||||
if (!s_locals.system_valid || s_locals.current_game_title.isEmpty())
|
||||
display_title = main_title;
|
||||
else if (isRenderingToMain())
|
||||
main_title = display_title;
|
||||
|
||||
if (windowTitle() != main_title)
|
||||
setWindowTitle(main_title);
|
||||
setWindowIcon(s_current_game_icon.isNull() ? QtHost::GetAppIcon() : s_current_game_icon);
|
||||
setWindowIcon(s_locals.current_game_icon.isNull() ? QtHost::GetAppIcon() : s_locals.current_game_icon);
|
||||
|
||||
if (m_display_widget && !isRenderingToMain())
|
||||
{
|
||||
@@ -2257,7 +2265,7 @@ void MainWindow::updateWindowTitle()
|
||||
m_display_container ? static_cast<QWidget*>(m_display_container) : static_cast<QWidget*>(m_display_widget);
|
||||
if (container->windowTitle() != display_title)
|
||||
container->setWindowTitle(display_title);
|
||||
container->setWindowIcon(s_current_game_icon.isNull() ? QtHost::GetAppIcon() : s_current_game_icon);
|
||||
container->setWindowIcon(s_locals.current_game_icon.isNull() ? QtHost::GetAppIcon() : s_locals.current_game_icon);
|
||||
}
|
||||
|
||||
if (g_log_window)
|
||||
@@ -2340,7 +2348,7 @@ bool MainWindow::shouldHideMainWindow() const
|
||||
((Host::GetBoolSettingValue("Main", "RenderToSeparateWindow", false) &&
|
||||
Host::GetBoolSettingValue("Main", "HideMainWindowWhenRunning", false)) ||
|
||||
(QtHost::CanRenderToMainWindow() &&
|
||||
(isRenderingFullscreen() || s_system_locked.load(std::memory_order_relaxed))))) ||
|
||||
(isRenderingFullscreen() || s_locals.system_locked.load(std::memory_order_relaxed))))) ||
|
||||
QtHost::InNoGUIMode();
|
||||
}
|
||||
|
||||
@@ -2356,8 +2364,8 @@ void MainWindow::switchToGameListView()
|
||||
if (isShowingGameList())
|
||||
return;
|
||||
|
||||
m_was_paused_on_game_list_switch = s_system_paused;
|
||||
if (!s_system_paused)
|
||||
m_was_paused_on_game_list_switch = s_locals.system_paused;
|
||||
if (!s_locals.system_paused)
|
||||
g_emu_thread->setSystemPaused(true);
|
||||
|
||||
m_ui.mainContainer->setCurrentIndex(0);
|
||||
@@ -2383,7 +2391,7 @@ void MainWindow::switchToEmulationView()
|
||||
m_display_widget->setFocus();
|
||||
|
||||
// resume if we weren't paused at switch time
|
||||
if (s_system_paused && !m_was_paused_on_game_list_switch)
|
||||
if (s_locals.system_paused && !m_was_paused_on_game_list_switch)
|
||||
g_emu_thread->setSystemPaused(false);
|
||||
|
||||
updateShortcutActions();
|
||||
@@ -2724,11 +2732,11 @@ void MainWindow::doSettings(const char* category /* = nullptr */)
|
||||
|
||||
void MainWindow::openGamePropertiesForCurrentGame(const char* category /* = nullptr */)
|
||||
{
|
||||
if (!s_system_valid)
|
||||
if (!s_locals.system_valid)
|
||||
return;
|
||||
|
||||
auto lock = GameList::GetLock();
|
||||
const std::string game_path = s_current_game_path.toStdString();
|
||||
const std::string game_path = s_locals.current_game_path.toStdString();
|
||||
const GameList::Entry* entry = GameList::GetEntryForPath(game_path);
|
||||
if (entry && entry->disc_set_member && !entry->dbentry->IsFirstDiscInSet() &&
|
||||
!System::ShouldUseSeparateDiscSettingsForSerial(entry->serial))
|
||||
@@ -2792,7 +2800,7 @@ void MainWindow::onViewClearGameListBackgroundTriggered()
|
||||
|
||||
void MainWindow::onSettingsTriggeredFromToolbar()
|
||||
{
|
||||
if (s_system_valid)
|
||||
if (s_locals.system_valid)
|
||||
m_settings_toolbar_menu->popup(QCursor::pos());
|
||||
else
|
||||
doSettings();
|
||||
@@ -2823,7 +2831,7 @@ void MainWindow::closeEvent(QCloseEvent* event)
|
||||
{
|
||||
QtUtils::SaveWindowGeometry(this);
|
||||
|
||||
if (s_fullscreen_ui_started && g_main_window == this)
|
||||
if (s_locals.fullscreen_ui_started && g_main_window == this)
|
||||
g_emu_thread->stopFullscreenUI();
|
||||
|
||||
destroySubWindows();
|
||||
@@ -2896,7 +2904,7 @@ void MainWindow::dropEvent(QDropEvent* event)
|
||||
return;
|
||||
}
|
||||
|
||||
if (s_system_valid)
|
||||
if (s_locals.system_valid)
|
||||
promptForDiscChange(qfilename);
|
||||
else
|
||||
startFileOrChangeDisc(qfilename);
|
||||
@@ -2962,7 +2970,7 @@ void MainWindow::requestShutdown(bool allow_confirm, bool allow_save_to_state, b
|
||||
{
|
||||
if (!QtHost::IsSystemValidOrStarting())
|
||||
{
|
||||
if (exit_fullscreen_ui && s_fullscreen_ui_started)
|
||||
if (exit_fullscreen_ui && s_locals.fullscreen_ui_started)
|
||||
g_emu_thread->stopFullscreenUI();
|
||||
|
||||
if (quit_afterwards)
|
||||
@@ -2972,14 +2980,15 @@ void MainWindow::requestShutdown(bool allow_confirm, bool allow_save_to_state, b
|
||||
}
|
||||
|
||||
// If we don't have a serial, we can't save state.
|
||||
allow_save_to_state &= !s_current_game_serial.isEmpty();
|
||||
allow_save_to_state &= !s_locals.current_game_serial.isEmpty();
|
||||
save_state &= allow_save_to_state;
|
||||
|
||||
// Only confirm on UI thread because we need to display a msgbox.
|
||||
if (!m_is_closing && s_system_valid && allow_confirm && Host::GetBoolSettingValue("Main", "ConfirmPowerOff", true))
|
||||
if (!m_is_closing && s_locals.system_valid && allow_confirm &&
|
||||
Host::GetBoolSettingValue("Main", "ConfirmPowerOff", true))
|
||||
{
|
||||
// Hardcore mode restrictions.
|
||||
if (check_pause && !s_system_paused && s_achievements_hardcore_mode && allow_confirm)
|
||||
if (check_pause && !s_locals.system_paused && s_locals.achievements_hardcore_mode && allow_confirm)
|
||||
{
|
||||
Host::RunOnCPUThread(
|
||||
[allow_confirm, allow_save_to_state, save_state, check_safety, exit_fullscreen_ui, quit_afterwards]() {
|
||||
@@ -3034,11 +3043,11 @@ void MainWindow::requestShutdown(bool allow_confirm, bool allow_save_to_state, b
|
||||
}
|
||||
|
||||
// If we're still starting, shut down first. Otherwise the FSUI shutdown will block until it finishes.
|
||||
if (s_system_starting)
|
||||
if (s_locals.system_starting)
|
||||
System::CancelPendingStartup();
|
||||
|
||||
// Stop fullscreen UI from reopening if requested.
|
||||
if (exit_fullscreen_ui && s_fullscreen_ui_started)
|
||||
if (exit_fullscreen_ui && s_locals.fullscreen_ui_started)
|
||||
g_emu_thread->stopFullscreenUI();
|
||||
|
||||
// Now we can actually shut down the VM.
|
||||
@@ -3055,15 +3064,16 @@ void MainWindow::checkForSettingChanges()
|
||||
{
|
||||
if (const bool disable_window_rounded_corners =
|
||||
Host::GetBaseBoolSettingValue("Main", "DisableWindowRoundedCorners", false);
|
||||
disable_window_rounded_corners != s_disable_window_rounded_corners)
|
||||
disable_window_rounded_corners != s_locals.disable_window_rounded_corners)
|
||||
{
|
||||
s_disable_window_rounded_corners = disable_window_rounded_corners;
|
||||
PlatformMisc::SetWindowRoundedCornerState(reinterpret_cast<void*>(winId()), !s_disable_window_rounded_corners);
|
||||
s_locals.disable_window_rounded_corners = disable_window_rounded_corners;
|
||||
PlatformMisc::SetWindowRoundedCornerState(reinterpret_cast<void*>(winId()),
|
||||
!s_locals.disable_window_rounded_corners);
|
||||
|
||||
if (QWidget* container = getDisplayContainer(); container && !container->parent() && !container->isFullScreen())
|
||||
{
|
||||
PlatformMisc::SetWindowRoundedCornerState(reinterpret_cast<void*>(container->winId()),
|
||||
!s_disable_window_rounded_corners);
|
||||
!s_locals.disable_window_rounded_corners);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3077,7 +3087,7 @@ void MainWindow::checkForSettingChanges()
|
||||
LogWindow::updateSettings();
|
||||
|
||||
// don't refresh window state while setup wizard is running, i.e. no game and hidden
|
||||
if (isVisible() || s_system_valid || s_system_starting)
|
||||
if (isVisible() || s_locals.system_valid || s_locals.system_starting)
|
||||
updateWindowState();
|
||||
}
|
||||
|
||||
@@ -3203,7 +3213,7 @@ void MainWindow::onAchievementsHardcoreModeChanged(bool enabled)
|
||||
QtUtils::CloseAndDeleteWindow(m_memory_scanner_window);
|
||||
}
|
||||
|
||||
s_achievements_hardcore_mode = enabled;
|
||||
s_locals.achievements_hardcore_mode = enabled;
|
||||
updateEmulationActions();
|
||||
}
|
||||
|
||||
@@ -3221,7 +3231,7 @@ bool MainWindow::onCreateAuxiliaryRenderWindow(RenderAPI render_api, qint32 x, q
|
||||
if (!widget)
|
||||
return false;
|
||||
|
||||
if (s_disable_window_rounded_corners)
|
||||
if (s_locals.disable_window_rounded_corners)
|
||||
PlatformMisc::SetWindowRoundedCornerState(reinterpret_cast<void*>(widget->winId()), false);
|
||||
|
||||
const std::optional<WindowInfo> owi = QtUtils::GetWindowInfoForWidget(widget, render_api, error);
|
||||
@@ -3269,7 +3279,7 @@ void MainWindow::onToolsCoverDownloaderTriggered()
|
||||
|
||||
void MainWindow::onToolsMediaCaptureTriggered(bool checked)
|
||||
{
|
||||
if (!s_system_valid)
|
||||
if (!s_locals.system_valid)
|
||||
{
|
||||
// leave it for later, we'll fill in the boot params
|
||||
return;
|
||||
@@ -3300,7 +3310,7 @@ void MainWindow::onToolsMediaCaptureTriggered(bool checked)
|
||||
|
||||
void MainWindow::onToolsMemoryEditorTriggered()
|
||||
{
|
||||
if (s_achievements_hardcore_mode)
|
||||
if (s_locals.achievements_hardcore_mode)
|
||||
return;
|
||||
|
||||
QtUtils::ShowOrRaiseWindow(getMemoryEditorWindow(), this, true);
|
||||
@@ -3308,7 +3318,7 @@ void MainWindow::onToolsMemoryEditorTriggered()
|
||||
|
||||
void MainWindow::onToolsMemoryScannerTriggered()
|
||||
{
|
||||
if (s_achievements_hardcore_mode)
|
||||
if (s_locals.achievements_hardcore_mode)
|
||||
return;
|
||||
|
||||
if (!m_memory_scanner_window)
|
||||
@@ -3333,7 +3343,7 @@ void MainWindow::onToolsISOBrowserTriggered()
|
||||
|
||||
void MainWindow::openCPUDebugger()
|
||||
{
|
||||
if (s_achievements_hardcore_mode)
|
||||
if (s_locals.achievements_hardcore_mode)
|
||||
return;
|
||||
|
||||
if (!m_debugger_window)
|
||||
@@ -3356,8 +3366,8 @@ void MainWindow::onToolsOpenDataDirectoryTriggered()
|
||||
void MainWindow::onToolsOpenTextureDirectoryTriggered()
|
||||
{
|
||||
QString dir = QString::fromStdString(EmuFolders::Textures);
|
||||
if (s_system_valid && !s_current_game_serial.isEmpty())
|
||||
dir = QStringLiteral("%1" FS_OSPATH_SEPARATOR_STR "%2").arg(dir).arg(s_current_game_serial);
|
||||
if (s_locals.system_valid && !s_locals.current_game_serial.isEmpty())
|
||||
dir = QStringLiteral("%1" FS_OSPATH_SEPARATOR_STR "%2").arg(dir).arg(s_locals.current_game_serial);
|
||||
|
||||
QtUtils::OpenURL(this, QUrl::fromLocalFile(dir));
|
||||
}
|
||||
@@ -3472,10 +3482,10 @@ MainWindow::SystemLock MainWindow::pauseAndLockSystem()
|
||||
#else
|
||||
const bool was_fullscreen = false;
|
||||
#endif
|
||||
const bool was_paused = !s_system_valid || s_system_paused;
|
||||
const bool was_paused = !s_locals.system_valid || s_locals.system_paused;
|
||||
|
||||
// Have to do this early to avoid making the main window visible.
|
||||
s_system_locked.fetch_add(1, std::memory_order_release);
|
||||
s_locals.system_locked.fetch_add(1, std::memory_order_release);
|
||||
|
||||
// We need to switch out of exclusive fullscreen before we can display our popup.
|
||||
// However, we do not want to switch back to render-to-main, the window might have generated this event.
|
||||
@@ -3492,7 +3502,7 @@ MainWindow::SystemLock MainWindow::pauseAndLockSystem()
|
||||
g_emu_thread->setSystemPaused(true);
|
||||
|
||||
// Need to wait for the pause to go through, and make the main window visible if needed.
|
||||
QtUtils::ProcessEventsWithSleep(QEventLoop::ExcludeUserInputEvents, []() { return !s_system_paused; });
|
||||
QtUtils::ProcessEventsWithSleep(QEventLoop::ExcludeUserInputEvents, []() { return !s_locals.system_paused; });
|
||||
|
||||
// Ensure it's visible before we try to create any dialogs parented to us.
|
||||
QApplication::sync();
|
||||
@@ -3527,8 +3537,8 @@ MainWindow::SystemLock::~SystemLock()
|
||||
if (!m_valid)
|
||||
return;
|
||||
|
||||
DebugAssert(s_system_locked.load(std::memory_order_relaxed) > 0);
|
||||
s_system_locked.fetch_sub(1, std::memory_order_release);
|
||||
DebugAssert(s_locals.system_locked.load(std::memory_order_relaxed) > 0);
|
||||
s_locals.system_locked.fetch_sub(1, std::memory_order_release);
|
||||
if (m_was_fullscreen)
|
||||
g_emu_thread->setFullscreen(true);
|
||||
if (!m_was_paused)
|
||||
@@ -3543,7 +3553,7 @@ void MainWindow::SystemLock::cancelResume()
|
||||
|
||||
bool QtHost::IsSystemLocked()
|
||||
{
|
||||
return (s_system_locked.load(std::memory_order_acquire) > 0);
|
||||
return (s_locals.system_locked.load(std::memory_order_acquire) > 0);
|
||||
}
|
||||
|
||||
#ifdef RC_CLIENT_SUPPORTS_RAINTEGRATION
|
||||
|
||||
Reference in New Issue
Block a user