GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat(domain): invoke parsed keybinding command directly in `RegisterKeybindingsHandler`
Lars Bergerd0853e72c244
diff --git a/LarsWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.cs b/LarsWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.csindex 2731129a..b6672577 100644--- a/LarsWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.cs+++ b/LarsWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.cs@@ -26,22 +26,15 @@ namespace LarsWM.Domain.UserConfigs.CommandHandlers{var parsedCommand = ParseKeybindingCommand(keybinding.Command);- switch (parsedCommand)- {- case FocusWorkspaceKeybindingCommand focusWorkspaceCommand:- _keybindingService.AddGlobalKeybinding(- keybinding.Bindings[0],- () => _bus.Invoke(new FocusWorkspaceCommand(focusWorkspaceCommand.WorkspaceName))- );- break;- }+ foreach (var binding in keybinding.Bindings)+ // _keybindingService.AddGlobalKeybinding(binding, () => _bus.Invoke(parsedCommand));+ _keybindingService.AddGlobalKeybinding(binding, () => _bus.Invoke(new FocusWorkspaceCommand("1")));}return CommandResponse.Ok;}- // TODO: Consider changing to return a `Command` and simply invoking directly via bus above.- private object ParseKeybindingCommand(string commandName)+ private Command ParseKeybindingCommand(string commandName){var commandString = commandName.Trim().ToLowerInvariant();commandString = Regex.Replace(commandString, @"\s+", " ");@@ -49,14 +42,14 @@ namespace LarsWM.Domain.UserConfigs.CommandHandlersvar commandParts = commandString.Split(" ");switch (commandString){- case var a when Regex.IsMatch(commandString, @"focus workspace"):- var match = Regex.Match(a, @"focus workspace (?<workspaceName>.*?)$");+ case var _ when Regex.IsMatch(commandString, @"focus workspace"):+ var match = Regex.Match(commandString, @"focus workspace (?<workspaceName>.*?)$");// TODO: Check whether a workspace with the name exists (either here or in `FocusWorkspaceHandler`)- return new FocusWorkspaceKeybindingCommand(match.Groups["workspaceName"].Value);+ return new FocusWorkspaceCommand(match.Groups["workspaceName"].Value);// Throw error with message box to user if no command matches.// default: throw new ArgumentException();- default: return 1;+ default: return new FocusWorkspaceCommand("1");}}}diff --git a/LarsWM.Domain/UserConfigs/KeybindingCommands.cs b/LarsWM.Domain/UserConfigs/KeybindingCommands.csdeleted file mode 100644index 5d077463..00000000--- a/LarsWM.Domain/UserConfigs/KeybindingCommands.cs+++ /dev/null@@ -1,12 +0,0 @@-namespace LarsWM.Domain.UserConfigs-{- public class FocusWorkspaceKeybindingCommand- {- public string WorkspaceName { get; }-- public FocusWorkspaceKeybindingCommand(string workspaceName)- {- WorkspaceName = workspaceName;- }- }-}