From 61ffb5c4d80e492ee7a6094260c03f30dbd3bfef Mon Sep 17 00:00:00 2001 From: jpark37 Date: Tue, 8 Feb 2022 23:34:45 -0800 Subject: [PATCH] UI: Add OBSQTDisplay::OnMove()/OnDisplayChange() This plumbing will be useful when handling color space changes. Currently does nothing, and only Windows is wired for now. --- UI/qt-display.cpp | 47 ++++++++++++++++++++++++++++----- UI/qt-display.hpp | 15 +++++++++-- UI/window-basic-filters.cpp | 31 ++++++++++++++++++++++ UI/window-basic-filters.hpp | 7 +++++ UI/window-basic-interaction.cpp | 32 ++++++++++++++++++++++ UI/window-basic-interaction.hpp | 7 +++++ UI/window-basic-main.cpp | 26 ++++++++++++++++++ UI/window-basic-main.hpp | 7 +++++ UI/window-basic-properties.cpp | 32 ++++++++++++++++++++++ UI/window-basic-properties.hpp | 7 +++++ 10 files changed, 202 insertions(+), 9 deletions(-) diff --git a/UI/qt-display.cpp b/UI/qt-display.cpp index 901390ee9..7dca7ead4 100644 --- a/UI/qt-display.cpp +++ b/UI/qt-display.cpp @@ -8,6 +8,11 @@ #include +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN +#include +#endif + #ifdef ENABLE_WAYLAND #include @@ -166,6 +171,37 @@ void OBSQTDisplay::CreateDisplay(bool force) emit DisplayCreated(this); } +void OBSQTDisplay::paintEvent(QPaintEvent *event) +{ + CreateDisplay(); + + QWidget::paintEvent(event); +} + +void OBSQTDisplay::moveEvent(QMoveEvent *event) +{ + QWidget::moveEvent(event); + + OnMove(); +} + +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +bool OBSQTDisplay::nativeEvent(const QByteArray &, void *message, qintptr *) +#else +bool OBSQTDisplay::nativeEvent(const QByteArray &, void *message, long *) +#endif +{ +#ifdef _WIN32 + const MSG &msg = *static_cast(message); + switch (msg.message) { + case WM_DISPLAYCHANGE: + OnDisplayChange(); + } +#endif + + return false; +} + void OBSQTDisplay::resizeEvent(QResizeEvent *event) { QWidget::resizeEvent(event); @@ -180,14 +216,11 @@ void OBSQTDisplay::resizeEvent(QResizeEvent *event) emit DisplayResized(); } -void OBSQTDisplay::paintEvent(QPaintEvent *event) -{ - CreateDisplay(); - - QWidget::paintEvent(event); -} - QPaintEngine *OBSQTDisplay::paintEngine() const { return nullptr; } + +void OBSQTDisplay::OnMove() {} + +void OBSQTDisplay::OnDisplayChange() {} diff --git a/UI/qt-display.hpp b/UI/qt-display.hpp index c48c12673..1edba68de 100644 --- a/UI/qt-display.hpp +++ b/UI/qt-display.hpp @@ -13,8 +13,16 @@ class OBSQTDisplay : public QWidget { OBSDisplay display; - void resizeEvent(QResizeEvent *event) override; - void paintEvent(QPaintEvent *event) override; + virtual void paintEvent(QPaintEvent *event) override; + virtual void moveEvent(QMoveEvent *event) override; + virtual void resizeEvent(QResizeEvent *event) override; +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + virtual bool nativeEvent(const QByteArray &eventType, void *message, + qintptr *result) override; +#else + virtual bool nativeEvent(const QByteArray &eventType, void *message, + long *result) override; +#endif signals: void DisplayCreated(OBSQTDisplay *window); @@ -35,4 +43,7 @@ public: void SetDisplayBackgroundColor(const QColor &color); void UpdateDisplayBackgroundColor(); void CreateDisplay(bool force = false); + + void OnMove(); + void OnDisplayChange(); }; diff --git a/UI/window-basic-filters.cpp b/UI/window-basic-filters.cpp index c8ad1b07f..75d81ffc4 100644 --- a/UI/window-basic-filters.cpp +++ b/UI/window-basic-filters.cpp @@ -36,6 +36,11 @@ #include #include +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN 1 +#include +#endif + using namespace std; Q_DECLARE_METATYPE(OBSSource); @@ -686,6 +691,32 @@ void OBSBasicFilters::closeEvent(QCloseEvent *event) main->SaveProject(); } +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +bool OBSBasicFilters::nativeEvent(const QByteArray &, void *message, qintptr *) +#else +bool OBSBasicFilters::nativeEvent(const QByteArray &, void *message, long *) +#endif +{ +#ifdef _WIN32 + const MSG &msg = *static_cast(message); + switch (msg.message) { + case WM_MOVE: + for (OBSQTDisplay *const display : + findChildren()) { + display->OnMove(); + } + break; + case WM_DISPLAYCHANGE: + for (OBSQTDisplay *const display : + findChildren()) { + display->OnDisplayChange(); + } + } +#endif + + return false; +} + /* OBS Signals */ void OBSBasicFilters::OBSSourceFilterAdded(void *param, calldata_t *data) diff --git a/UI/window-basic-filters.hpp b/UI/window-basic-filters.hpp index 063367382..bd3f6a4bc 100644 --- a/UI/window-basic-filters.hpp +++ b/UI/window-basic-filters.hpp @@ -135,4 +135,11 @@ public: protected: virtual void closeEvent(QCloseEvent *event) override; +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + virtual bool nativeEvent(const QByteArray &eventType, void *message, + qintptr *result) override; +#else + virtual bool nativeEvent(const QByteArray &eventType, void *message, + long *result) override; +#endif }; diff --git a/UI/window-basic-interaction.cpp b/UI/window-basic-interaction.cpp index b2788259b..b830ee8dc 100644 --- a/UI/window-basic-interaction.cpp +++ b/UI/window-basic-interaction.cpp @@ -26,6 +26,11 @@ #include #include +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN 1 +#include +#endif + using namespace std; OBSBasicInteraction::OBSBasicInteraction(QWidget *parent, OBSSource source_) @@ -175,6 +180,33 @@ void OBSBasicInteraction::closeEvent(QCloseEvent *event) this); } +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +bool OBSBasicInteraction::nativeEvent(const QByteArray &, void *message, + qintptr *) +#else +bool OBSBasicInteraction::nativeEvent(const QByteArray &, void *message, long *) +#endif +{ +#ifdef _WIN32 + const MSG &msg = *static_cast(message); + switch (msg.message) { + case WM_MOVE: + for (OBSQTDisplay *const display : + findChildren()) { + display->OnMove(); + } + break; + case WM_DISPLAYCHANGE: + for (OBSQTDisplay *const display : + findChildren()) { + display->OnDisplayChange(); + } + } +#endif + + return false; +} + static int TranslateQtKeyboardEventModifiers(QInputEvent *event, bool mouseEvent) { diff --git a/UI/window-basic-interaction.hpp b/UI/window-basic-interaction.hpp index 4d53b837a..3b9241848 100644 --- a/UI/window-basic-interaction.hpp +++ b/UI/window-basic-interaction.hpp @@ -65,6 +65,13 @@ public: protected: virtual void closeEvent(QCloseEvent *event) override; +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + virtual bool nativeEvent(const QByteArray &eventType, void *message, + qintptr *result) override; +#else + virtual bool nativeEvent(const QByteArray &eventType, void *message, + long *result) override; +#endif }; typedef std::function EventFilterFunc; diff --git a/UI/window-basic-main.cpp b/UI/window-basic-main.cpp index 1cadc9052..94c849ce2 100644 --- a/UI/window-basic-main.cpp +++ b/UI/window-basic-main.cpp @@ -4680,6 +4680,32 @@ void OBSBasic::closeEvent(QCloseEvent *event) QMetaObject::invokeMethod(App(), "quit", Qt::QueuedConnection); } +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +bool OBSBasic::nativeEvent(const QByteArray &, void *message, qintptr *) +#else +bool OBSBasic::nativeEvent(const QByteArray &, void *message, long *) +#endif +{ +#ifdef _WIN32 + const MSG &msg = *static_cast(message); + switch (msg.message) { + case WM_MOVE: + for (OBSQTDisplay *const display : + findChildren()) { + display->OnMove(); + } + break; + case WM_DISPLAYCHANGE: + for (OBSQTDisplay *const display : + findChildren()) { + display->OnDisplayChange(); + } + } +#endif + + return false; +} + void OBSBasic::changeEvent(QEvent *event) { if (event->type() == QEvent::WindowStateChange) { diff --git a/UI/window-basic-main.hpp b/UI/window-basic-main.hpp index 9e54ef891..881050d9b 100644 --- a/UI/window-basic-main.hpp +++ b/UI/window-basic-main.hpp @@ -947,6 +947,13 @@ public: protected: virtual void closeEvent(QCloseEvent *event) override; +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + virtual bool nativeEvent(const QByteArray &eventType, void *message, + qintptr *result) override; +#else + virtual bool nativeEvent(const QByteArray &eventType, void *message, + long *result) override; +#endif virtual void changeEvent(QEvent *event) override; private slots: diff --git a/UI/window-basic-properties.cpp b/UI/window-basic-properties.cpp index 945c8d408..885ae9576 100644 --- a/UI/window-basic-properties.cpp +++ b/UI/window-basic-properties.cpp @@ -31,6 +31,11 @@ #include #include +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN 1 +#include +#endif + using namespace std; static void CreateTransitionScene(OBSSource scene, const char *text, @@ -512,6 +517,33 @@ void OBSBasicProperties::closeEvent(QCloseEvent *event) Cleanup(); } +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +bool OBSBasicProperties::nativeEvent(const QByteArray &, void *message, + qintptr *) +#else +bool OBSBasicProperties::nativeEvent(const QByteArray &, void *message, long *) +#endif +{ +#ifdef _WIN32 + const MSG &msg = *static_cast(message); + switch (msg.message) { + case WM_MOVE: + for (OBSQTDisplay *const display : + findChildren()) { + display->OnMove(); + } + break; + case WM_DISPLAYCHANGE: + for (OBSQTDisplay *const display : + findChildren()) { + display->OnDisplayChange(); + } + } +#endif + + return false; +} + void OBSBasicProperties::Init() { show(); diff --git a/UI/window-basic-properties.hpp b/UI/window-basic-properties.hpp index 3630908e7..2a4f6a4e2 100644 --- a/UI/window-basic-properties.hpp +++ b/UI/window-basic-properties.hpp @@ -72,5 +72,12 @@ public: protected: virtual void closeEvent(QCloseEvent *event) override; +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + virtual bool nativeEvent(const QByteArray &eventType, void *message, + qintptr *result) override; +#else + virtual bool nativeEvent(const QByteArray &eventType, void *message, + long *result) override; +#endif virtual void reject() override; };