GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat(domain): ignore added windows based on matching window rules
Lars Bergerf24c986663de
diff --git a/LarsWM.Domain/Windows/CommandHandlers/AddInitialWindowsHandler.cs b/LarsWM.Domain/Windows/CommandHandlers/AddInitialWindowsHandler.csindex 1a7fda33..0dc2b2fb 100644--- a/LarsWM.Domain/Windows/CommandHandlers/AddInitialWindowsHandler.cs+++ b/LarsWM.Domain/Windows/CommandHandlers/AddInitialWindowsHandler.cs@@ -14,17 +14,19 @@ namespace LarsWM.Domain.Windows.CommandHandlersprivate UserConfigService _userConfigService;private MonitorService _monitorService;private WindowService _windowService;+ private CommandParsingService _commandParsingService;public AddInitialWindowsHandler(Bus bus,UserConfigService userConfigService,MonitorService monitorService,- WindowService windowService)+ WindowService windowService, CommandParsingService commandParsingService){_bus = bus;_userConfigService = userConfigService;_monitorService = monitorService;_windowService = windowService;+ _commandParsingService = commandParsingService;}public CommandResponse Handle(AddInitialWindowsCommand command)@@ -37,6 +39,13 @@ namespace LarsWM.Domain.Windows.CommandHandlers{var matchingWindowRules = GetMatchingWindowRules(window);+ var commandStrings = matchingWindowRules+ .SelectMany(rule => rule.CommandStrings)+ .Select(commandString => _commandParsingService.FormatCommand(commandString));++ if (commandStrings.Contains("ignore"))+ continue;+// Get workspace that encompasses most of the window.var targetMonitor = _monitorService.GetMonitorFromUnmanagedHandle(window.Hwnd);var targetWorkspace = targetMonitor.DisplayedWorkspace;diff --git a/LarsWM.Domain/Windows/CommandHandlers/AddWindowHandler.cs b/LarsWM.Domain/Windows/CommandHandlers/AddWindowHandler.csindex 1c4d7876..a26ab83f 100644--- a/LarsWM.Domain/Windows/CommandHandlers/AddWindowHandler.cs+++ b/LarsWM.Domain/Windows/CommandHandlers/AddWindowHandler.cs@@ -1,4 +1,5 @@-using System.Linq;+using System.Collections.Generic;+using System.Linq;using System.Text.RegularExpressions;using LarsWM.Domain.Containers;using LarsWM.Domain.Containers.Commands;@@ -17,14 +18,16 @@ namespace LarsWM.Domain.Windows.CommandHandlersprivate WindowService _windowService;private MonitorService _monitorService;private UserConfigService _userConfigService;+ private CommandParsingService _commandParsingService;- public AddWindowHandler(Bus bus, WindowService windowService, MonitorService monitorService, ContainerService containerService, UserConfigService userConfigService)+ public AddWindowHandler(Bus bus, WindowService windowService, MonitorService monitorService, ContainerService containerService, UserConfigService userConfigService, CommandParsingService commandParsingService){_bus = bus;_windowService = windowService;_monitorService = monitorService;_containerService = containerService;_userConfigService = userConfigService;+ _commandParsingService = commandParsingService;}public CommandResponse Handle(AddWindowCommand command)@@ -34,19 +37,26 @@ namespace LarsWM.Domain.Windows.CommandHandlersif (!window.IsManageable)return CommandResponse.Ok;- var matchedWindowRules = _userConfigService.UserConfig.WindowRules- .Where(rule => rule.ClassNameRegex.IsMatch(window.ClassName))- .Where(rule => rule.ProcessNameRegex.IsMatch(window.Process.ProcessName))- .Where(rule => rule.TitleRegex.IsMatch(window.Title));+ var matchingWindowRules = GetMatchingWindowRules(window);++ var commandStrings = matchingWindowRules+ .SelectMany(rule => rule.CommandStrings)+ .Select(commandString => _commandParsingService.FormatCommand(commandString));++ if (commandStrings.Contains("ignore"))+ return CommandResponse.Ok;var focusedContainer = _containerService.FocusedContainer;- // If the focused container is a workspace, attach the window as a child of the- // workspace. Otherwise, attach the window as a sibling to the focused window.+ // If the focused container is a workspace, attach the window as a child of the workspace.if (focusedContainer is Workspace)_bus.Invoke(new AttachContainerCommand(focusedContainer as Workspace, window));++ // Attach the window as a sibling next to the focused window.else- _bus.Invoke(new AttachContainerCommand(focusedContainer.Parent as SplitContainer, window));+ _bus.Invoke(new AttachContainerCommand(+ focusedContainer.Parent as SplitContainer, window, focusedContainer.Index + 1+ ));_bus.Invoke(new RedrawContainersCommand());@@ -55,5 +65,24 @@ namespace LarsWM.Domain.Windows.CommandHandlersreturn CommandResponse.Ok;}++ private List<WindowRuleConfig> GetMatchingWindowRules(Window window)+ {+ return _userConfigService.UserConfig.WindowRules+ .Where(rule =>+ {+ if (rule.ProcessNameRegex != null && !rule.ProcessNameRegex.IsMatch(window.Process.ProcessName))+ return false;++ if (rule.ClassNameRegex != null && !rule.ClassNameRegex.IsMatch(window.ClassName))+ return false;++ if (rule.TitleRegex != null && !rule.TitleRegex.IsMatch(window.Title))+ return false;++ return true;+ })+ .ToList();+ }}}