From 27c9f2d834a60d89a2260fbbeec03ae15107c4af Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Wed, 26 Feb 2020 19:26:14 +1000 Subject: [PATCH] Qt: Add a method for the emulation thread to focus the display widget --- src/duckstation-qt/mainwindow.cpp | 19 ++++++++++++++----- src/duckstation-qt/mainwindow.h | 1 + src/duckstation-qt/qthostinterface.cpp | 9 ++++++--- src/duckstation-qt/qthostinterface.h | 1 + 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/duckstation-qt/mainwindow.cpp b/src/duckstation-qt/mainwindow.cpp index 29be72d35..4a67c2d7d 100644 --- a/src/duckstation-qt/mainwindow.cpp +++ b/src/duckstation-qt/mainwindow.cpp @@ -84,11 +84,6 @@ void MainWindow::destroyDisplayWindow() m_display_widget = nullptr; } -void MainWindow::toggleFullscreen() -{ - setFullscreen(!m_display_widget->isFullScreen()); -} - void MainWindow::setFullscreen(bool fullscreen) { if (fullscreen) @@ -110,6 +105,19 @@ void MainWindow::setFullscreen(bool fullscreen) m_ui.actionFullscreen->setChecked(fullscreen); } +void MainWindow::toggleFullscreen() +{ + setFullscreen(!m_display_widget->isFullScreen()); +} + +void MainWindow::focusDisplayWidget() +{ + if (m_ui.mainContainer->currentIndex() != 1) + return; + + m_display_widget->setFocus(); +} + void MainWindow::onEmulationStarted() { m_emulation_running = true; @@ -349,6 +357,7 @@ void MainWindow::connectSignals() connect(m_host_interface, &QtHostInterface::destroyDisplayWindowRequested, this, &MainWindow::destroyDisplayWindow); connect(m_host_interface, &QtHostInterface::setFullscreenRequested, this, &MainWindow::setFullscreen); connect(m_host_interface, &QtHostInterface::toggleFullscreenRequested, this, &MainWindow::toggleFullscreen); + connect(m_host_interface, &QtHostInterface::focusDisplayWidgetRequested, this, &MainWindow::focusDisplayWidget); connect(m_host_interface, &QtHostInterface::emulationStarted, this, &MainWindow::onEmulationStarted); connect(m_host_interface, &QtHostInterface::emulationStopped, this, &MainWindow::onEmulationStopped); connect(m_host_interface, &QtHostInterface::emulationPaused, this, &MainWindow::onEmulationPaused); diff --git a/src/duckstation-qt/mainwindow.h b/src/duckstation-qt/mainwindow.h index 2c19072fe..12b883417 100644 --- a/src/duckstation-qt/mainwindow.h +++ b/src/duckstation-qt/mainwindow.h @@ -29,6 +29,7 @@ private Q_SLOTS: void destroyDisplayWindow(); void setFullscreen(bool fullscreen); void toggleFullscreen(); + void focusDisplayWidget(); void onEmulationStarted(); void onEmulationStopped(); void onEmulationPaused(bool paused); diff --git a/src/duckstation-qt/qthostinterface.cpp b/src/duckstation-qt/qthostinterface.cpp index 896e0fe1c..79b810d75 100644 --- a/src/duckstation-qt/qthostinterface.cpp +++ b/src/duckstation-qt/qthostinterface.cpp @@ -303,10 +303,13 @@ void QtHostInterface::OnSystemPaused(bool paused) { HostInterface::OnSystemPaused(paused); - if (!paused) - wakeThread(); - emit emulationPaused(paused); + + if (!paused) + { + wakeThread(); + emit focusDisplayWidgetRequested(); + } } void QtHostInterface::OnSystemDestroyed() diff --git a/src/duckstation-qt/qthostinterface.h b/src/duckstation-qt/qthostinterface.h index 765c34286..2bcd1ed61 100644 --- a/src/duckstation-qt/qthostinterface.h +++ b/src/duckstation-qt/qthostinterface.h @@ -75,6 +75,7 @@ Q_SIGNALS: void destroyDisplayWindowRequested(); void setFullscreenRequested(bool fullscreen); void toggleFullscreenRequested(); + void focusDisplayWidgetRequested(); void systemPerformanceCountersUpdated(float speed, float fps, float vps, float avg_frame_time, float worst_frame_time); void runningGameChanged(const QString& filename, const QString& game_code, const QString& game_title);