vcl/inc/qt5/QtInstance.hxx |    8 ++++++++
 vcl/qt5/QtInstance.cxx     |   36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+)

New commits:
commit ced4cde59eb51e4364daf69520a184b55c2c54db
Author:     Jan-Marek Glogowski <glo...@fbihome.de>
AuthorDate: Sun Jan 16 10:14:47 2022 +0100
Commit:     Jan-Marek Glogowski <glo...@fbihome.de>
CommitDate: Sun Jan 16 14:42:31 2022 +0100

    Qt notify LO of many QScreen related events
    
    LO just has a single display event, SalEvent::DisplayChanged, Qt
    has a multitude. So this will generate multiple LO notifications.
    I don't see any reasonable way to prevent that. Doesn't seem a
    problem here.
    
    Change-Id: I2f11e53765869a4ca292a1d337347e4e7470e3c2
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128474
    Tested-by: Jenkins
    Reviewed-by: Jan-Marek Glogowski <glo...@fbihome.de>

diff --git a/vcl/inc/qt5/QtInstance.hxx b/vcl/inc/qt5/QtInstance.hxx
index 24629a36af8c..1511996c0ce0 100644
--- a/vcl/inc/qt5/QtInstance.hxx
+++ b/vcl/inc/qt5/QtInstance.hxx
@@ -75,6 +75,12 @@ private Q_SLOTS:
     static void deleteObjectLater(QObject* pObject);
     static void localeChanged();
 
+    void orientationChanged(Qt::ScreenOrientation);
+    void primaryScreenChanged(QScreen*);
+    void screenAdded(QScreen*);
+    void screenRemoved(QScreen*);
+    void virtualGeometryChanged(const QRect&);
+
 Q_SIGNALS:
     bool ImplYieldSignal(bool bWait, bool bHandleAllCurrentEvents);
     void deleteObjectLaterSignal(QObject* pObject);
@@ -86,6 +92,8 @@ protected:
     bool useCairo() const { return m_bUseCairo; }
     // encodes cairo usage and Qt platform name into the ToolkitName
     OUString constructToolkitID(std::u16string_view sTKname);
+    void connectQScreenSignals(const QScreen*);
+    void notifyDisplayChanged();
 
 public:
     explicit QtInstance(std::unique_ptr<QApplication>& pQApp, bool bUseCairo = 
false);
diff --git a/vcl/qt5/QtInstance.cxx b/vcl/qt5/QtInstance.cxx
index bb7e98c051cd..9629532f824b 100644
--- a/vcl/qt5/QtInstance.cxx
+++ b/vcl/qt5/QtInstance.cxx
@@ -40,6 +40,7 @@
 
 #include <QtCore/QAbstractEventDispatcher>
 #include <QtCore/QThread>
+#include <QtGui/QScreen>
 #include <QtWidgets/QApplication>
 #include <QtWidgets/QWidget>
 
@@ -250,6 +251,12 @@ QtInstance::QtInstance(std::unique_ptr<QApplication>& 
pQApp, bool bUseCairo)
     connect(QGuiApplication::inputMethod(), &QInputMethod::localeChanged, this,
             &QtInstance::localeChanged);
 
+    for (const QScreen* pCurScreen : QApplication::screens())
+        connectQScreenSignals(pCurScreen);
+    connect(qApp, &QGuiApplication::primaryScreenChanged, this, 
&QtInstance::primaryScreenChanged);
+    connect(qApp, &QGuiApplication::screenAdded, this, 
&QtInstance::screenAdded);
+    connect(qApp, &QGuiApplication::screenRemoved, this, 
&QtInstance::screenRemoved);
+
 #ifndef EMSCRIPTEN
     m_bSupportsOpenGL = true;
 #endif
@@ -604,6 +611,35 @@ void* QtInstance::CreateGStreamerSink(const 
SystemChildWindow* pWindow)
 #endif
 }
 
+void QtInstance::connectQScreenSignals(const QScreen* pScreen)
+{
+    connect(pScreen, &QScreen::orientationChanged, this, 
&QtInstance::orientationChanged);
+    connect(pScreen, &QScreen::virtualGeometryChanged, this, 
&QtInstance::virtualGeometryChanged);
+}
+
+void QtInstance::notifyDisplayChanged()
+{
+    SolarMutexGuard aGuard;
+    SalFrame* pAnyFrame = anyFrame();
+    if (pAnyFrame)
+        pAnyFrame->CallCallback(SalEvent::DisplayChanged, nullptr);
+}
+
+void QtInstance::orientationChanged(Qt::ScreenOrientation) { 
notifyDisplayChanged(); }
+
+void QtInstance::primaryScreenChanged(QScreen*) { notifyDisplayChanged(); }
+
+void QtInstance::screenAdded(QScreen* pScreen)
+{
+    connectQScreenSignals(pScreen);
+    if (QApplication::screens().size() == 1)
+        notifyDisplayChanged();
+}
+
+void QtInstance::screenRemoved(QScreen*) { notifyDisplayChanged(); }
+
+void QtInstance::virtualGeometryChanged(const QRect&) { 
notifyDisplayChanged(); }
+
 void QtInstance::AllocFakeCmdlineArgs(std::unique_ptr<char* []>& rFakeArgv,
                                       std::unique_ptr<int>& rFakeArgc,
                                       std::vector<FreeableCStr>& 
rFakeArgvFreeable)

Reply via email to