GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
refactor(domain): add getters for sections of `UserConfig`; refactor any direct uses of `UserConfig`
Lars Berger7e2f9129b9c3
diff --git a/GlazeWM.Bar/BarViewModel.cs b/GlazeWM.Bar/BarViewModel.csindex 86fdd223..0a87902f 100644--- a/GlazeWM.Bar/BarViewModel.cs+++ b/GlazeWM.Bar/BarViewModel.cs@@ -17,7 +17,7 @@ namespace GlazeWM.Barprivate readonly UserConfigService _userConfigService =ServiceLocator.Provider.GetRequiredService<UserConfigService>();- private BarConfig _barConfig => _userConfigService.UserConfig.Bar;+ private BarConfig _barConfig => _userConfigService.BarConfig;public BarPosition Position => _barConfig.Position;public string Background => _barConfig.Background;diff --git a/GlazeWM.Bar/Components/WorkspacesComponentViewModel.cs b/GlazeWM.Bar/Components/WorkspacesComponentViewModel.csindex 83919d34..8eccb589 100644--- a/GlazeWM.Bar/Components/WorkspacesComponentViewModel.cs+++ b/GlazeWM.Bar/Components/WorkspacesComponentViewModel.cs@@ -35,7 +35,7 @@ namespace GlazeWM.Bar.Componentsprivate IEnumerable<Workspace> _orderedWorkspaces => _monitor.Children.Cast<Workspace>().OrderBy((workspace) =>- _userConfigService.UserConfig.Workspaces.FindIndex(+ _userConfigService.WorkspaceConfigs.FindIndex((workspaceConfig) => workspaceConfig.Name == workspace.Name));diff --git a/GlazeWM.Bar/MainWindow.xaml.cs b/GlazeWM.Bar/MainWindow.xaml.csindex 43e0a850..62f3424d 100644--- a/GlazeWM.Bar/MainWindow.xaml.cs+++ b/GlazeWM.Bar/MainWindow.xaml.cs@@ -65,11 +65,11 @@ namespace GlazeWM.Barprivate void PositionWindow(IntPtr windowHandle){// Since window size is set manually, need to scale up height to make window DPI responsive.- var barHeight = _userConfigService.UserConfig.Bar.Height;+ var barHeight = _userConfigService.BarConfig.Height;var scaledBarHeight = Convert.ToInt32(barHeight * _monitor.ScaleFactor);// Get offset from top of monitor.- var barOffsetY = _userConfigService.UserConfig.Bar.Position == BarPosition.Bottom+ var barOffsetY = _userConfigService.BarConfig.Position == BarPosition.Bottom? _monitor.Height - scaledBarHeight: 0;diff --git a/GlazeWM.Domain/Containers/ContainerService.cs b/GlazeWM.Domain/Containers/ContainerService.csindex a7ee8113..c06a088e 100644--- a/GlazeWM.Domain/Containers/ContainerService.cs+++ b/GlazeWM.Domain/Containers/ContainerService.cs@@ -57,7 +57,7 @@ namespace GlazeWM.Domain.Containersif (parent.Layout == Layout.VERTICAL)return parent.Width;- var innerGap = _userConfigService.UserConfig.Gaps.InnerGap;+ var innerGap = _userConfigService.GapsConfig.InnerGap;var resizableSiblings = container.SelfAndSiblingsOfType<IResizable>();return (int)((container as IResizable).SizePercentage@@ -75,7 +75,7 @@ namespace GlazeWM.Domain.Containersif (parent.Layout == Layout.HORIZONTAL)return parent.Height;- var innerGap = _userConfigService.UserConfig.Gaps.InnerGap;+ var innerGap = _userConfigService.GapsConfig.InnerGap;var resizableSiblings = container.SelfAndSiblingsOfType<IResizable>();return (int)((container as IResizable).SizePercentage@@ -95,7 +95,7 @@ namespace GlazeWM.Domain.Containersif (parent.Layout == Layout.VERTICAL || isFirstOfType)return parent.X;- var innerGap = _userConfigService.UserConfig.Gaps.InnerGap;+ var innerGap = _userConfigService.GapsConfig.InnerGap;return container.PreviousSiblingOfType<IResizable>().X+ container.PreviousSiblingOfType<IResizable>().Width@@ -115,7 +115,7 @@ namespace GlazeWM.Domain.Containersif (parent.Layout == Layout.HORIZONTAL || isFirstOfType)return parent.Y;- var innerGap = _userConfigService.UserConfig.Gaps.InnerGap;+ var innerGap = _userConfigService.GapsConfig.InnerGap;return container.PreviousSiblingOfType<IResizable>().Y+ container.PreviousSiblingOfType<IResizable>().Heightdiff --git a/GlazeWM.Domain/UserConfigs/CommandHandlers/ReloadUserConfigHandler.cs b/GlazeWM.Domain/UserConfigs/CommandHandlers/ReloadUserConfigHandler.csindex 261d00b0..46933b75 100644--- a/GlazeWM.Domain/UserConfigs/CommandHandlers/ReloadUserConfigHandler.cs+++ b/GlazeWM.Domain/UserConfigs/CommandHandlers/ReloadUserConfigHandler.cs@@ -33,7 +33,7 @@ namespace GlazeWM.Domain.UserConfigs.CommandHandlers// Re-evaluate user config file and set its values in state._bus.Invoke(new EvaluateUserConfigCommand());- _bus.Invoke(new UpdateWorkspacesFromConfigCommand(_userConfigService.UserConfig.Workspaces));+ _bus.Invoke(new UpdateWorkspacesFromConfigCommand(_userConfigService.WorkspaceConfigs));foreach (var window in _windowService.GetWindows()){diff --git a/GlazeWM.Domain/UserConfigs/UserConfigService.cs b/GlazeWM.Domain/UserConfigs/UserConfigService.csindex 0c06e391..10192816 100644--- a/GlazeWM.Domain/UserConfigs/UserConfigService.cs+++ b/GlazeWM.Domain/UserConfigs/UserConfigService.cs@@ -9,7 +9,16 @@ namespace GlazeWM.Domain.UserConfigs{public class UserConfigService{- public UserConfig UserConfig { get; set; }+ /// <summary>+ /// The deserialized user config. Sections of the config can be accessed via getters.+ /// </summary>+ public UserConfig UserConfig { private get; set; }++ public GapsConfig GapsConfig => UserConfig.Gaps;+ public BarConfig BarConfig => UserConfig.Bar;+ public List<WorkspaceConfig> WorkspaceConfigs => UserConfig.Workspaces;+ public List<WindowRuleConfig> WindowRules => UserConfig.WindowRules;+ public List<KeybindingConfig> Keybindings => UserConfig.Keybindings;/// <summary>/// Path to the user's config file.diff --git a/GlazeWM.Domain/Workspaces/Workspace.cs b/GlazeWM.Domain/Workspaces/Workspace.csindex c07d02bc..8e98c79d 100644--- a/GlazeWM.Domain/Workspaces/Workspace.cs+++ b/GlazeWM.Domain/Workspaces/Workspace.cs@@ -30,7 +30,7 @@ namespace GlazeWM.Domain.Workspaces{get{- var barHeight = _userConfigService.UserConfig.Bar.Height;+ var barHeight = _userConfigService.BarConfig.Height;return Convert.ToInt32(barHeight * (Parent as Monitor).ScaleFactor);}}@@ -39,12 +39,12 @@ namespace GlazeWM.Domain.Workspaces{get{- var barPosition = _userConfigService.UserConfig.Bar.Position;+ var barPosition = _userConfigService.BarConfig.Position;return barPosition == BarPosition.Top ? _logicalBarHeight : 0;}}- private int _outerGap => _userConfigService.UserConfig.Gaps.OuterGap;+ private int _outerGap => _userConfigService.GapsConfig.OuterGap;public override int Height => Parent.Height - (_outerGap * 2) - _logicalBarHeight;public override int Width => Parent.Width - (_outerGap * 2);diff --git a/GlazeWM.Domain/Workspaces/WorkspaceService.cs b/GlazeWM.Domain/Workspaces/WorkspaceService.csindex ea20167e..bf68f346 100644--- a/GlazeWM.Domain/Workspaces/WorkspaceService.cs+++ b/GlazeWM.Domain/Workspaces/WorkspaceService.cs@@ -36,7 +36,7 @@ namespace GlazeWM.Domain.Workspaces{var activeWorkspaces = GetActiveWorkspaces();- return _userConfigService.UserConfig.Workspaces.Where(+ return _userConfigService.WorkspaceConfigs.Where((config) => !activeWorkspaces.Any((workspace) => workspace.Name == config.Name));}