[Libreoffice-commits] core.git: vcl/inc vcl/qt5

Jan-Marek Glogowski (via logerrit) logerrit at kemper.freedesktop.org
Fri Jul 3 13:59:44 UTC 2020


 vcl/inc/qt5/Qt5Instance.hxx |    7 ++++---
 vcl/inc/qt5/Qt5Timer.hxx    |    2 ++
 vcl/qt5/Qt5Instance.cxx     |   43 +++++++++++++++++++++++++------------------
 3 files changed, 31 insertions(+), 21 deletions(-)

New commits:
commit 47c098e5760537e8c43a92c9dbe16ace3902a19d
Author:     Jan-Marek Glogowski <glogow at fbihome.de>
AuthorDate: Sun Jun 2 21:08:25 2019 +0000
Commit:     Jan-Marek Glogowski <glogow at fbihome.de>
CommitDate: Fri Jul 3 15:58:54 2020 +0200

    Qt5 better / working wakeup handling
    
    Report some of the stuff we can in AnyInput. And instead of
    posting an event, just use QAbstractEventDispatcher::wakeUp().
    
    Change-Id: I020a71eca7208030ddbfcd2b16d9bc4ceff315e5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/73676
    Tested-by: Jenkins
    Reviewed-by: Jan-Marek Glogowski <glogow at fbihome.de>

diff --git a/vcl/inc/qt5/Qt5Instance.hxx b/vcl/inc/qt5/Qt5Instance.hxx
index 361eca0fc519..232606c48062 100644
--- a/vcl/inc/qt5/Qt5Instance.hxx
+++ b/vcl/inc/qt5/Qt5Instance.hxx
@@ -35,6 +35,8 @@
 
 #include "Qt5FilePicker.hxx"
 
+class Qt5Timer;
+
 class QApplication;
 class SalYieldMutex;
 class SalFrame;
@@ -52,8 +54,9 @@ class VCLPLUG_QT5_PUBLIC Qt5Instance : public QObject,
     Q_OBJECT
 
     osl::Condition m_aWaitingYieldCond;
-    int m_postUserEventId;
     const bool m_bUseCairo;
+    Qt5Timer* m_pTimer;
+    bool m_bSleeping;
     std::unordered_map<OUString, css::uno::Reference<css::uno::XInterface>> m_aClipboards;
 
     std::unique_ptr<QApplication> m_pQApplication;
@@ -69,12 +72,10 @@ class VCLPLUG_QT5_PUBLIC Qt5Instance : public QObject,
 
 private Q_SLOTS:
     bool ImplYield(bool bWait, bool bHandleAllCurrentEvents);
-    void ImplRunInMain();
     static void deleteObjectLater(QObject* pObject);
 
 Q_SIGNALS:
     bool ImplYieldSignal(bool bWait, bool bHandleAllCurrentEvents);
-    void ImplRunInMainSignal();
     void deleteObjectLaterSignal(QObject* pObject);
 
 protected:
diff --git a/vcl/inc/qt5/Qt5Timer.hxx b/vcl/inc/qt5/Qt5Timer.hxx
index 20b2a4c70cf7..99878e67ad6b 100644
--- a/vcl/inc/qt5/Qt5Timer.hxx
+++ b/vcl/inc/qt5/Qt5Timer.hxx
@@ -40,6 +40,8 @@ Q_SIGNALS:
 public:
     Qt5Timer();
 
+    int remainingTime() const { return m_aTimer.remainingTime(); }
+
     virtual void Start(sal_uInt64 nMS) override;
     virtual void Stop() override;
 };
diff --git a/vcl/qt5/Qt5Instance.cxx b/vcl/qt5/Qt5Instance.cxx
index 06b959b9163e..1868042cdb6d 100644
--- a/vcl/qt5/Qt5Instance.cxx
+++ b/vcl/qt5/Qt5Instance.cxx
@@ -187,10 +187,8 @@ void Qt5Instance::RunInMainThread(std::function<void()> func)
         pMutex->m_isWakeUpMain = true;
         pMutex->m_InMainCondition.notify_all();
     }
-    // wake up main thread in case it is blocked on event queue
-    // TriggerUserEventProcessing() appears to be insufficient in case the
-    // main thread does QEventLoop::WaitForMoreEvents
-    Q_EMIT ImplRunInMainSignal();
+
+    TriggerUserEventProcessing();
     {
         std::unique_lock<std::mutex> g(pMutex->m_RunInMainMutex);
         pMutex->m_ResultCondition.wait(g, [pMutex]() { return pMutex->m_isResultReady; });
@@ -198,16 +196,11 @@ void Qt5Instance::RunInMainThread(std::function<void()> func)
     }
 }
 
