From 39295476d08ad8be8c48a89f944ca2f1f2421d94 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 8 Oct 2023 15:23:40 +1100 Subject: [PATCH] Cleanup: store const events in GHOST's event handling logic --- intern/ghost/GHOST_IEventConsumer.hh | 2 +- intern/ghost/intern/GHOST_CallbackEventConsumer.cc | 2 +- intern/ghost/intern/GHOST_CallbackEventConsumer.hh | 2 +- intern/ghost/intern/GHOST_EventManager.cc | 10 +++++----- intern/ghost/intern/GHOST_EventManager.hh | 10 +++++----- intern/ghost/intern/GHOST_EventPrinter.cc | 2 +- intern/ghost/intern/GHOST_EventPrinter.hh | 2 +- intern/ghost/intern/GHOST_System.cc | 2 +- intern/ghost/intern/GHOST_System.hh | 2 +- intern/ghost/intern/GHOST_SystemWayland.cc | 6 +++--- intern/ghost/test/gears/GHOST_Test.cpp | 2 +- 11 files changed, 21 insertions(+), 21 deletions(-) diff --git a/intern/ghost/GHOST_IEventConsumer.hh b/intern/ghost/GHOST_IEventConsumer.hh index 90d71decbbf..546fd592518 100644 --- a/intern/ghost/GHOST_IEventConsumer.hh +++ b/intern/ghost/GHOST_IEventConsumer.hh @@ -32,7 +32,7 @@ class GHOST_IEventConsumer { * \param event: The event that can be handled or ignored. * \return Indication as to whether the event was handled. */ - virtual bool processEvent(GHOST_IEvent *event) = 0; + virtual bool processEvent(const GHOST_IEvent *event) = 0; #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("GHOST:GHOST_IEventConsumer") diff --git a/intern/ghost/intern/GHOST_CallbackEventConsumer.cc b/intern/ghost/intern/GHOST_CallbackEventConsumer.cc index 7933c128cbe..25cf79823ed 100644 --- a/intern/ghost/intern/GHOST_CallbackEventConsumer.cc +++ b/intern/ghost/intern/GHOST_CallbackEventConsumer.cc @@ -21,7 +21,7 @@ GHOST_CallbackEventConsumer::GHOST_CallbackEventConsumer(GHOST_EventCallbackProc m_userData = userData; } -bool GHOST_CallbackEventConsumer::processEvent(GHOST_IEvent *event) +bool GHOST_CallbackEventConsumer::processEvent(const GHOST_IEvent *event) { return m_eventCallback((GHOST_EventHandle)event, m_userData); } diff --git a/intern/ghost/intern/GHOST_CallbackEventConsumer.hh b/intern/ghost/intern/GHOST_CallbackEventConsumer.hh index 2495aecf67f..4966e56e0d5 100644 --- a/intern/ghost/intern/GHOST_CallbackEventConsumer.hh +++ b/intern/ghost/intern/GHOST_CallbackEventConsumer.hh @@ -36,7 +36,7 @@ class GHOST_CallbackEventConsumer : public GHOST_IEventConsumer { * \param event: The event that can be handled or ignored. * \return Indication as to whether the event was handled. */ - bool processEvent(GHOST_IEvent *event); + bool processEvent(const GHOST_IEvent *event); protected: /** The call-back routine invoked. */ diff --git a/intern/ghost/intern/GHOST_EventManager.cc b/intern/ghost/intern/GHOST_EventManager.cc index a7eac30c419..9e5bcb2a3b2 100644 --- a/intern/ghost/intern/GHOST_EventManager.cc +++ b/intern/ghost/intern/GHOST_EventManager.cc @@ -45,7 +45,7 @@ uint32_t GHOST_EventManager::getNumEvents(GHOST_TEventType type) return numEvents; } -GHOST_TSuccess GHOST_EventManager::pushEvent(GHOST_IEvent *event) +GHOST_TSuccess GHOST_EventManager::pushEvent(const GHOST_IEvent *event) { GHOST_TSuccess success; GHOST_ASSERT(event, "invalid event"); @@ -59,7 +59,7 @@ GHOST_TSuccess GHOST_EventManager::pushEvent(GHOST_IEvent *event) return success; } -void GHOST_EventManager::dispatchEvent(GHOST_IEvent *event) +void GHOST_EventManager::dispatchEvent(const GHOST_IEvent *event) { TConsumerVector::iterator iter; @@ -70,7 +70,7 @@ void GHOST_EventManager::dispatchEvent(GHOST_IEvent *event) void GHOST_EventManager::dispatchEvent() { - GHOST_IEvent *event = m_events.back(); + const GHOST_IEvent *event = m_events.back(); m_events.pop_back(); m_handled_events.push_back(event); @@ -130,7 +130,7 @@ void GHOST_EventManager::removeWindowEvents(const GHOST_IWindow *window) TEventStack::iterator iter; iter = m_events.begin(); while (iter != m_events.end()) { - GHOST_IEvent *event = *iter; + const GHOST_IEvent *event = *iter; if (event->getWindow() == window) { GHOST_PRINT("GHOST_EventManager::removeWindowEvents(): removing event\n"); /* @@ -152,7 +152,7 @@ void GHOST_EventManager::removeTypeEvents(GHOST_TEventType type, const GHOST_IWi TEventStack::iterator iter; iter = m_events.begin(); while (iter != m_events.end()) { - GHOST_IEvent *event = *iter; + const GHOST_IEvent *event = *iter; if ((event->getType() == type) && (!window || (event->getWindow() == window))) { GHOST_PRINT("GHOST_EventManager::removeTypeEvents(): removing event\n"); /* diff --git a/intern/ghost/intern/GHOST_EventManager.hh b/intern/ghost/intern/GHOST_EventManager.hh index 12c6dfa37d0..8f52dca3717 100644 --- a/intern/ghost/intern/GHOST_EventManager.hh +++ b/intern/ghost/intern/GHOST_EventManager.hh @@ -53,12 +53,12 @@ class GHOST_EventManager { * Do not delete the event! * \param event: The event to push on the stack. */ - GHOST_TSuccess pushEvent(GHOST_IEvent *event); + GHOST_TSuccess pushEvent(const GHOST_IEvent *event); /** * Dispatches the given event directly, bypassing the event stack. */ - void dispatchEvent(GHOST_IEvent *event); + void dispatchEvent(const GHOST_IEvent *event); /** * Dispatches the event at the back of the stack. @@ -108,11 +108,11 @@ class GHOST_EventManager { void disposeEvents(); /** A stack with events. */ - typedef std::deque TEventStack; + typedef std::deque TEventStack; /** The event stack. */ - std::deque m_events; - std::deque m_handled_events; + std::deque m_events; + std::deque m_handled_events; /** A vector with event consumers. */ typedef std::vector TConsumerVector; diff --git a/intern/ghost/intern/GHOST_EventPrinter.cc b/intern/ghost/intern/GHOST_EventPrinter.cc index 40fa3343f0c..53413930c71 100644 --- a/intern/ghost/intern/GHOST_EventPrinter.cc +++ b/intern/ghost/intern/GHOST_EventPrinter.cc @@ -31,7 +31,7 @@ static const char *getButtonActionString(const GHOST_TButtonAction action) } #endif /* WITH_INPUT_NDOF */ -bool GHOST_EventPrinter::processEvent(GHOST_IEvent *event) +bool GHOST_EventPrinter::processEvent(const GHOST_IEvent *event) { bool handled = false; diff --git a/intern/ghost/intern/GHOST_EventPrinter.hh b/intern/ghost/intern/GHOST_EventPrinter.hh index b2708748043..ef6fcbad073 100644 --- a/intern/ghost/intern/GHOST_EventPrinter.hh +++ b/intern/ghost/intern/GHOST_EventPrinter.hh @@ -22,7 +22,7 @@ class GHOST_EventPrinter : public GHOST_IEventConsumer { * \param event: The event that can be handled or not. * \return Indication as to whether the event was handled. */ - bool processEvent(GHOST_IEvent *event); + bool processEvent(const GHOST_IEvent *event); protected: /** diff --git a/intern/ghost/intern/GHOST_System.cc b/intern/ghost/intern/GHOST_System.cc index 65d1323938b..a20e5c626bb 100644 --- a/intern/ghost/intern/GHOST_System.cc +++ b/intern/ghost/intern/GHOST_System.cc @@ -267,7 +267,7 @@ GHOST_TSuccess GHOST_System::removeEventConsumer(GHOST_IEventConsumer *consumer) return success; } -GHOST_TSuccess GHOST_System::pushEvent(GHOST_IEvent *event) +GHOST_TSuccess GHOST_System::pushEvent(const GHOST_IEvent *event) { GHOST_TSuccess success; if (m_eventManager) { diff --git a/intern/ghost/intern/GHOST_System.hh b/intern/ghost/intern/GHOST_System.hh index 3bfaa370028..26b5263cf71 100644 --- a/intern/ghost/intern/GHOST_System.hh +++ b/intern/ghost/intern/GHOST_System.hh @@ -285,7 +285,7 @@ class GHOST_System : public GHOST_ISystem { * Do not delete the event! * \param event: The event to push on the stack. */ - GHOST_TSuccess pushEvent(GHOST_IEvent *event); + GHOST_TSuccess pushEvent(const GHOST_IEvent *event); /** * \return The timer manager. diff --git a/intern/ghost/intern/GHOST_SystemWayland.cc b/intern/ghost/intern/GHOST_SystemWayland.cc index 4758a817d74..a9b60f0d7d5 100644 --- a/intern/ghost/intern/GHOST_SystemWayland.cc +++ b/intern/ghost/intern/GHOST_SystemWayland.cc @@ -1005,7 +1005,7 @@ struct GWL_Display { * Events added from the event reading thread. * Added into the main event queue when on #GHOST_SystemWayland::processEvents. */ - std::vector events_pending; + std::vector events_pending; /** Guard against multiple threads accessing `events_pending` at once. */ std::mutex events_pending_mutex; @@ -1081,7 +1081,7 @@ static void gwl_display_destroy(GWL_Display *display) display->ghost_timer_manager = nullptr; } /* Pending events may be left unhandled. */ - for (GHOST_IEvent *event : display->events_pending) { + for (const GHOST_IEvent *event : display->events_pending) { delete event; } @@ -5737,7 +5737,7 @@ bool GHOST_SystemWayland::processEvents(bool waitForEvent) { std::lock_guard lock{display_->events_pending_mutex}; - for (GHOST_IEvent *event : display_->events_pending) { + for (const GHOST_IEvent *event : display_->events_pending) { /* Perform actions that aren't handled in a thread. */ switch (event->getType()) { diff --git a/intern/ghost/test/gears/GHOST_Test.cpp b/intern/ghost/test/gears/GHOST_Test.cpp index f338d6bfa8b..5c2409a12f0 100644 --- a/intern/ghost/test/gears/GHOST_Test.cpp +++ b/intern/ghost/test/gears/GHOST_Test.cpp @@ -443,7 +443,7 @@ Application::~Application() } } -bool Application::processEvent(GHOST_IEvent *event) +bool Application::processEvent(const GHOST_IEvent *event) { GHOST_IWindow *window = event->getWindow(); bool handled = true;