From 45fbeda95b90f85ecd8b7a0c68d593f182b16286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Capello?= Date: Fri, 11 Apr 2025 15:16:09 -0300 Subject: [PATCH] Avoid enqueuing events directly to laf-os --- src/app/ui/timeline/timeline.cpp | 11 +++-------- src/ui/manager.cpp | 7 +++++++ src/ui/manager.h | 4 ++++ src/ui/widget.cpp | 10 ++++++++++ src/ui/widget.h | 4 ++++ 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/app/ui/timeline/timeline.cpp b/src/app/ui/timeline/timeline.cpp index cd404a136..2719bce97 100644 --- a/src/app/ui/timeline/timeline.cpp +++ b/src/app/ui/timeline/timeline.cpp @@ -55,8 +55,6 @@ #include "fmt/format.h" #include "gfx/point.h" #include "gfx/rect.h" -#include "os/event.h" -#include "os/event_queue.h" #include "os/surface.h" #include "os/system.h" #include "text/font.h" @@ -4496,8 +4494,7 @@ void Timeline::onDragLeave(ui::DragEvent& e) m_dropRange.clearRange(); invalidate(); flushRedraw(); - os::Event ev; - os::System::instance()->eventQueue()->queueEvent(ev); + flushMessages(); } void Timeline::onDrag(ui::DragEvent& e) @@ -4526,8 +4523,7 @@ void Timeline::onDrag(ui::DragEvent& e) updateDropRange(e.position()); flushRedraw(); - os::Event ev; - os::System::instance()->eventQueue()->queueEvent(ev); + flushMessages(); } void Timeline::onDrop(ui::DragEvent& e) @@ -4603,8 +4599,7 @@ void Timeline::onDrop(ui::DragEvent& e) m_dropRange.clearRange(); invalidate(); flushRedraw(); - os::Event ev; - os::System::instance()->eventQueue()->queueEvent(ev); + flushMessages(); } int Timeline::tagFramesDuration(const Tag* tag) const diff --git a/src/ui/manager.cpp b/src/ui/manager.cpp index d66c4d7af..0666e6b2d 100644 --- a/src/ui/manager.cpp +++ b/src/ui/manager.cpp @@ -881,6 +881,13 @@ void Manager::dispatchMessages() } } +void Manager::flushMessages() const +{ + // Send a dummy event just to break the waiting loop. + os::Event evt; + m_eventQueue->queueEvent(evt); +} + void Manager::addToGarbage(Widget* widget) { ASSERT(widget); diff --git a/src/ui/manager.h b/src/ui/manager.h index 721efc341..ef4226078 100644 --- a/src/ui/manager.h +++ b/src/ui/manager.h @@ -63,6 +63,10 @@ public: bool generateMessages(); void dispatchMessages(); + // Wakes up the system's events queue to process the currently enqueued UI + // messages. + void flushMessages() const; + // Makes the generateMessages() function to return immediately if // there is no user events in the OS queue. Useful only for tests // or benchmarks where we don't wait the user (or we don't even diff --git a/src/ui/widget.cpp b/src/ui/widget.cpp index a80a25392..b13850334 100644 --- a/src/ui/widget.cpp +++ b/src/ui/widget.cpp @@ -1176,6 +1176,16 @@ void Widget::flushRedraw() } } +void Widget::flushMessages() const +{ + Manager* manager = this->manager(); + ASSERT(manager); + if (!manager) + return; + + manager->flushMessages(); +} + void Widget::paint(Graphics* graphics, const gfx::Region& drawRegion, const bool isBg) { if (drawRegion.isEmpty()) diff --git a/src/ui/widget.h b/src/ui/widget.h index c909f3d2b..44799dfb1 100644 --- a/src/ui/widget.h +++ b/src/ui/widget.h @@ -313,6 +313,10 @@ public: // Generates paint messages for the current update region. void flushRedraw(); + // Wakes up the system's events queue to process the currently enqueued UI + // messages. + void flushMessages() const; + GraphicsPtr getGraphics(const gfx::Rect& clip); // ===============================================================