-void Qt5Instance::ImplRunInMain()
-{
-    SolarMutexGuard g; // trigger the dispatch code in Qt5YieldMutex::doAcquire
-    (void)this; // suppress unhelpful [loplugin:staticmethods]; can't be static
-}
-
 Qt5Instance::Qt5Instance(std::unique_ptr<QApplication>& pQApp, bool bUseCairo)
     : SalGenericInstance(std::make_unique<Qt5YieldMutex>())
-    , m_postUserEventId(-1)
     , m_bUseCairo(bUseCairo)
+    , m_pTimer(nullptr)
+    , m_bSleeping(false)
     , m_pQApplication(std::move(pQApp))
     , m_aUpdateStyleTimer("vcl::qt5 m_aUpdateStyleTimer")
     , m_bUpdateFonts(false)
@@ -218,14 +211,10 @@ Qt5Instance::Qt5Instance(std::unique_ptr<QApplication>& pQApp, bool bUseCairo)
     else
         pSVData->maAppData.mxToolkitName = OUString("qt5");
 
-    m_postUserEventId = QEvent::registerEventType();
-
     // this one needs to be blocking, so that the handling in main thread
     // is processed before the thread emitting the signal continues
     connect(this, SIGNAL(ImplYieldSignal(bool, bool)), this, SLOT(ImplYield(bool, bool)),
             Qt::BlockingQueuedConnection);
-    connect(this, &Qt5Instance::ImplRunInMainSignal, this, &Qt5Instance::ImplRunInMain,
-            Qt::QueuedConnection); // no Blocking!
 
     // this one needs to be queued non-blocking
     // in order to have this event arriving to correct event processing loop
@@ -235,6 +224,11 @@ Qt5Instance::Qt5Instance(std::unique_ptr<QApplication>& pQApp, bool bUseCairo)
 
     m_aUpdateStyleTimer.SetTimeout(50);
     m_aUpdateStyleTimer.SetInvokeHandler(LINK(this, Qt5Instance, updateStyleHdl));
+
+    QAbstractEventDispatcher* dispatcher = QAbstractEventDispatcher::instance(qApp->thread());
+    connect(dispatcher, &QAbstractEventDispatcher::awake, this, [this]() { m_bSleeping = false; });
+    connect(dispatcher, &QAbstractEventDispatcher::aboutToBlock, this,
+            [this]() { m_bSleeping = true; });
 }
 
 Qt5Instance::~Qt5Instance()
@@ -333,7 +327,11 @@ std::unique_ptr<SalMenuItem> Qt5Instance::CreateMenuItem(const SalItemParams& rI
     return std::unique_ptr<SalMenuItem>(new Qt5MenuItem(&rItemData));
 }
 
-SalTimer* Qt5Instance::CreateSalTimer() { return new Qt5Timer(); }
+SalTimer* Qt5Instance::CreateSalTimer()
+{
+    m_pTimer = new Qt5Timer();
+    return m_pTimer;
+}
 
 SalSystem* Qt5Instance::CreateSalSystem() { return new Qt5System; }
 
@@ -392,7 +390,15 @@ bool Qt5Instance::DoYield(bool bWait, bool bHandleAllCurrentEvents)
     return bWasEvent;
 }
 
-bool Qt5Instance::AnyInput(VclInputFlags /*nType*/) { return false; }
+bool Qt5Instance::AnyInput(VclInputFlags nType)
+{
+    bool bResult = false;
+    if (nType & VclInputFlags::TIMER)
+        bResult |= (m_pTimer && m_pTimer->remainingTime() == 0);
+    if (nType & VclInputFlags::OTHER)
+        bResult |= !m_bSleeping;
+    return bResult;
+}
 
 OUString Qt5Instance::GetConnectionIdentifier() { return OUString(); }
 
@@ -407,7 +413,8 @@ bool Qt5Instance::IsMainThread() const
 
 void Qt5Instance::TriggerUserEventProcessing()
 {
-    QApplication::postEvent(this, new QEvent(QEvent::Type(m_postUserEventId)));
+    QAbstractEventDispatcher* dispatcher = QAbstractEventDispatcher::instance(qApp->thread());
+    dispatcher->wakeUp();
 }
 
 void Qt5Instance::ProcessEvent(SalUserEvent aEvent)


More information about the Libreoffice-commits mailing list