Skip to content

Commit

Permalink
Qt: Fix list focus restoration after system shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Aug 17, 2024
1 parent 2f5aa45 commit add4624
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
15 changes: 13 additions & 2 deletions src/duckstation-qt/gamelistwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QWidget*>(m_list_view) : static_cast<QWidget*>(m_table_view));

updateToolbar();
resizeTableViewColumnsToFit();
Expand Down Expand Up @@ -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<QWidget*>(m_list_view) : static_cast<QWidget*>(m_table_view));
}

if (!m_model->hasTakenGameList() || time >= SHORT_REFRESH_TIME)
emit refreshProgress(status, current, total);
Expand All @@ -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)
Expand Down Expand Up @@ -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();
Expand All @@ -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();
}
Expand Down
27 changes: 13 additions & 14 deletions src/duckstation-qt/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit add4624

Please sign in to comment.