Qt: Fix list focus restoration after system shutdown

This commit is contained in:
Stenzek 2024-08-17 22:13:33 +10:00
parent 2f5aa45e1f
commit add46248a3
No known key found for this signature in database
2 changed files with 26 additions and 16 deletions

View file

@ -244,10 +244,12 @@ void GameListWidget::initialize()
connect(m_empty_ui.scanForNewGames, &QPushButton::clicked, this, [this]() { refresh(false); }); connect(m_empty_ui.scanForNewGames, &QPushButton::clicked, this, [this]() { refresh(false); });
m_ui.stack->insertWidget(2, m_empty_widget); 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); m_ui.stack->setCurrentIndex(1);
else else
m_ui.stack->setCurrentIndex(0); m_ui.stack->setCurrentIndex(0);
setFocusProxy(grid_view ? static_cast<QWidget*>(m_list_view) : static_cast<QWidget*>(m_table_view));
updateToolbar(); updateToolbar();
resizeTableViewColumnsToFit(); 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 // switch away from the placeholder while we scan, in case we find anything
if (m_ui.stack->currentIndex() == 2) 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<QWidget*>(m_list_view) : static_cast<QWidget*>(m_table_view));
}
if (!m_model->hasTakenGameList() || time >= SHORT_REFRESH_TIME) if (!m_model->hasTakenGameList() || time >= SHORT_REFRESH_TIME)
emit refreshProgress(status, current, total); emit refreshProgress(status, current, total);
@ -341,7 +347,10 @@ void GameListWidget::onRefreshComplete()
// if we still had no games, switch to the helper widget // if we still had no games, switch to the helper widget
if (m_model->rowCount() == 0) if (m_model->rowCount() == 0)
{
m_ui.stack->setCurrentIndex(2); m_ui.stack->setCurrentIndex(2);
setFocusProxy(nullptr);
}
} }
void GameListWidget::onSelectionModelCurrentChanged(const QModelIndex& current, const QModelIndex& previous) void GameListWidget::onSelectionModelCurrentChanged(const QModelIndex& current, const QModelIndex& previous)
@ -468,6 +477,7 @@ void GameListWidget::showGameList()
Host::SetBaseBoolSettingValue("UI", "GameListGridView", false); Host::SetBaseBoolSettingValue("UI", "GameListGridView", false);
Host::CommitBaseSettingChanges(); Host::CommitBaseSettingChanges();
m_ui.stack->setCurrentIndex(0); m_ui.stack->setCurrentIndex(0);
setFocusProxy(m_table_view);
resizeTableViewColumnsToFit(); resizeTableViewColumnsToFit();
updateToolbar(); updateToolbar();
emit layoutChange(); emit layoutChange();
@ -484,6 +494,7 @@ void GameListWidget::showGameGrid()
Host::SetBaseBoolSettingValue("UI", "GameListGridView", true); Host::SetBaseBoolSettingValue("UI", "GameListGridView", true);
Host::CommitBaseSettingChanges(); Host::CommitBaseSettingChanges();
m_ui.stack->setCurrentIndex(1); m_ui.stack->setCurrentIndex(1);
setFocusProxy(m_list_view);
updateToolbar(); updateToolbar();
emit layoutChange(); emit layoutChange();
} }

View file

@ -2003,23 +2003,22 @@ bool MainWindow::shouldHideMainWindow() const
void MainWindow::switchToGameListView() void MainWindow::switchToGameListView()
{ {
if (isShowingGameList()) if (!isShowingGameList())
{ {
m_game_list_widget->setFocus(); if (m_display_created)
return; {
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_game_list_widget->setFocus();
{
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);
}
} }
void MainWindow::switchToEmulationView() void MainWindow::switchToEmulationView()