refactor: Make IEventQueueBuffer Types an enum class, use proper names rename kNone => Unknown to reflect its unknowns an unknown type of event

This commit is contained in:
sithlord48
2025-07-08 07:50:42 -04:00
committed by Chris Rizzitello
parent fc58688bb0
commit c12aa4c6e9
7 changed files with 26 additions and 24 deletions

View File

@ -126,7 +126,8 @@ bool EventQueue::processEvent(Event &event, double timeout, Stopwatch &timer)
uint32_t dataID;
IEventQueueBuffer::Type type = m_buffer->getEvent(event, dataID);
switch (type) {
case IEventQueueBuffer::kNone:
using enum IEventQueueBuffer::Type;
case Unknown:
if (timeout < 0.0 || timeout <= timer.getTime()) {
// don't want to fail if client isn't expecting that
// so if getEvent() fails with an infinite timeout
@ -135,10 +136,10 @@ bool EventQueue::processEvent(Event &event, double timeout, Stopwatch &timer)
}
return false;
case IEventQueueBuffer::kSystem:
case System:
return true;
case IEventQueueBuffer::kUser: {
case User: {
std::scoped_lock lock{m_mutex};
event = removeEvent(dataID);
return true;

View File

@ -20,11 +20,11 @@ An event queue buffer provides a queue of events for an IEventQueue.
class IEventQueueBuffer : public IInterface
{
public:
enum Type
enum class Type : uint8_t
{
kNone, //!< No event is available
kSystem, //!< Event is a system event
kUser //!< Event is a user event
Unknown, //!< No event is available
System, //!< Event is a system event
User //!< Event is a user event
};
//! @name manipulators
@ -45,11 +45,11 @@ public:
//! Get the next event
/*!
Get the next event from the buffer. Return kNone if no event is
available. If a system event is next, return kSystem and fill in
Get the next event from the buffer. Return None if no event is
available. If a system event is next, return System and fill in
event. The event data in a system event can point to a static
buffer (because Event::deleteData() will not attempt to delete
data in a kSystem event). Otherwise, return kUser and fill in
data in a System event). Otherwise, return User and fill in
\p dataID with the value passed to \c addEvent().
*/
virtual Type getEvent(Event &event, uint32_t &dataID) = 0;

View File

@ -49,12 +49,12 @@ IEventQueueBuffer::Type SimpleEventQueueBuffer::getEvent(Event &, uint32_t &data
{
ArchMutexLock lock(m_queueMutex);
if (!m_queueReady) {
return kNone;
return IEventQueueBuffer::Type::Unknown;
}
dataID = m_queue.back();
m_queue.pop_back();
m_queueReady = !m_queue.empty();
return kUser;
return IEventQueueBuffer::Type::User;
}
bool SimpleEventQueueBuffer::addEvent(uint32_t dataID)

View File

@ -115,12 +115,12 @@ IEventQueueBuffer::Type EiEventQueueBuffer::getEvent(Event &event, uint32_t &dat
// if this an injected special event, just return the data and exit
if (pair.first == false) {
dataID = pair.second;
return kUser;
return IEventQueueBuffer::Type::User;
}
event = Event(EventTypes::System, m_events->getSystemTarget());
return kSystem;
return IEventQueueBuffer::Type::System;
}
bool EiEventQueueBuffer::addEvent(uint32_t dataID)

View File

@ -66,6 +66,7 @@ void MSWindowsEventQueueBuffer::waitForEvent(double timeout)
IEventQueueBuffer::Type MSWindowsEventQueueBuffer::getEvent(Event &event, uint32_t &dataID)
{
using enum IEventQueueBuffer::Type;
// NOTE: QS_ALLINPUT was replaced with QS_ALLPOSTMESSAGE.
//
// peek at messages first. waiting for QS_ALLINPUT will return
@ -73,25 +74,25 @@ IEventQueueBuffer::Type MSWindowsEventQueueBuffer::getEvent(Event &event, uint32
// dispatch that message behind our backs and block. PeekMessage
// will also dispatch behind our backs but won't block.
if (!PeekMessage(&m_event, nullptr, 0, 0, PM_NOREMOVE) && !PeekMessage(&m_event, (HWND)-1, 0, 0, PM_NOREMOVE)) {
return kNone;
return Unknown;
}
// BOOL. yeah, right.
BOOL result = GetMessage(&m_event, nullptr, 0, 0);
if (result == -1) {
return kNone;
return Unknown;
} else if (result == 0) {
event = Event(EventTypes::Quit);
return kSystem;
return System;
} else if (m_daemonQuit != 0 && m_event.message == m_daemonQuit) {
event = Event(EventTypes::Quit);
return kSystem;
return System;
} else if (m_event.message == m_userEvent) {
dataID = static_cast<uint32_t>(m_event.wParam);
return kUser;
return User;
} else {
event = Event(EventTypes::System, m_events->getSystemTarget(), &m_event);
return kSystem;
return System;
}
}

View File

@ -51,7 +51,7 @@ IEventQueueBuffer::Type OSXEventQueueBuffer::getEvent(Event &event, uint32_t &da
std::unique_lock lock(m_mutex);
if (m_dataQueue.empty()) {
LOG_DEBUG2("no events in queue");
return kNone;
return IEventQueueBuffer::Type::Unknown;
}
dataID = m_dataQueue.front();
@ -59,7 +59,7 @@ IEventQueueBuffer::Type OSXEventQueueBuffer::getEvent(Event &event, uint32_t &da
lock.unlock(); // Unlock early to allow other threads to proceed
LOG_DEBUG2("handled user event with dataID: %u", dataID);
return kUser;
return IEventQueueBuffer::Type::User;
}
bool OSXEventQueueBuffer::addEvent(uint32_t dataID)

View File

@ -142,10 +142,10 @@ IEventQueueBuffer::Type XWindowsEventQueueBuffer::getEvent(Event &event, uint32_
// process event
if (m_event.xany.type == ClientMessage && m_event.xclient.message_type == m_userEvent) {
dataID = static_cast<uint32_t>(m_event.xclient.data.l[0]);
return kUser;
return IEventQueueBuffer::Type::User;
} else {
event = Event(EventTypes::System, m_events->getSystemTarget(), &m_event);
return kSystem;
return IEventQueueBuffer::Type::System;
}
}