GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat: add command for reloading user config (#114)
lars-berger6a3277dad714
diff --git a/GlazeWM.Bar/BarService.cs b/GlazeWM.Bar/BarService.csindex 424c7adc..13c6cc27 100644--- a/GlazeWM.Bar/BarService.cs+++ b/GlazeWM.Bar/BarService.cs@@ -1,4 +1,6 @@+using GlazeWM.Domain.Monitors;using GlazeWM.Domain.Monitors.Events;+using GlazeWM.Domain.UserConfigs.Events;using GlazeWM.Infrastructure.Bussing;using System.Reactive.Linq;using System;@@ -13,58 +15,34 @@ namespace GlazeWM.Barpublic class BarService{private readonly Bus _bus;+ private readonly MonitorService _monitorService;private Application _application;private readonly Dictionary<string, MainWindow> _activeWindowsByDeviceName = new();- public BarService(Bus bus)+ public BarService(Bus bus, MonitorService monitorService){_bus = bus;+ _monitorService = monitorService;}public void StartApp(){var thread = new Thread(() =>{- _application = new Application();+ _application = new()+ {+ ShutdownMode = ShutdownMode.OnExplicitShutdown+ };// Launch the bar window on the added monitor.- _bus.Events.Where(@event => @event is MonitorAddedEvent)- .Subscribe((@event) =>- {- _application.Dispatcher.Invoke(() =>- {- var addedMonitor = (@event as MonitorAddedEvent).AddedMonitor;- var originalFocusedHandle = GetForegroundWindow();-- var barViewModel = new BarViewModel()- {- Monitor = addedMonitor,- Dispatcher = _application.Dispatcher,- };-- var barWindow = new MainWindow(barViewModel);- barWindow.Show();-- // Store active window.- _activeWindowsByDeviceName[addedMonitor.DeviceName] = barWindow;-- // Reset focus to whichever window was focused before the bar window was launched.- SetForegroundWindow(originalFocusedHandle);- });- });-- _bus.Events.Where(@event => @event is MonitorRemovedEvent)- .Subscribe((@event) =>- {- _application.Dispatcher.Invoke(() =>- {- var deviceName = (@event as MonitorRemovedEvent).RemovedDeviceName;-- // Kill the corresponding bar window.- var barWindow = _activeWindowsByDeviceName.GetValueOrDefault(deviceName);- barWindow.Close();- });- });+ _bus.Events.OfType<MonitorAddedEvent>()+ .Subscribe((@event) => ShowWindow(@event.AddedMonitor));++ _bus.Events.OfType<MonitorRemovedEvent>()+ .Subscribe((@event) => CloseWindow(@event.RemovedDeviceName));++ _bus.Events.OfType<UserConfigReloadedEvent>()+ .Subscribe((_) => RestartApp());_application.Run();})@@ -80,6 +58,48 @@ namespace GlazeWM.Bar_application.Dispatcher.Invoke(() => _application.Shutdown());}+ private void RestartApp()+ {+ foreach (var deviceName in _activeWindowsByDeviceName.Keys.ToList())+ CloseWindow(deviceName);++ foreach (var monitor in _monitorService.GetMonitors())+ ShowWindow(monitor);+ }++ public void ShowWindow(Domain.Monitors.Monitor targetMonitor)+ {+ _application.Dispatcher.Invoke(() =>+ {+ var originalFocusedHandle = GetForegroundWindow();++ var barViewModel = new BarViewModel()+ {+ Monitor = targetMonitor,+ Dispatcher = _application.Dispatcher,+ };++ var barWindow = new MainWindow(barViewModel);+ barWindow.Show();++ // Store active window.+ _activeWindowsByDeviceName[targetMonitor.DeviceName] = barWindow;++ // Reset focus to whichever window was focused before the bar window was launched.+ SetForegroundWindow(originalFocusedHandle);+ });+ }++ private void CloseWindow(string deviceName)+ {+ _application.Dispatcher.Invoke(() =>+ {+ // Kill the corresponding bar window.+ var barWindow = _activeWindowsByDeviceName.GetValueOrDefault(deviceName);+ barWindow.Close();+ });+ }+/// <summary>/// Convert shorthand properties from user config (ie. `Padding`, `Margin`, and `BorderWidth`)/// to be compatible with their equivalent XAML properties (ie. `Padding`, `Margin`, anddiff --git a/GlazeWM.Bootstrapper/Program.cs b/GlazeWM.Bootstrapper/Program.csindex 2424b32f..9d90e2d5 100644--- a/GlazeWM.Bootstrapper/Program.cs+++ b/GlazeWM.Bootstrapper/Program.cs@@ -10,7 +10,6 @@ using System;using System.Collections.Generic;using System.Diagnostics;using System.Threading;-using System.Windows.Forms;using Microsoft.Extensions.Configuration;namespace GlazeWM.Bootstrapper@@ -42,7 +41,6 @@ namespace GlazeWM.Bootstrappervar startup = ServiceLocator.Provider.GetRequiredService<Startup>();startup.Run();- Application.Run();}private static IHost CreateHost(string[] args)@@ -52,6 +50,7 @@ namespace GlazeWM.Bootstrapper{appConfig.AddCommandLine(args, new Dictionary<string, string>{+ // Map CLI argument `--config` to `UserConfigPath` configuration key.{"--config", "UserConfigPath"}});})diff --git a/GlazeWM.Bootstrapper/Startup.cs b/GlazeWM.Bootstrapper/Startup.csindex 8893f489..326043ff 100644--- a/GlazeWM.Bootstrapper/Startup.cs+++ b/GlazeWM.Bootstrapper/Startup.cs@@ -1,14 +1,6 @@using GlazeWM.Bar;-using GlazeWM.Domain.Containers;-using GlazeWM.Domain.Containers.Commands;-using GlazeWM.Domain.Containers.Events;-using GlazeWM.Domain.Monitors;-using GlazeWM.Domain.Monitors.Commands;-using GlazeWM.Domain.UserConfigs.Commands;-using GlazeWM.Domain.Windows;+using GlazeWM.Domain.Common.Commands;using GlazeWM.Domain.Windows.Commands;-using GlazeWM.Domain.Workspaces;-using GlazeWM.Domain.Workspaces.Commands;using GlazeWM.Infrastructure.Bussing;using GlazeWM.Infrastructure.WindowsApi;using GlazeWM.Infrastructure.WindowsApi.Events;@@ -23,34 +15,24 @@ namespace GlazeWM.Bootstrapperinternal class Startup{private readonly Bus _bus;- private readonly MonitorService _monitorService;private readonly KeybindingService _keybindingService;private readonly WindowEventService _windowEventService;- private readonly WindowService _windowService;private readonly BarService _barService;- private readonly WorkspaceService _workspaceService;private readonly SystemTrayService _systemTrayService;private readonly SystemEventService _systemEventService;public Startup(Bus bus,- MonitorService monitorService,KeybindingService keybindingService,WindowEventService windowEventService,- WindowService windowService,BarService barService,- WorkspaceService workspaceService,SystemTrayService systemTrayService,- SystemEventService systemEventService- )+ SystemEventService systemEventService){_bus = bus;- _monitorService = monitorService;_keybindingService = keybindingService;_windowEventService = windowEventService;- _windowService = windowService;_barService = barService;- _workspaceService = workspaceService;_systemTrayService = systemTrayService;_systemEventService = systemEventService;}@@ -65,7 +47,7 @@ namespace GlazeWM.Bootstrapper_barService.StartApp();// Populate initial monitors, windows, workspaces and user config.- PopulateInitialState();+ _bus.Invoke(new PopulateInitialStateCommand());// Listen on registered keybindings._keybindingService.Start();@@ -81,65 +63,8 @@ namespace GlazeWM.Bootstrapper_bus.Events.Where(@event => @event is ApplicationExitingEvent).Subscribe(_ => OnApplicationExit());- }-- /// <summary>- /// Populate initial monitors, windows, workspaces and user config.- /// </summary>- private void PopulateInitialState()- {- // Read user config file and set its values in state.- _bus.Invoke(new EvaluateUserConfigCommand());-- // Create a Monitor and consequently a Workspace for each detected Screen. `AllScreens` is an- // abstraction over `EnumDisplayMonitors` native method.- foreach (var screen in Screen.AllScreens)- _bus.Invoke(new AddMonitorCommand(screen));-- // Add initial windows to the tree.- foreach (var windowHandle in WindowService.GetAllWindowHandles())- {- // Register appbar windows.- if (_windowService.IsHandleAppBar(windowHandle))- {- _windowService.AppBarHandles.Add(windowHandle);- continue;- }-- if (!WindowService.IsHandleManageable(windowHandle))- continue;-- // Get workspace that encompasses most of the window.- var targetMonitor = _monitorService.GetMonitorFromHandleLocation(windowHandle);- var targetWorkspace = targetMonitor.DisplayedWorkspace;-- _bus.Invoke(new AddWindowCommand(windowHandle, targetWorkspace, false));- }-- _bus.Invoke(new RedrawContainersCommand());-- // Get the originally focused window when the WM is started.- var focusedWindow =- _windowService.GetWindows().FirstOrDefault(window => window.Hwnd == GetForegroundWindow());-- if (focusedWindow != null)- {- _bus.Invoke(new SetFocusedDescendantCommand(focusedWindow));- _bus.RaiseEvent(new FocusChangedEvent(focusedWindow));- return;- }-- // `GetForegroundWindow` might return a handle that is not in the tree. In that case, set- // focus to an arbitrary window. If there are no manageable windows in the tree, set focus to- // an arbitrary workspace.- var containerToFocus =- _windowService.GetWindows().FirstOrDefault() as Container- ?? _workspaceService.GetActiveWorkspaces().FirstOrDefault();- if (containerToFocus is Window)- _bus.Invoke(new FocusWindowCommand(containerToFocus as Window));- else if (containerToFocus is Workspace)- _bus.Invoke(new FocusWorkspaceCommand((containerToFocus as Workspace).Name));+ Application.Run();}private void OnApplicationExit()@@ -148,6 +73,8 @@ namespace GlazeWM.Bootstrapper_barService.ExitApp();_systemTrayService.RemoveFromSystemTray();Application.Exit();+ // TODO: Use exit code 1 if exiting due to an unhandled error.+ Environment.Exit(0);}}}diff --git a/GlazeWM.Domain/Common/CommandHandlers/PopulateInitialStateHandler.cs b/GlazeWM.Domain/Common/CommandHandlers/PopulateInitialStateHandler.csnew file mode 100644index 00000000..056baac5--- /dev/null+++ b/GlazeWM.Domain/Common/CommandHandlers/PopulateInitialStateHandler.cs@@ -0,0 +1,99 @@+using System.Linq;+using GlazeWM.Domain.Common.Commands;+using GlazeWM.Domain.Containers;+using GlazeWM.Domain.Containers.Commands;+using GlazeWM.Domain.Containers.Events;+using GlazeWM.Domain.Monitors;+using GlazeWM.Domain.Monitors.Commands;+using GlazeWM.Domain.UserConfigs.Commands;+using GlazeWM.Domain.Windows;+using GlazeWM.Domain.Windows.Commands;+using GlazeWM.Domain.Workspaces;+using GlazeWM.Domain.Workspaces.Commands;+using GlazeWM.Infrastructure.Bussing;+using static GlazeWM.Infrastructure.WindowsApi.WindowsApiService;++namespace GlazeWM.Domain.Common.CommandHandlers+{+ internal class PopulateInitialStateHandler : ICommandHandler<PopulateInitialStateCommand>+ {+ private readonly Bus _bus;+ private readonly MonitorService _monitorService;+ private readonly WindowService _windowService;+ private readonly WorkspaceService _workspaceService;++ public PopulateInitialStateHandler(Bus bus,+ MonitorService monitorService,+ WindowService windowService,+ WorkspaceService workspaceService)+ {+ _bus = bus;+ _monitorService = monitorService;+ _windowService = windowService;+ _workspaceService = workspaceService;+ }++ public CommandResponse Handle(PopulateInitialStateCommand command)+ {+ // Read user config file and set its values in state.+ _bus.Invoke(new EvaluateUserConfigCommand());++ PopulateContainerTree();++ // Register appbar windows.+ foreach (var windowHandle in WindowService.GetAllWindowHandles())+ if (_windowService.IsHandleAppBar(windowHandle))+ _windowService.AppBarHandles.Add(windowHandle);++ _bus.Invoke(new RedrawContainersCommand());++ // Get the originally focused window when the WM is started.+ var focusedWindow =+ _windowService.GetWindows().FirstOrDefault(window => window.Hwnd == GetForegroundWindow());++ if (focusedWindow is not null)+ {+ _bus.Invoke(new SetFocusedDescendantCommand(focusedWindow));+ _bus.RaiseEvent(new FocusChangedEvent(focusedWindow));+ return CommandResponse.Ok;+ }++ // `GetForegroundWindow` might return a handle that is not in the tree. In that case, set+ // focus to an arbitrary window. If there are no manageable windows in the tree, set focus to+ // an arbitrary workspace.+ var containerToFocus =+ _windowService.GetWindows().FirstOrDefault() as Container+ ?? _workspaceService.GetActiveWorkspaces().FirstOrDefault();++ if (containerToFocus is Window)+ _bus.Invoke(new FocusWindowCommand(containerToFocus as Window));+ else if (containerToFocus is Workspace)+ _bus.Invoke(new FocusWorkspaceCommand((containerToFocus as Workspace).Name));++ return CommandResponse.Ok;+ }++ private void PopulateContainerTree()+ {+ // Create a Monitor and consequently a Workspace for each detected Screen. `AllScreens` is an+ // abstraction over `EnumDisplayMonitors` native method.+ foreach (var screen in System.Windows.Forms.Screen.AllScreens)+ _bus.Invoke(new AddMonitorCommand(screen));++ // Add initial windows to the tree.+ // TODO: Copy all the below over to populate with cache method, but filter out window handles+ // that have already been added to state.+ foreach (var windowHandle in WindowService.GetAllWindowHandles())+ {+ if (!WindowService.IsHandleManageable(windowHandle))+ continue;++ // Get workspace that encompasses most of the window.+ var targetMonitor = _monitorService.GetMonitorFromHandleLocation(windowHandle);+ var targetWorkspace = targetMonitor.DisplayedWorkspace;++ _bus.Invoke(new AddWindowCommand(windowHandle, targetWorkspace, false));+ }+ }+ }+}diff --git a/GlazeWM.Domain/Common/Commands/PopulateInitialStateCommand.cs b/GlazeWM.Domain/Common/Commands/PopulateInitialStateCommand.csnew file mode 100644index 00000000..d26c9517--- /dev/null+++ b/GlazeWM.Domain/Common/Commands/PopulateInitialStateCommand.cs@@ -0,0 +1,11 @@+using GlazeWM.Infrastructure.Bussing;++namespace GlazeWM.Domain.Common.Commands+{+ /// <summary>+ /// Populate initial monitors, windows, workspaces, and user config.+ /// </summary>+ public class PopulateInitialStateCommand : Command+ {+ }+}diff --git a/GlazeWM.Domain/DependencyInjection.cs b/GlazeWM.Domain/DependencyInjection.csindex f6f27531..7c8538d6 100644--- a/GlazeWM.Domain/DependencyInjection.cs+++ b/GlazeWM.Domain/DependencyInjection.cs@@ -1,4 +1,5 @@-using GlazeWM.Domain.Common.CommandHandlers;+using GlazeWM.Domain.Common;+using GlazeWM.Domain.Common.CommandHandlers;using GlazeWM.Domain.Common.Commands;using GlazeWM.Domain.Containers;using GlazeWM.Domain.Containers.CommandHandlers;@@ -35,6 +36,8 @@ namespace GlazeWM.Domainservices.AddSingleton<WorkspaceService>();services.AddSingleton<ICommandHandler<ExitApplicationCommand>, ExitApplicationHandler>();+ services.AddSingleton<ICommandHandler<PopulateInitialStateCommand>, PopulateInitialStateHandler>();+ services.AddSingleton<ICommandHandler<StartProcessCommand>, StartProcessHandler>();services.AddSingleton<ICommandHandler<AttachAndResizeContainerCommand>, AttachAndResizeContainerHandler>();services.AddSingleton<ICommandHandler<AttachContainerCommand>, AttachContainerHandler>();services.AddSingleton<ICommandHandler<ChangeContainerLayoutCommand>, ChangeContainerLayoutHandler>();@@ -52,6 +55,7 @@ namespace GlazeWM.Domainservices.AddSingleton<ICommandHandler<RemoveMonitorCommand>, RemoveMonitorHandler>();services.AddSingleton<ICommandHandler<EvaluateUserConfigCommand>, EvaluateUserConfigHandler>();services.AddSingleton<ICommandHandler<RegisterKeybindingsCommand>, RegisterKeybindingsHandler>();+ services.AddSingleton<ICommandHandler<ReloadUserConfigCommand>, ReloadUserConfigHandler>();services.AddSingleton<ICommandHandler<AddWindowCommand>, AddWindowHandler>();services.AddSingleton<ICommandHandler<CloseWindowCommand>, CloseWindowHandler>();services.AddSingleton<ICommandHandler<FocusWindowCommand>, FocusWindowHandler>();@@ -69,7 +73,7 @@ namespace GlazeWM.Domainservices.AddSingleton<ICommandHandler<DeactivateWorkspaceCommand>, DeactivateWorkspaceHandler>();services.AddSingleton<ICommandHandler<FocusWorkspaceCommand>, FocusWorkspaceHandler>();services.AddSingleton<ICommandHandler<MoveWindowToWorkspaceCommand>, MoveWindowToWorkspaceHandler>();- services.AddSingleton<ICommandHandler<StartProcessCommand>, StartProcessHandler>();+ services.AddSingleton<ICommandHandler<UpdateWorkspacesFromConfigCommand>, UpdateWorkspacesFromConfigHandler>();services.AddSingleton<IEventHandler<DisplaySettingsChangedEvent>, DisplaySettingsChangedHandler>();services.AddSingleton<IEventHandler<WindowDestroyedEvent>, WindowDestroyedHandler>();diff --git a/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.cs b/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.csindex a36ed6d6..fca00c26 100644--- a/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.cs+++ b/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.cs@@ -28,6 +28,8 @@ namespace GlazeWM.Domain.UserConfigs.CommandHandlerspublic CommandResponse Handle(RegisterKeybindingsCommand command){+ _keybindingService.Reset();+foreach (var keybindingConfig in command.Keybindings){// Format command strings defined in keybinding config.diff --git a/GlazeWM.Domain/UserConfigs/CommandHandlers/ReloadUserConfigHandler.cs b/GlazeWM.Domain/UserConfigs/CommandHandlers/ReloadUserConfigHandler.csnew file mode 100644index 00000000..629de73d--- /dev/null+++ b/GlazeWM.Domain/UserConfigs/CommandHandlers/ReloadUserConfigHandler.cs@@ -0,0 +1,69 @@+using System.Linq;+using GlazeWM.Domain.Containers;+using GlazeWM.Domain.Containers.Commands;+using GlazeWM.Domain.UserConfigs.Commands;+using GlazeWM.Domain.UserConfigs.Events;+using GlazeWM.Domain.Windows;+using GlazeWM.Domain.Workspaces.Commands;+using GlazeWM.Infrastructure.Bussing;++namespace GlazeWM.Domain.UserConfigs.CommandHandlers+{+ internal class ReloadUserConfigHandler : ICommandHandler<ReloadUserConfigCommand>+ {+ private readonly Bus _bus;+ private readonly CommandParsingService _commandParsingService;+ private readonly ContainerService _containerService;+ private readonly UserConfigService _userConfigService;+ private readonly WindowService _windowService;++ public ReloadUserConfigHandler(+ Bus bus,+ CommandParsingService commandParsingService,+ ContainerService containerService,+ UserConfigService userConfigService,+ WindowService windowService)+ {+ _bus = bus;+ _commandParsingService = commandParsingService;+ _containerService = containerService;+ _userConfigService = userConfigService;+ _windowService = windowService;+ }++ public CommandResponse Handle(ReloadUserConfigCommand command)+ {+ // Re-evaluate user config file and set its values in state.+ _bus.Invoke(new EvaluateUserConfigCommand());++ _bus.Invoke(new UpdateWorkspacesFromConfigCommand(_userConfigService.UserConfig.Workspaces));++ foreach (var window in _windowService.GetWindows())+ {+ // TODO: Create `RunWindowRulesCommand(Window window, List<WindowRule> windowRules).+ var matchingWindowRules = _userConfigService.GetMatchingWindowRules(window);++ var commandStrings = matchingWindowRules+ .SelectMany(rule => rule.CommandList)+ .Select(commandString => CommandParsingService.FormatCommand(commandString));++ var parsedCommands = commandStrings+ .Select(commandString => _commandParsingService.ParseCommand(commandString, window))+ .ToList();++ // Invoke commands in the matching window rules. Use `dynamic` to resolve the command type+ // at runtime and allow multiple dispatch.+ foreach (var parsedCommand in parsedCommands)+ _bus.Invoke((dynamic)parsedCommand);+ }++ // Redraw full container tree.+ _containerService.ContainersToRedraw.Add(_containerService.ContainerTree);+ _bus.Invoke(new RedrawContainersCommand());++ _bus.RaiseEvent(new UserConfigReloadedEvent());++ return CommandResponse.Ok;+ }+ }+}diff --git a/GlazeWM.Domain/UserConfigs/CommandParsingService.cs b/GlazeWM.Domain/UserConfigs/CommandParsingService.csindex 2ce0a894..7ec7412a 100644--- a/GlazeWM.Domain/UserConfigs/CommandParsingService.cs+++ b/GlazeWM.Domain/UserConfigs/CommandParsingService.cs@@ -5,6 +5,7 @@ using GlazeWM.Domain.Common.Commands;using GlazeWM.Domain.Common.Enums;using GlazeWM.Domain.Containers;using GlazeWM.Domain.Containers.Commands;+using GlazeWM.Domain.UserConfigs.Commands;using GlazeWM.Domain.Windows;using GlazeWM.Domain.Windows.Commands;using GlazeWM.Domain.Workspaces.Commands;@@ -60,9 +61,11 @@ namespace GlazeWM.Domain.UserConfigs"close" => subjectContainer is Window? new CloseWindowCommand(subjectContainer as Window): new NoopCommand(),+ "reload" => ParseReloadCommand(commandParts),"start" => new StartProcessCommand(commandParts[1],- commandParts.Length > 2 ? commandParts[2..] : Array.Empty<string>()),+ commandParts.Length > 2 ? commandParts[2..] : Array.Empty<string>()+ ),// TODO: Temporary hack to avoid errors during `ValidateCommand`."ignore" => new NoopCommand(),_ => throw new ArgumentException(null, nameof(commandString)),@@ -181,6 +184,15 @@ namespace GlazeWM.Domain.UserConfigs};}+ private static Command ParseReloadCommand(string[] commandParts)+ {+ return commandParts[1] switch+ {+ "config" => new ReloadUserConfigCommand(),+ _ => throw new ArgumentException(null, nameof(commandParts)),+ };+ }+/// <summary>/// Whether a workspace exists with the given name./// </summary>diff --git a/GlazeWM.Domain/UserConfigs/Commands/ReloadUserConfigCommand.cs b/GlazeWM.Domain/UserConfigs/Commands/ReloadUserConfigCommand.csnew file mode 100644index 00000000..4a10a237--- /dev/null+++ b/GlazeWM.Domain/UserConfigs/Commands/ReloadUserConfigCommand.cs@@ -0,0 +1,8 @@+using GlazeWM.Infrastructure.Bussing;++namespace GlazeWM.Domain.UserConfigs.Commands+{+ public class ReloadUserConfigCommand : Command+ {+ }+}diff --git a/GlazeWM.Domain/UserConfigs/Events/UserConfigReloadedEvent.cs b/GlazeWM.Domain/UserConfigs/Events/UserConfigReloadedEvent.csnew file mode 100644index 00000000..c9ccd36c--- /dev/null+++ b/GlazeWM.Domain/UserConfigs/Events/UserConfigReloadedEvent.cs@@ -0,0 +1,8 @@+using GlazeWM.Infrastructure.Bussing;++namespace GlazeWM.Domain.UserConfigs.Events+{+ public class UserConfigReloadedEvent : Event+ {+ }+}diff --git a/GlazeWM.Domain/UserConfigs/UserConfigService.cs b/GlazeWM.Domain/UserConfigs/UserConfigService.csindex 108c07f7..311f81bb 100644--- a/GlazeWM.Domain/UserConfigs/UserConfigService.cs+++ b/GlazeWM.Domain/UserConfigs/UserConfigService.cs@@ -14,15 +14,16 @@ namespace GlazeWM.Domain.UserConfigs/// <summary>/// Path to the user's config file./// </summary>- public string UserConfigPath => _configuration.GetValue<string>("UserConfigPath") ?? _defaultUserConfigPath;-+ public string UserConfigPath =>+ _configuration.GetValue<string>("UserConfigPath") ?? _defaultUserConfigPath;+private readonly string _defaultUserConfigPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),"./.glaze-wm/config.yaml");private readonly IConfiguration _configuration;-+public UserConfigService(IConfiguration configuration){_configuration = configuration;diff --git a/GlazeWM.Domain/Windows/CommandHandlers/ResizeWindowBordersHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/ResizeWindowBordersHandler.csindex d63fe06c..8c44bee8 100644--- a/GlazeWM.Domain/Windows/CommandHandlers/ResizeWindowBordersHandler.cs+++ b/GlazeWM.Domain/Windows/CommandHandlers/ResizeWindowBordersHandler.cs@@ -22,18 +22,20 @@ namespace GlazeWM.Domain.Windows.CommandHandlersvar borderDelta = command.BorderDelta;var windowToResize = command.WindowToResize;- // Adjust the existing border delta of the window.+ // Set the new border delta of the window.+ // TODO: Move default border delta into some sort of shared state.+ var defaultBorderDelta = new RectDelta(7, 0, 7, 7);windowToResize.BorderDelta = new RectDelta(- windowToResize.BorderDelta.DeltaLeft + borderDelta.DeltaLeft,- windowToResize.BorderDelta.DeltaTop + borderDelta.DeltaTop,- windowToResize.BorderDelta.DeltaRight + borderDelta.DeltaRight,- windowToResize.BorderDelta.DeltaBottom + borderDelta.DeltaBottom+ defaultBorderDelta.DeltaLeft + borderDelta.DeltaLeft,+ defaultBorderDelta.DeltaTop + borderDelta.DeltaTop,+ defaultBorderDelta.DeltaRight + borderDelta.DeltaRight,+ defaultBorderDelta.DeltaBottom + borderDelta.DeltaBottom);+ // No need to redraw if window isn't tiling.if (windowToResize is not TilingWindow)return CommandResponse.Ok;- // Only redraw the window if it's tiling._containerService.ContainersToRedraw.Add(windowToResize);_bus.Invoke(new RedrawContainersCommand());diff --git a/GlazeWM.Domain/Workspaces/CommandHandlers/UpdateWorkspacesFromConfigHandler.cs b/GlazeWM.Domain/Workspaces/CommandHandlers/UpdateWorkspacesFromConfigHandler.csnew file mode 100644index 00000000..e79d0f36--- /dev/null+++ b/GlazeWM.Domain/Workspaces/CommandHandlers/UpdateWorkspacesFromConfigHandler.cs@@ -0,0 +1,59 @@+using System.Linq;+using GlazeWM.Infrastructure.Bussing;+using GlazeWM.Domain.Workspaces.Commands;+using GlazeWM.Domain.Monitors;+using GlazeWM.Infrastructure.Exceptions;+using GlazeWM.Domain.UserConfigs;++namespace GlazeWM.Domain.Workspaces.CommandHandlers+{+ internal class UpdateWorkspacesFromConfigHandler :+ ICommandHandler<UpdateWorkspacesFromConfigCommand>+ {+ private readonly Bus _bus;+ private readonly WorkspaceService _workspaceService;+ private readonly UserConfigService _userConfigService;++ public UpdateWorkspacesFromConfigHandler(+ Bus bus,+ WorkspaceService workspaceService,+ UserConfigService userConfigService)+ {+ _bus = bus;+ _workspaceService = workspaceService;+ _userConfigService = userConfigService;+ }++ public CommandResponse Handle(UpdateWorkspacesFromConfigCommand command)+ {+ var workspaceConfigs = command.WorkspaceConfigs;+ var workspaces = _workspaceService.GetActiveWorkspaces();++ foreach (var workspace in workspaces)+ {+ var workspaceConfig = workspaceConfigs.Find(config => config.Name == workspace.Name);++ if (workspaceConfig is null)+ {+ var monitor = workspace.Parent as Monitor;+ // TODO: Move this to a dedicated `WorkspaceService` method.+ var inactiveWorkspaceName = _workspaceService.GetInactiveWorkspaceNameForMonitor(monitor) ??+ _workspaceService.GetInactiveWorkspaceNamesNotDedicatedToAMonitor().ElementAtOrDefault(0) ??+ _workspaceService.GetInactiveWorkspaceNames().ElementAtOrDefault(0);++ if (inactiveWorkspaceName is null)+ throw new FatalUserException("At least 1 workspace is required per monitor.");++ var inactiveWorkspaceConfig =+ _userConfigService.GetWorkspaceConfigByName(inactiveWorkspaceName);++ workspace.Name = inactiveWorkspaceName;+ }++ // TODO: Update `DisplayName` and `KeepAlive` once they are changed to properties.+ }++ return CommandResponse.Ok;+ }+ }+}diff --git a/GlazeWM.Domain/Workspaces/Commands/UpdateWorkspacesFromConfigCommand.cs b/GlazeWM.Domain/Workspaces/Commands/UpdateWorkspacesFromConfigCommand.csnew file mode 100644index 00000000..84f6c6a0--- /dev/null+++ b/GlazeWM.Domain/Workspaces/Commands/UpdateWorkspacesFromConfigCommand.cs@@ -0,0 +1,16 @@+using System.Collections.Generic;+using GlazeWM.Domain.UserConfigs;+using GlazeWM.Infrastructure.Bussing;++namespace GlazeWM.Domain.Workspaces.Commands+{+ internal class UpdateWorkspacesFromConfigCommand : Command+ {+ public List<WorkspaceConfig> WorkspaceConfigs { get; }++ public UpdateWorkspacesFromConfigCommand(List<WorkspaceConfig> workspaceConfigs)+ {+ WorkspaceConfigs = workspaceConfigs;+ }+ }+}diff --git a/GlazeWM.Infrastructure/WindowsApi/KeybindingService.cs b/GlazeWM.Infrastructure/WindowsApi/KeybindingService.csindex 2c4ab0d1..f6fcdef4 100644--- a/GlazeWM.Infrastructure/WindowsApi/KeybindingService.cs+++ b/GlazeWM.Infrastructure/WindowsApi/KeybindingService.cs@@ -70,6 +70,11 @@ namespace GlazeWM.Infrastructure.WindowsApi_keybindingsByTriggerKey.Add(triggerKey, new List<Keybinding>() { keybinding });}+ public void Reset()+ {+ _keybindingsByTriggerKey.Clear();+ }+private static string FormatKeybinding(string key){var isNumeric = int.TryParse(key, out var _);