Skip to content

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

refactor: moved method for populating initial state to Startup class

Lars6bc9d8a1bab8
diff --git a/LarsWM.Core/AppState.cs b/LarsWM.Core/AppState.cs
index 7fc17114..aa5f435b 100644
--- a/LarsWM.Core/AppState.cs
+++ b/LarsWM.Core/AppState.cs
@@ -1,16 +1,8 @@
-using LarsWM.Core.Common.Services;
-using LarsWM.Core.Monitors;
-using LarsWM.Core.Monitors.Commands;
+using LarsWM.Core.Monitors;
using LarsWM.Core.UserConfigs;
-using LarsWM.Core.UserConfigs.Commands;
using LarsWM.Core.Windows;
using LarsWM.Core.Workspaces;
-using static LarsWM.Core.WindowsApi.WindowsApiFacade;
-using System;
using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Windows.Forms;
namespace LarsWM.Core
{
@@ -21,37 +13,5 @@ namespace LarsWM.Core
public List<Workspace> Workspaces { get; set; } = new List<Workspace>();
public List<Window> Windows { get; set; } = new List<Window>();
public UserConfig UserConfig { get; set; } = null;
-
- private IBus _bus;
- private MonitorService _monitorService;
-
- public AppState(IBus bus, MonitorService monitorService)
- {
- _bus = bus;
- _monitorService = monitorService;
- }
-
- public void InitialiseState()
- {
- // Read user config file and set its values in state.
- // TODO: Rename to ReadUserConfigCommand
- _bus.Invoke(new GetUserConfigCommand());
-
- // Create a Monitor and consequently a Workspace for each detected Screen.
- foreach (var screen in Screen.AllScreens)
- {
- _bus.Invoke(new AddMonitorCommand(screen));
- }
-
- // TODO: move the below code to its own command
- var windows = GetOpenWindows();
-
- foreach (var window in windows)
- {
- // Add window to its nearest workspace
- var targetMonitor = _monitorService.GetMonitorFromWindowHandle(window);
- targetMonitor.DisplayedWorkspace.WindowsInWorkspace.Add(window);
- }
- }
}
}
diff --git a/LarsWM.Core/Startup.cs b/LarsWM.Core/Startup.cs
index 2b147783..24e9306e 100644
--- a/LarsWM.Core/Startup.cs
+++ b/LarsWM.Core/Startup.cs
@@ -20,18 +20,21 @@ namespace LarsWM.Core
{
private IBus _bus;
private AppState _appState;
+ private MonitorService _monitorService;
+
private List<Monitor> _monitors = new List<Monitor>();
- public Startup(IBus bus, AppState appState)
+ public Startup(IBus bus, AppState appState, MonitorService monitorService)
{
_bus = bus;
_appState = appState;
+ _monitorService = monitorService;
}
public void Init()
{
// Populate initial monitors, windows, workspaces and user config in AppState.
- _appState.InitialiseState();
+ PopulateState();
// Subscribe to windows hooks
@@ -67,6 +70,32 @@ namespace LarsWM.Core
Debug.WriteLine(_monitors);
}
+ /// <summary>
+ /// Populate AppState with initial monitors, windows, workspaces and user config.
+ /// </summary>
+ private void PopulateState()
+ {
+ // Read user config file and set its values in state.
+ // TODO: Rename to ReadUserConfigCommand
+ _bus.Invoke(new GetUserConfigCommand());
+
+ // Create a Monitor and consequently a Workspace for each detected Screen.
+ foreach (var screen in Screen.AllScreens)
+ {
+ _bus.Invoke(new AddMonitorCommand(screen));
+ }
+
+ // TODO: move the below code to its own command
+ var windows = GetOpenWindows();
+
+ foreach (var window in windows)
+ {
+ // Add window to its nearest workspace
+ var targetMonitor = _monitorService.GetMonitorFromWindowHandle(window);
+ targetMonitor.DisplayedWorkspace.WindowsInWorkspace.Add(window);
+ }
+ }
+
private static void DumpManagedWindows(Window window)
{
StringBuilder sb = new StringBuilder(GetWindowTextLength(window.Hwnd) + 1);