diff options
author | Sadie Powell <sadie@witchery.services> | 2020-01-17 10:50:26 +0000 |
---|---|---|
committer | Sadie Powell <sadie@witchery.services> | 2020-01-17 11:27:31 +0000 |
commit | 5ae65245221dfad24510ee9a1fbead8db740251f (patch) | |
tree | 9469450b4d176ad16bc941acd524635daf83bdce | |
parent | 72286cca740b374661a03d8544ca28d9237875ad (diff) |
Fix the ordering of custom event handlers.
Closes #1742.
-rw-r--r-- | include/event.h | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/include/event.h b/include/event.h index 503c6ce54..39273413f 100644 --- a/include/event.h +++ b/include/event.h @@ -37,10 +37,15 @@ class Events::ModuleEventProvider : public ServiceProvider, private dynamic_refe public: struct Comp { - bool operator()(ModuleEventListener* one, ModuleEventListener* two) const; + bool operator()(ModuleEventListener* lhs, ModuleEventListener* rhs) const; }; - typedef insp::flat_multiset<ModuleEventListener*, Comp, std::less<ModuleEventListener*> > SubscriberList; + struct ElementComp + { + bool operator()(ModuleEventListener* lhs, ModuleEventListener* rhs) const; + }; + + typedef insp::flat_multiset<ModuleEventListener*, Comp, ElementComp> SubscriberList; /** Constructor * @param mod Module providing the event(s) @@ -152,12 +157,22 @@ class Events::ModuleEventListener : private dynamic_reference_base::CaptureHook /** Retrieves the module which created this listener. */ const Module* GetModule() const { return prov.creator; } - friend struct ModuleEventProvider::Comp; + /** Retrieves the priority of this event. */ + unsigned int GetPriority() const { return eventpriority; } }; -inline bool Events::ModuleEventProvider::Comp::operator()(Events::ModuleEventListener* one, Events::ModuleEventListener* two) const +inline bool Events::ModuleEventProvider::Comp::operator()(Events::ModuleEventListener* lhs, Events::ModuleEventListener* rhs) const +{ + return (lhs->GetPriority() < rhs->GetPriority()); +} + +inline bool Events::ModuleEventProvider::ElementComp::operator()(Events::ModuleEventListener* lhs, Events::ModuleEventListener* rhs) const { - return (one->eventpriority < two->eventpriority); + if (lhs->GetPriority() < rhs->GetPriority()) + return true; + if (lhs->GetPriority() > rhs->GetPriority()) + return false; + return std::less<ModuleEventListener*>()(lhs, rhs); } /** |