Avoid enqueuing events directly to laf-os

This commit is contained in:
Martín Capello 2025-04-11 15:16:09 -03:00 committed by David Capello
parent a3236bc1e9
commit 45fbeda95b
5 changed files with 28 additions and 8 deletions

View File

@ -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

View File

@ -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);

View File

@ -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

View File

@ -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())

View File

@ -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);
// ===============================================================