Skip to content

GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.

feat: successfully invoke appropriate event handler through Bus

Larsf822a350d268
diff --git a/LarsWM.Core/Common/Services/Bus.cs b/LarsWM.Core/Common/Services/Bus.cs
index f02f4c17..d63cfbc0 100644
--- a/LarsWM.Core/Common/Services/Bus.cs
+++ b/LarsWM.Core/Common/Services/Bus.cs
@@ -41,7 +41,19 @@ namespace LarsWM.Core.Common.Services
/// </summary>
public void RaiseEvent<T>(T @event) where T : Event
{
- throw new NotImplementedException();
+ // Create a Type object representing the generic IEventHandler type.
+ var eventHandlerGeneric = typeof(IEventHandler<>);
+
+ // Create a Type object representing the constructed IEventHandler generic.
+ var handlerTypeToCall = eventHandlerGeneric.MakeGenericType(@event.GetType());
+
+ var handlersToCall = _registeredEventHandlers.Where(handler => handlerTypeToCall.IsAssignableFrom(handler));
+
+ foreach (var handler in handlersToCall)
+ {
+ IEventHandler<T> handlerInstance = Program.ServiceProvider.GetService(handler) as IEventHandler<T>;
+ handlerInstance.Handle(@event);
+ }
}
public void RegisterCommandHandler<T>()