Qt: Force redraw the display when restoring after minimized

This commit is contained in:
Connor McLaughlin 2020-03-22 21:50:49 +10:00
parent 361bedc2c3
commit 1d9bcb2a48
6 changed files with 42 additions and 0 deletions

View File

@ -14,6 +14,7 @@
#include <QtCore/QFileInfo> #include <QtCore/QFileInfo>
#include <QtCore/QUrl> #include <QtCore/QUrl>
#include <QtGui/QDesktopServices> #include <QtGui/QDesktopServices>
#include <QtGui/QWindowStateChangeEvent>
#include <QtWidgets/QFileDialog> #include <QtWidgets/QFileDialog>
#include <QtWidgets/QMessageBox> #include <QtWidgets/QMessageBox>
#include <cmath> #include <cmath>
@ -568,3 +569,15 @@ void MainWindow::closeEvent(QCloseEvent* event)
m_host_interface->synchronousPowerOffSystem(); m_host_interface->synchronousPowerOffSystem();
QMainWindow::closeEvent(event); QMainWindow::closeEvent(event);
} }
void MainWindow::changeEvent(QEvent* event)
{
if (static_cast<QWindowStateChangeEvent*>(event)->oldState()& Qt::WindowMinimized)
{
// TODO: This should check the render-to-main option.
if (m_display_widget)
m_host_interface->redrawDisplayWindow();
}
QMainWindow::changeEvent(event);
}

View File

@ -55,6 +55,7 @@ private Q_SLOTS:
protected: protected:
void closeEvent(QCloseEvent* event) override; void closeEvent(QCloseEvent* event) override;
void changeEvent(QEvent* event) override;
private: private:
void setupAdditionalUi(); void setupAdditionalUi();

View File

@ -7,6 +7,7 @@
#include <QtGui/QKeyEvent> #include <QtGui/QKeyEvent>
#include <QtGui/QScreen> #include <QtGui/QScreen>
#include <QtGui/QWindow> #include <QtGui/QWindow>
#include <QtGui/QWindowStateChangeEvent>
#include <cmath> #include <cmath>
QtDisplayWidget::QtDisplayWidget(QtHostInterface* host_interface, QWidget* parent) QtDisplayWidget::QtDisplayWidget(QtHostInterface* host_interface, QWidget* parent)
@ -144,6 +145,16 @@ bool QtDisplayWidget::event(QEvent* event)
return true; return true;
} }
case QEvent::WindowStateChange:
{
QWidget::event(event);
if (static_cast<QWindowStateChangeEvent*>(event)->oldState() & Qt::WindowMinimized)
emit windowRestoredEvent();
return true;
}
default: default:
return QWidget::event(event); return QWidget::event(event);
} }

View File

@ -31,6 +31,7 @@ public:
Q_SIGNALS: Q_SIGNALS:
void windowResizedEvent(int width, int height); void windowResizedEvent(int width, int height);
void windowRestoredEvent();
protected: protected:
qreal getDevicePixelRatioFromScreen() const; qreal getDevicePixelRatioFromScreen() const;

View File

@ -189,6 +189,7 @@ QtDisplayWidget* QtHostInterface::createDisplayWidget()
m_display_widget = new OpenGLDisplayWidget(this, nullptr); m_display_widget = new OpenGLDisplayWidget(this, nullptr);
#endif #endif
connect(m_display_widget, &QtDisplayWidget::windowResizedEvent, this, &QtHostInterface::onDisplayWidgetResized); connect(m_display_widget, &QtDisplayWidget::windowResizedEvent, this, &QtHostInterface::onDisplayWidgetResized);
connect(m_display_widget, &QtDisplayWidget::windowRestoredEvent, this, &QtHostInterface::redrawDisplayWindow);
return m_display_widget; return m_display_widget;
} }
@ -242,6 +243,20 @@ void QtHostInterface::onDisplayWidgetResized(int width, int height)
renderDisplay(); renderDisplay();
} }
void QtHostInterface::redrawDisplayWindow()
{
if (!isOnWorkerThread())
{
QMetaObject::invokeMethod(this, "redrawDisplayWindow", Qt::QueuedConnection);
return;
}
if (!m_display_widget || !m_system)
return;
renderDisplay();
}
bool QtHostInterface::AcquireHostDisplay() bool QtHostInterface::AcquireHostDisplay()
{ {
DebugAssert(!m_display_widget); DebugAssert(!m_display_widget);

View File

@ -102,6 +102,7 @@ public Q_SLOTS:
void startDumpingAudio(); void startDumpingAudio();
void stopDumpingAudio(); void stopDumpingAudio();
void saveScreenshot(); void saveScreenshot();
void redrawDisplayWindow();
/// Enables controller polling even without a system active. Must be matched by a call to /// Enables controller polling even without a system active. Must be matched by a call to
/// disableBackgroundControllerPolling. /// disableBackgroundControllerPolling.