diff --git a/GlazeWM.Domain/UserConfigs/CommandHandlers/ReloadUserConfigHandler.cs b/GlazeWM.Domain/UserConfigs/CommandHandlers/ReloadUserConfigHandler.cs index 53a989cfb..b272d888e 100644 --- a/GlazeWM.Domain/UserConfigs/CommandHandlers/ReloadUserConfigHandler.cs +++ b/GlazeWM.Domain/UserConfigs/CommandHandlers/ReloadUserConfigHandler.cs @@ -38,7 +38,11 @@ public CommandResponse Handle(ReloadUserConfigCommand command) foreach (var window in _windowService.GetWindows()) { - var windowRules = _userConfigService.GetMatchingWindowRules(window); + var windowRules = _userConfigService.GetWindowRules( + window, + WindowRuleType.Manage + ); + var windowRuleCommands = windowRules .SelectMany(rule => rule.CommandList) .Select(CommandParsingService.FormatCommand); diff --git a/GlazeWM.Domain/UserConfigs/UserConfigService.cs b/GlazeWM.Domain/UserConfigs/UserConfigService.cs index 34269d917..92f81f10c 100644 --- a/GlazeWM.Domain/UserConfigs/UserConfigService.cs +++ b/GlazeWM.Domain/UserConfigs/UserConfigService.cs @@ -10,10 +10,18 @@ namespace GlazeWM.Domain.UserConfigs { public class UserConfigService { + private UserConfig _userConfig; + /// /// The deserialized user config. Sections of the config can be accessed via getters. /// - public UserConfig UserConfig { private get; set; } + public UserConfig UserConfig { + get => _userConfig; + set { + _userConfig = value; + _windowRulesByType = GetWindowRulesByType(value); + } + }; public GapsConfig GapsConfig => UserConfig.Gaps; public FocusBordersConfig FocusBorderConfig => UserConfig.FocusBorderColor; @@ -28,11 +36,7 @@ public class UserConfigService /// Dictionary of window rule types (eg. 'Manage', 'Focus') and the corresponding /// window rules of that type. /// - private Dictionary> WindowRulesByType = - new(Enum.GetValues(typeof(WindowRuleType)).ToDictionary( - (ruleType) => ruleType, - (_) => new List() - )); + private Dictionary> _windowRulesByType = new(); /// /// Path to the user's config file. @@ -115,6 +119,26 @@ private static List GetDefaultWindowRules() return windowRules; } + private Dictionary> GetWindowRulesByType( + UserConfig userConfig) + { + var windowRulesByType = Enum.GetValues(typeof(WindowRuleType)).ToDictionary( + (ruleType) => ruleType, + (_) => new List() + ); + + foreach (var windowRule in userConfig.WindowRules) + { + foreach (var ruleType in windowRule.On) + { + var windowRules = windowRulesByType[ruleType]; + windowRules.Add(windowRule); + } + } + + return windowRulesByType; + } + public WorkspaceConfig GetWorkspaceConfigByName(string workspaceName) { return WorkspaceConfigs.Find( @@ -138,9 +162,11 @@ public BarConfig GetBarConfigForMonitor(Monitor monitor) return boundMonitor ?? BarConfigs[0]; } - public List GetMatchingWindowRules(Window window) + public List GetWindowRules(Window window, WindowRuleType ruleType) { - return WindowRules.Where(rule => + var windowRules = _windowRulesByType[ruleType]; + + return windowRules.Where(rule => { return rule.ProcessNameRegex?.IsMatch(window.ProcessName) != false && rule.ClassNameRegex?.IsMatch(window.ClassName) != false &&