diff --git a/src/duckstation-qt/mainwindow.cpp b/src/duckstation-qt/mainwindow.cpp index 21b877fb8..ad00c8f52 100644 --- a/src/duckstation-qt/mainwindow.cpp +++ b/src/duckstation-qt/mainwindow.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -568,3 +569,15 @@ void MainWindow::closeEvent(QCloseEvent* event) m_host_interface->synchronousPowerOffSystem(); QMainWindow::closeEvent(event); } + +void MainWindow::changeEvent(QEvent* event) +{ + if (static_cast(event)->oldState()& Qt::WindowMinimized) + { + // TODO: This should check the render-to-main option. + if (m_display_widget) + m_host_interface->redrawDisplayWindow(); + } + + QMainWindow::changeEvent(event); +} diff --git a/src/duckstation-qt/mainwindow.h b/src/duckstation-qt/mainwindow.h index b1a1cf4a4..17960e061 100644 --- a/src/duckstation-qt/mainwindow.h +++ b/src/duckstation-qt/mainwindow.h @@ -55,6 +55,7 @@ private Q_SLOTS: protected: void closeEvent(QCloseEvent* event) override; + void changeEvent(QEvent* event) override; private: void setupAdditionalUi(); diff --git a/src/duckstation-qt/qtdisplaywidget.cpp b/src/duckstation-qt/qtdisplaywidget.cpp index 4edb0703f..6c8fcf178 100644 --- a/src/duckstation-qt/qtdisplaywidget.cpp +++ b/src/duckstation-qt/qtdisplaywidget.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include QtDisplayWidget::QtDisplayWidget(QtHostInterface* host_interface, QWidget* parent) @@ -144,6 +145,16 @@ bool QtDisplayWidget::event(QEvent* event) return true; } + case QEvent::WindowStateChange: + { + QWidget::event(event); + + if (static_cast(event)->oldState() & Qt::WindowMinimized) + emit windowRestoredEvent(); + + return true; + } + default: return QWidget::event(event); } diff --git a/src/duckstation-qt/qtdisplaywidget.h b/src/duckstation-qt/qtdisplaywidget.h index b900f1445..4f5e1037b 100644 --- a/src/duckstation-qt/qtdisplaywidget.h +++ b/src/duckstation-qt/qtdisplaywidget.h @@ -31,6 +31,7 @@ public: Q_SIGNALS: void windowResizedEvent(int width, int height); + void windowRestoredEvent(); protected: qreal getDevicePixelRatioFromScreen() const; diff --git a/src/duckstation-qt/qthostinterface.cpp b/src/duckstation-qt/qthostinterface.cpp index 109637723..0fcb791d1 100644 --- a/src/duckstation-qt/qthostinterface.cpp +++ b/src/duckstation-qt/qthostinterface.cpp @@ -189,6 +189,7 @@ QtDisplayWidget* QtHostInterface::createDisplayWidget() m_display_widget = new OpenGLDisplayWidget(this, nullptr); #endif connect(m_display_widget, &QtDisplayWidget::windowResizedEvent, this, &QtHostInterface::onDisplayWidgetResized); + connect(m_display_widget, &QtDisplayWidget::windowRestoredEvent, this, &QtHostInterface::redrawDisplayWindow); return m_display_widget; } @@ -242,6 +243,20 @@ void QtHostInterface::onDisplayWidgetResized(int width, int height) renderDisplay(); } +void QtHostInterface::redrawDisplayWindow() +{ + if (!isOnWorkerThread()) + { + QMetaObject::invokeMethod(this, "redrawDisplayWindow", Qt::QueuedConnection); + return; + } + + if (!m_display_widget || !m_system) + return; + + renderDisplay(); +} + bool QtHostInterface::AcquireHostDisplay() { DebugAssert(!m_display_widget); diff --git a/src/duckstation-qt/qthostinterface.h b/src/duckstation-qt/qthostinterface.h index 804110417..f5dc49173 100644 --- a/src/duckstation-qt/qthostinterface.h +++ b/src/duckstation-qt/qthostinterface.h @@ -102,6 +102,7 @@ public Q_SLOTS: void startDumpingAudio(); void stopDumpingAudio(); void saveScreenshot(); + void redrawDisplayWindow(); /// Enables controller polling even without a system active. Must be matched by a call to /// disableBackgroundControllerPolling.