Skip to content

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

feat: command and event handlers are registered with bus on startup

Larsfd01b9b4f1db
diff --git a/LarsWM.Core/Common/Services/Bus.cs b/LarsWM.Core/Common/Services/Bus.cs
index dd379349..b1d95c36 100644
--- a/LarsWM.Core/Common/Services/Bus.cs
+++ b/LarsWM.Core/Common/Services/Bus.cs
@@ -1,4 +1,4 @@
-using LarsWM.Core.Common.Models;
+using LarsWM.Core.Common.Models;
using System;
using System.Collections.Generic;
using System.Text;
@@ -10,8 +10,8 @@ namespace LarsWM.Core.Common.Services
/// </summary>
public sealed class Bus : IBus
{
- private static readonly IDictionary<Type, Type> RegisteredCommandHandlers = new Dictionary<Type, Type>();
- private static readonly IDictionary<Type, Type> RegisteredEventHandlers = new Dictionary<Type, Type>();
+ private static readonly List<Type> RegisteredCommandHandlers = new List<Type>();
+ private static readonly List<Type> RegisteredEventHandlers = new List<Type>();
/// <summary>
/// Sends command to appropriate command handler.
@@ -32,12 +32,12 @@ namespace LarsWM.Core.Common.Services
public void RegisterCommandHandler<T>()
{
- throw new NotImplementedException();
+ RegisteredCommandHandlers.Add(typeof(T));
}
public void RegisterEventHandler<T>()
{
- throw new NotImplementedException();
+ RegisteredEventHandlers.Add(typeof(T));
}
}
}
diff --git a/LarsWM.Core/Program.cs b/LarsWM.Core/Program.cs
index 10e804f3..9507aed7 100644
--- a/LarsWM.Core/Program.cs
+++ b/LarsWM.Core/Program.cs
@@ -1,4 +1,6 @@
using LarsWM.Core.Common.Services;
+using LarsWM.Core.Monitors.CommandHandlers;
+using LarsWM.Core.Monitors.EventHandler;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Diagnostics;
@@ -9,6 +11,8 @@ namespace LarsWM.Core
{
class Program
{
+ public static ServiceCollection ServiceCollection { get; private set; } = new ServiceCollection();
+
/// <summary>
/// The main entry point for the application.
/// </summary>
@@ -17,24 +21,25 @@ namespace LarsWM.Core
{
Debug.WriteLine("Application started");
- var serviceCollection = new ServiceCollection();
- ConfigureServices(serviceCollection);
+ ConfigureServices();
+
+ var serviceProvider = ServiceCollection.BuildServiceProvider();
- var serviceProvider = serviceCollection.BuildServiceProvider();
+ var bus = serviceProvider.GetRequiredService<IBus>();
+
+ bus.RegisterCommandHandler<AddMonitorHandler>();
+ bus.RegisterEventHandler<MonitorAddedHandler>();
var startup = serviceProvider.GetRequiredService<Startup>();
startup.Init();
-
- // TODO: Read config file and initialise UserConfig class with its values
- // TODO: Register windows hooks
- // TODO: Create a workspace and assign a workspace to each connected display
- // TODO: Force initial layout
}
- private static void ConfigureServices(ServiceCollection serviceCollection)
+ private static void ConfigureServices()
{
- serviceCollection.AddSingleton<IBus, Bus>();
- serviceCollection.AddSingleton<Startup>();
+ ServiceCollection.AddSingleton<IBus, Bus>();
+ ServiceCollection.AddSingleton<AddMonitorHandler>();
+ ServiceCollection.AddSingleton<MonitorAddedHandler>();
+ ServiceCollection.AddSingleton<Startup>();
}
}
}