From add46248a3447f28094b7ac808ca9ba86eca16b9 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 17 Aug 2024 22:13:33 +1000 Subject: [PATCH] Qt: Fix list focus restoration after system shutdown --- src/duckstation-qt/gamelistwidget.cpp | 15 +++++++++++++-- src/duckstation-qt/mainwindow.cpp | 27 +++++++++++++-------------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/duckstation-qt/gamelistwidget.cpp b/src/duckstation-qt/gamelistwidget.cpp index 80ccd09f95..ca907cb057 100644 --- a/src/duckstation-qt/gamelistwidget.cpp +++ b/src/duckstation-qt/gamelistwidget.cpp @@ -244,10 +244,12 @@ void GameListWidget::initialize() connect(m_empty_ui.scanForNewGames, &QPushButton::clicked, this, [this]() { refresh(false); }); m_ui.stack->insertWidget(2, m_empty_widget); - if (Host::GetBaseBoolSettingValue("UI", "GameListGridView", false)) + const bool grid_view = Host::GetBaseBoolSettingValue("UI", "GameListGridView", false); + if (grid_view) m_ui.stack->setCurrentIndex(1); else m_ui.stack->setCurrentIndex(0); + setFocusProxy(grid_view ? static_cast(m_list_view) : static_cast(m_table_view)); updateToolbar(); resizeTableViewColumnsToFit(); @@ -323,7 +325,11 @@ void GameListWidget::onRefreshProgress(const QString& status, int current, int t // switch away from the placeholder while we scan, in case we find anything if (m_ui.stack->currentIndex() == 2) - m_ui.stack->setCurrentIndex(Host::GetBaseBoolSettingValue("UI", "GameListGridView", false) ? 1 : 0); + { + const bool grid_view = Host::GetBaseBoolSettingValue("UI", "GameListGridView", false); + m_ui.stack->setCurrentIndex(grid_view ? 1 : 0); + setFocusProxy(grid_view ? static_cast(m_list_view) : static_cast(m_table_view)); + } if (!m_model->hasTakenGameList() || time >= SHORT_REFRESH_TIME) emit refreshProgress(status, current, total); @@ -341,7 +347,10 @@ void GameListWidget::onRefreshComplete() // if we still had no games, switch to the helper widget if (m_model->rowCount() == 0) + { m_ui.stack->setCurrentIndex(2); + setFocusProxy(nullptr); + } } void GameListWidget::onSelectionModelCurrentChanged(const QModelIndex& current, const QModelIndex& previous) @@ -468,6 +477,7 @@ void GameListWidget::showGameList() Host::SetBaseBoolSettingValue("UI", "GameListGridView", false); Host::CommitBaseSettingChanges(); m_ui.stack->setCurrentIndex(0); + setFocusProxy(m_table_view); resizeTableViewColumnsToFit(); updateToolbar(); emit layoutChange(); @@ -484,6 +494,7 @@ void GameListWidget::showGameGrid() Host::SetBaseBoolSettingValue("UI", "GameListGridView", true); Host::CommitBaseSettingChanges(); m_ui.stack->setCurrentIndex(1); + setFocusProxy(m_list_view); updateToolbar(); emit layoutChange(); } diff --git a/src/duckstation-qt/mainwindow.cpp b/src/duckstation-qt/mainwindow.cpp index 2d9a6d430d..eac232cc11 100644 --- a/src/duckstation-qt/mainwindow.cpp +++ b/src/duckstation-qt/mainwindow.cpp @@ -2003,23 +2003,22 @@ bool MainWindow::shouldHideMainWindow() const void MainWindow::switchToGameListView() { - if (isShowingGameList()) + if (!isShowingGameList()) { - m_game_list_widget->setFocus(); - return; + if (m_display_created) + { + m_was_paused_on_surface_loss = s_system_paused; + if (!s_system_paused) + g_emu_thread->setSystemPaused(true); + + // switch to surfaceless. we have to wait until the display widget is gone before we swap over. + g_emu_thread->setSurfaceless(true); + while (m_display_widget) + QApplication::processEvents(QEventLoop::ExcludeUserInputEvents, 1); + } } - if (m_display_created) - { - m_was_paused_on_surface_loss = s_system_paused; - if (!s_system_paused) - g_emu_thread->setSystemPaused(true); - - // switch to surfaceless. we have to wait until the display widget is gone before we swap over. - g_emu_thread->setSurfaceless(true); - while (m_display_widget) - QApplication::processEvents(QEventLoop::ExcludeUserInputEvents, 1); - } + m_game_list_widget->setFocus(); } void MainWindow::switchToEmulationView()