GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
refactor(all): remove `IBus`; replace uses with `Bus` class
Lars0d27ae42dff4
diff --git a/LarsWM.Bar/CommandHandlers/LaunchBarOnMonitorHandler.cs b/LarsWM.Bar/CommandHandlers/LaunchBarOnMonitorHandler.csindex 4a42a731..1d2ad7f5 100644--- a/LarsWM.Bar/CommandHandlers/LaunchBarOnMonitorHandler.cs+++ b/LarsWM.Bar/CommandHandlers/LaunchBarOnMonitorHandler.cs@@ -9,9 +9,9 @@ namespace LarsWM.Bar.CommandHandlersclass LaunchBarOnMonitorHandler : ICommandHandler<LaunchBarOnMonitorCommand>{private MonitorService _monitorService { get; }- public IBus _bus { get; }+ public Bus _bus { get; }- public LaunchBarOnMonitorHandler(MonitorService monitorService, IBus bus)+ public LaunchBarOnMonitorHandler(MonitorService monitorService, Bus bus){_monitorService = monitorService;_bus = bus;diff --git a/LarsWM.Bar/DependencyInjection.cs b/LarsWM.Bar/DependencyInjection.csindex 6e9b7216..3316f26e 100644--- a/LarsWM.Bar/DependencyInjection.cs+++ b/LarsWM.Bar/DependencyInjection.cs@@ -18,7 +18,7 @@ namespace LarsWM.Barpublic static IServiceProvider RegisterBarHandlers(this IServiceProvider serviceProvider){- var bus = serviceProvider.GetRequiredService<IBus>();+ var bus = serviceProvider.GetRequiredService<Bus>();bus.RegisterCommandHandler<LaunchBarOnMonitorHandler>();bus.RegisterEventHandler<MonitorAddedHandler>();diff --git a/LarsWM.Bar/EventHandlers/MonitorAddedHandler.cs b/LarsWM.Bar/EventHandlers/MonitorAddedHandler.csindex f6167e0a..08bcf403 100644--- a/LarsWM.Bar/EventHandlers/MonitorAddedHandler.cs+++ b/LarsWM.Bar/EventHandlers/MonitorAddedHandler.cs@@ -6,9 +6,9 @@ namespace LarsWM.Bar.EventHandlers{class MonitorAddedHandler : IEventHandler<MonitorAddedEvent>{- private IBus _bus;+ private Bus _bus;- public MonitorAddedHandler(IBus bus)+ public MonitorAddedHandler(Bus bus){_bus = bus;}diff --git a/LarsWM.Bar/MainWindow.xaml.cs b/LarsWM.Bar/MainWindow.xaml.csindex 4c04bfb9..0c1b3b87 100644--- a/LarsWM.Bar/MainWindow.xaml.cs+++ b/LarsWM.Bar/MainWindow.xaml.cs@@ -12,9 +12,9 @@ namespace LarsWM.Bar/// </summary>public partial class MainWindow : Window{- private IBus _bus { get; }+ private Bus _bus { get; }- public MainWindow(Monitor monitor, IBus bus)+ public MainWindow(Monitor monitor, Bus bus){_bus = bus;diff --git a/LarsWM.Bootstrapper/Startup.cs b/LarsWM.Bootstrapper/Startup.csindex 1956d0da..6cfe4418 100644--- a/LarsWM.Bootstrapper/Startup.cs+++ b/LarsWM.Bootstrapper/Startup.cs@@ -15,7 +15,7 @@ namespace LarsWM.Bootstrapper{class Startup{- private IBus _bus;+ private Bus _bus;private MonitorService _monitorService;private KeybindingService _keybindingService;private WindowEventService _windowEventService;@@ -23,7 +23,7 @@ namespace LarsWM.Bootstrapperprivate WindowService _windowService;public Startup(- IBus bus,+ Bus bus,MonitorService monitorService,KeybindingService keybindingService,WindowEventService windowEventService,diff --git a/LarsWM.Domain/Common/Services/KeybindingService.cs b/LarsWM.Domain/Common/Services/KeybindingService.csindex 5c503944..c904556b 100644--- a/LarsWM.Domain/Common/Services/KeybindingService.cs+++ b/LarsWM.Domain/Common/Services/KeybindingService.cs@@ -21,9 +21,9 @@ namespace LarsWM.Domain.Common.Servicespublic static readonly uint WM_KEYDOWN = 0x100;public static readonly uint WM_SYSKEYDOWN = 0x104;- private IBus _bus;+ private Bus _bus;- public KeybindingService(IBus bus)+ public KeybindingService(Bus bus){_bus = bus;}diff --git a/LarsWM.Domain/Containers/CommandHandlers/AttachContainerHandler.cs b/LarsWM.Domain/Containers/CommandHandlers/AttachContainerHandler.csindex 396480c0..a8cf455f 100644--- a/LarsWM.Domain/Containers/CommandHandlers/AttachContainerHandler.cs+++ b/LarsWM.Domain/Containers/CommandHandlers/AttachContainerHandler.cs@@ -8,11 +8,11 @@ namespace LarsWM.Domain.Containers.CommandHandlers{class AttachContainerHandler : ICommandHandler<AttachContainerCommand>{- private IBus _bus;+ private Bus _bus;private ContainerService _containerService;private readonly UserConfigService _userConfigService;- public AttachContainerHandler(IBus bus, ContainerService containerService, UserConfigService userConfigService)+ public AttachContainerHandler(Bus bus, ContainerService containerService, UserConfigService userConfigService){_bus = bus;_containerService = containerService;diff --git a/LarsWM.Domain/Containers/CommandHandlers/ChangeContainerLayoutHandler.cs b/LarsWM.Domain/Containers/CommandHandlers/ChangeContainerLayoutHandler.csindex bff471a1..f3bc023f 100644--- a/LarsWM.Domain/Containers/CommandHandlers/ChangeContainerLayoutHandler.cs+++ b/LarsWM.Domain/Containers/CommandHandlers/ChangeContainerLayoutHandler.cs@@ -11,11 +11,11 @@ namespace LarsWM.Domain.Containers.CommandHandlers{class ChangeContainerLayoutHandler : ICommandHandler<ChangeContainerLayoutCommand>{- private IBus _bus;+ private Bus _bus;private ContainerService _containerService;private WindowService _windowService;- public ChangeContainerLayoutHandler(IBus bus, ContainerService containerService, WindowService windowService)+ public ChangeContainerLayoutHandler(Bus bus, ContainerService containerService, WindowService windowService){_bus = bus;_containerService = containerService;diff --git a/LarsWM.Domain/Containers/CommandHandlers/DetachContainerHandler.cs b/LarsWM.Domain/Containers/CommandHandlers/DetachContainerHandler.csindex 0683cf7f..f8ce7d38 100644--- a/LarsWM.Domain/Containers/CommandHandlers/DetachContainerHandler.cs+++ b/LarsWM.Domain/Containers/CommandHandlers/DetachContainerHandler.cs@@ -9,11 +9,11 @@ namespace LarsWM.Domain.Containers.CommandHandlers{class DetachContainerHandler : ICommandHandler<DetachContainerCommand>{- private IBus _bus;+ private Bus _bus;private ContainerService _containerService;private readonly UserConfigService _userConfigService;- public DetachContainerHandler(IBus bus, ContainerService containerService, UserConfigService userConfigService)+ public DetachContainerHandler(Bus bus, ContainerService containerService, UserConfigService userConfigService){_bus = bus;_containerService = containerService;diff --git a/LarsWM.Domain/DependencyInjection.cs b/LarsWM.Domain/DependencyInjection.csindex 6d04f5ec..4e1ab564 100644--- a/LarsWM.Domain/DependencyInjection.cs+++ b/LarsWM.Domain/DependencyInjection.cs@@ -48,7 +48,7 @@ namespace LarsWM.Domainpublic static IServiceProvider RegisterDomainHandlers(this IServiceProvider serviceProvider){- var bus = serviceProvider.GetRequiredService<IBus>();+ var bus = serviceProvider.GetRequiredService<Bus>();bus.RegisterCommandHandler<AttachContainerHandler>();bus.RegisterCommandHandler<ChangeContainerLayoutHandler>();bus.RegisterCommandHandler<DetachContainerHandler>();diff --git a/LarsWM.Domain/Monitors/CommandHandlers/AddMonitorHandler.cs b/LarsWM.Domain/Monitors/CommandHandlers/AddMonitorHandler.csindex b2c46a90..89101921 100644--- a/LarsWM.Domain/Monitors/CommandHandlers/AddMonitorHandler.cs+++ b/LarsWM.Domain/Monitors/CommandHandlers/AddMonitorHandler.cs@@ -7,10 +7,10 @@ namespace LarsWM.Domain.Monitors.CommandHandlers{class AddMonitorHandler : ICommandHandler<AddMonitorCommand>{- private IBus _bus;+ private Bus _bus;private ContainerService _containerService;- public AddMonitorHandler(IBus bus, ContainerService containerService)+ public AddMonitorHandler(Bus bus, ContainerService containerService){_bus = bus;_containerService = containerService;diff --git a/LarsWM.Domain/Monitors/EventHandlers/MonitorAddedHandler.cs b/LarsWM.Domain/Monitors/EventHandlers/MonitorAddedHandler.csindex 39b05f6a..d2ce1e9c 100644--- a/LarsWM.Domain/Monitors/EventHandlers/MonitorAddedHandler.cs+++ b/LarsWM.Domain/Monitors/EventHandlers/MonitorAddedHandler.cs@@ -10,10 +10,10 @@ namespace LarsWM.Domain.Monitors.EventHandler{class MonitorAddedHandler : IEventHandler<MonitorAddedEvent>{- private IBus _bus;+ private Bus _bus;private WorkspaceService _workspaceService;- public MonitorAddedHandler(IBus bus, WorkspaceService workspaceService)+ public MonitorAddedHandler(Bus bus, WorkspaceService workspaceService){_bus = bus;_workspaceService = workspaceService;diff --git a/LarsWM.Domain/UserConfigs/CommandHandlers/EvaluateUserConfigHandler.cs b/LarsWM.Domain/UserConfigs/CommandHandlers/EvaluateUserConfigHandler.csindex 6558fce3..f04f6a44 100644--- a/LarsWM.Domain/UserConfigs/CommandHandlers/EvaluateUserConfigHandler.cs+++ b/LarsWM.Domain/UserConfigs/CommandHandlers/EvaluateUserConfigHandler.cs@@ -11,9 +11,9 @@ namespace LarsWM.Domain.UserConfigs.CommandHandlersclass EvaluateUserConfigHandler : ICommandHandler<EvaluateUserConfigCommand>{private UserConfigService _userConfigService;- private IBus _bus;+ private Bus _bus;- public EvaluateUserConfigHandler(UserConfigService userConfigService, IBus bus)+ public EvaluateUserConfigHandler(UserConfigService userConfigService, Bus bus){_userConfigService = userConfigService;_bus = bus;diff --git a/LarsWM.Domain/Windows/CommandHandlers/AddInitialWindowsHandler.cs b/LarsWM.Domain/Windows/CommandHandlers/AddInitialWindowsHandler.csindex 2c14248e..0001778f 100644--- a/LarsWM.Domain/Windows/CommandHandlers/AddInitialWindowsHandler.cs+++ b/LarsWM.Domain/Windows/CommandHandlers/AddInitialWindowsHandler.cs@@ -11,13 +11,13 @@ namespace LarsWM.Domain.Windows.CommandHandlers{class AddInitialWindowsHandler : ICommandHandler<AddInitialWindowsCommand>{- private IBus _bus;+ private Bus _bus;private UserConfigService _userConfigService;private MonitorService _monitorService;private WindowService _windowService;public AddInitialWindowsHandler(- IBus bus,+ Bus bus,UserConfigService userConfigService,MonitorService monitorService,WindowService windowService)diff --git a/LarsWM.Domain/Windows/CommandHandlers/AddWindowHandler.cs b/LarsWM.Domain/Windows/CommandHandlers/AddWindowHandler.csindex f7811eb3..2ffb3021 100644--- a/LarsWM.Domain/Windows/CommandHandlers/AddWindowHandler.cs+++ b/LarsWM.Domain/Windows/CommandHandlers/AddWindowHandler.cs@@ -8,11 +8,11 @@ namespace LarsWM.Domain.Windows.CommandHandlers{class AddWindowHandler : ICommandHandler<AddWindowCommand>{- private IBus _bus;+ private Bus _bus;private WindowService _windowService;private MonitorService _monitorService;- public AddWindowHandler(IBus bus, WindowService windowService, MonitorService monitorService)+ public AddWindowHandler(Bus bus, WindowService windowService, MonitorService monitorService){_bus = bus;_windowService = windowService;diff --git a/LarsWM.Domain/Windows/CommandHandlers/ResizeFocusedWindowHandler.cs b/LarsWM.Domain/Windows/CommandHandlers/ResizeFocusedWindowHandler.csindex aabd369c..953ec043 100644--- a/LarsWM.Domain/Windows/CommandHandlers/ResizeFocusedWindowHandler.cs+++ b/LarsWM.Domain/Windows/CommandHandlers/ResizeFocusedWindowHandler.cs@@ -11,12 +11,12 @@ namespace LarsWM.Domain.Windows.CommandHandlers{class ResizeFocusedWindowHandler : ICommandHandler<ResizeFocusedWindowCommand>{- private IBus _bus;+ private Bus _bus;private WindowService _windowService;private UserConfigService _userConfigService;private ContainerService _containerService;- public ResizeFocusedWindowHandler(IBus bus, WindowService windowService, UserConfigService userConfigService, ContainerService containerService)+ public ResizeFocusedWindowHandler(Bus bus, WindowService windowService, UserConfigService userConfigService, ContainerService containerService){_bus = bus;_windowService = windowService;diff --git a/LarsWM.Domain/Windows/WindowHooksHandler.cs b/LarsWM.Domain/Windows/WindowHooksHandler.csindex 21042f24..b13dbc98 100644--- a/LarsWM.Domain/Windows/WindowHooksHandler.cs+++ b/LarsWM.Domain/Windows/WindowHooksHandler.cs@@ -13,14 +13,14 @@ namespace LarsWM.Domain.Windows// TODO: Move Configure method to WindowService.public class WindowHooksHandler{- private IBus _bus;+ private Bus _bus;private WindowService _windowService;private ContainerService _containerService;private WindowEventService _windowEventService { get; }public WindowHooksHandler(- IBus bus,+ Bus bus,WindowService windowService,WindowEventService windowEventService,ContainerService containerService)diff --git a/LarsWM.Domain/Workspaces/CommandHandlers/DisplayWorkspaceHandler.cs b/LarsWM.Domain/Workspaces/CommandHandlers/DisplayWorkspaceHandler.csindex 1f815f75..391eaad6 100644--- a/LarsWM.Domain/Workspaces/CommandHandlers/DisplayWorkspaceHandler.cs+++ b/LarsWM.Domain/Workspaces/CommandHandlers/DisplayWorkspaceHandler.cs@@ -10,11 +10,11 @@ namespace LarsWM.Domain.Workspaces.CommandHandlers{class DisplayWorkspaceHandler : ICommandHandler<DisplayWorkspaceCommand>{- private IBus _bus;+ private Bus _bus;private MonitorService _monitorService;private ContainerService _containerService;- public DisplayWorkspaceHandler(IBus bus, MonitorService monitorService, ContainerService containerService)+ public DisplayWorkspaceHandler(Bus bus, MonitorService monitorService, ContainerService containerService){_bus = bus;_monitorService = monitorService;diff --git a/LarsWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs b/LarsWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.csindex 799e1731..98d2224d 100644--- a/LarsWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs+++ b/LarsWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs@@ -1,4 +1,4 @@-using LarsWM.Infrastructure.Bussing;+using LarsWM.Infrastructure.Bussing;using LarsWM.Domain.Monitors;using LarsWM.Domain.Workspaces.Commands;using LarsWM.Domain.Windows.Commands;@@ -10,11 +10,11 @@ namespace LarsWM.Domain.Workspaces.CommandHandlers{class FocusWorkspaceHandler : ICommandHandler<FocusWorkspaceCommand>{- private IBus _bus;+ private Bus _bus;private WorkspaceService _workspaceService;private MonitorService _monitorService;- public FocusWorkspaceHandler(IBus bus, WorkspaceService workspaceService, MonitorService monitorService)+ public FocusWorkspaceHandler(Bus bus, WorkspaceService workspaceService, MonitorService monitorService){_bus = bus;_workspaceService = workspaceService;diff --git a/LarsWM.Infrastructure/Bussing/Bus.cs b/LarsWM.Infrastructure/Bussing/Bus.csindex 09dbf0a3..623b444e 100644--- a/LarsWM.Infrastructure/Bussing/Bus.cs+++ b/LarsWM.Infrastructure/Bussing/Bus.cs@@ -1,79 +1,79 @@-using Microsoft.Extensions.DependencyInjection;-using System;-using System.Collections.Generic;-using System.Diagnostics;-using System.Linq;--namespace LarsWM.Infrastructure.Bussing-{- /// <summary>- /// Bus facilitates communication to command and event handlers.- /// </summary>- public sealed class Bus : IBus- {- private List<Type> _registeredCommandHandlers = new List<Type>();- private List<Type> _registeredEventHandlers = new List<Type>();- private static readonly Object lockObj = new Object();-- /// <summary>- /// Sends command to appropriate command handler.- /// </summary>- public dynamic Invoke<T>(T command) where T : Command- {- // Create a Type object representing the generic ICommandHandler type.- var commandHandlerGeneric = typeof(ICommandHandler<>);-- // Create a Type object representing the constructed ICommandHandler generic.- var handlerTypeToCall = commandHandlerGeneric.MakeGenericType(command.GetType());-- var handlers = _registeredCommandHandlers.Where(handler => handlerTypeToCall.IsAssignableFrom(handler)).ToList();-- if (handlers.Count() != 1)- {- throw new Exception("Only one CommandHandler can be registered to handle a Command.");- }-- // TODO: Add centralised error handling here?- Debug.WriteLine($"Command {command.Name} invoked.");-- ICommandHandler<T> handlerInstance = ServiceLocator.Provider.GetRequiredService(handlers[0]) as ICommandHandler<T>;- lock (lockObj)- {- return handlerInstance.Handle(command);- }- }-- /// <summary>- /// Sends event to appropriate event handlers.- /// </summary>- public void RaiseEvent<T>(T @event) where T : Event- {- // 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));-- Debug.WriteLine($"Event {@event.Name} emitted.");-- // TODO: Add centralised error handling here?- foreach (var handler in handlersToCall)- {- IEventHandler<T> handlerInstance = ServiceLocator.Provider.GetService(handler) as IEventHandler<T>;- handlerInstance.Handle(@event);- }- }-- public void RegisterCommandHandler<T>()- {- _registeredCommandHandlers.Add(typeof(T));- }-- public void RegisterEventHandler<T>()- {- _registeredEventHandlers.Add(typeof(T));- }- }-}+using Microsoft.Extensions.DependencyInjection;+using System;+using System.Collections.Generic;+using System.Diagnostics;+using System.Linq;++namespace LarsWM.Infrastructure.Bussing+{+ /// <summary>+ /// Bus facilitates communication to command and event handlers.+ /// </summary>+ public sealed class Bus+ {+ private List<Type> _registeredCommandHandlers = new List<Type>();+ private List<Type> _registeredEventHandlers = new List<Type>();+ private static readonly Object lockObj = new Object();++ /// <summary>+ /// Sends command to appropriate command handler.+ /// </summary>+ public dynamic Invoke<T>(T command) where T : Command+ {+ // Create a Type object representing the generic ICommandHandler type.+ var commandHandlerGeneric = typeof(ICommandHandler<>);++ // Create a Type object representing the constructed ICommandHandler generic.+ var handlerTypeToCall = commandHandlerGeneric.MakeGenericType(command.GetType());++ var handlers = _registeredCommandHandlers.Where(handler => handlerTypeToCall.IsAssignableFrom(handler)).ToList();++ if (handlers.Count() != 1)+ {+ throw new Exception("Only one CommandHandler can be registered to handle a Command.");+ }++ // TODO: Add centralised error handling here?+ Debug.WriteLine($"Command {command.Name} invoked.");++ ICommandHandler<T> handlerInstance = ServiceLocator.Provider.GetRequiredService(handlers[0]) as ICommandHandler<T>;+ lock (lockObj)+ {+ return handlerInstance.Handle(command);+ }+ }++ /// <summary>+ /// Sends event to appropriate event handlers.+ /// </summary>+ public void RaiseEvent<T>(T @event) where T : Event+ {+ // 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));++ Debug.WriteLine($"Event {@event.Name} emitted.");++ // TODO: Add centralised error handling here?+ foreach (var handler in handlersToCall)+ {+ IEventHandler<T> handlerInstance = ServiceLocator.Provider.GetService(handler) as IEventHandler<T>;+ handlerInstance.Handle(@event);+ }+ }++ public void RegisterCommandHandler<T>()+ {+ _registeredCommandHandlers.Add(typeof(T));+ }++ public void RegisterEventHandler<T>()+ {+ _registeredEventHandlers.Add(typeof(T));+ }+ }+}diff --git a/LarsWM.Infrastructure/Bussing/IBus.cs b/LarsWM.Infrastructure/Bussing/IBus.csdeleted file mode 100644index 627e92fe..00000000--- a/LarsWM.Infrastructure/Bussing/IBus.cs+++ /dev/null@@ -1,10 +0,0 @@-namespace LarsWM.Infrastructure.Bussing-{- public interface IBus- {- dynamic Invoke<T>(T command) where T : Command;- void RaiseEvent<T>(T @event) where T : Event;- void RegisterCommandHandler<T>();- void RegisterEventHandler<T>();- }-}diff --git a/LarsWM.Infrastructure/DependencyInjection.cs b/LarsWM.Infrastructure/DependencyInjection.csindex ee9bd3df..32818c2a 100644--- a/LarsWM.Infrastructure/DependencyInjection.cs+++ b/LarsWM.Infrastructure/DependencyInjection.cs@@ -8,7 +8,7 @@ namespace LarsWM.Infrastructure{public static IServiceCollection AddInfrastructureServices(this IServiceCollection services){- services.AddSingleton<IBus, Bus>();+ services.AddSingleton<Bus, Bus>();services.AddSingleton<WindowEventService>();// TODO: Change WindowsApiFacade & WindowsApiService to be compatible with DI.