GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat: prevent use command parts at workspaces names (#166)
Vladimir Kuznetsov0842576bfc7a
diff --git a/GlazeWM.Domain/Common/Utils/Keywords.cs b/GlazeWM.Domain/Common/Utils/Keywords.csnew file mode 100644index 00000000..39331a6f--- /dev/null+++ b/GlazeWM.Domain/Common/Utils/Keywords.cs@@ -0,0 +1,13 @@+using System.Collections.Generic;++namespace GlazeWM.Domain.Common.Utils+{+ public static class Keywords+ {+ /// <summary>+ /// Keywords that are part of the "focus workspace" commands+ /// Keywords cannot be used as a workspace name+ /// </summary>+ public static HashSet<string> WorkspaceKeyswords = new HashSet<string>() { "prev", "next", "recent" };+ }+}diff --git a/GlazeWM.Domain/UserConfigs/CommandHandlers/EvaluateUserConfigHandler.cs b/GlazeWM.Domain/UserConfigs/CommandHandlers/EvaluateUserConfigHandler.csindex e5a3b6eb..d4a197bf 100644--- a/GlazeWM.Domain/UserConfigs/CommandHandlers/EvaluateUserConfigHandler.cs+++ b/GlazeWM.Domain/UserConfigs/CommandHandlers/EvaluateUserConfigHandler.cs@@ -1,4 +1,5 @@-using GlazeWM.Domain.UserConfigs.Commands;+using GlazeWM.Domain.Common.Utils;+using GlazeWM.Domain.UserConfigs.Commands;using GlazeWM.Infrastructure.Bussing;using GlazeWM.Infrastructure.Exceptions;using GlazeWM.Infrastructure.Serialization;@@ -112,6 +113,9 @@ namespace GlazeWM.Domain.UserConfigs.CommandHandlers{if (workspaceConfig.Name is null)throw new FatalUserException("Property 'name' is required in workspace config.");++ if (Keywords.WorkspaceKeyswords.Contains(workspaceConfig.Name))+ throw new FatalUserException($"Can not use keyword '{workspaceConfig.Name}' as workspace name");}var componentConfigs = deserializedConfig.Bar.ComponentsLeftdiff --git a/GlazeWM.Domain/UserConfigs/CommandParsingService.cs b/GlazeWM.Domain/UserConfigs/CommandParsingService.csindex 7a38b7e0..3efb62f3 100644--- a/GlazeWM.Domain/UserConfigs/CommandParsingService.cs+++ b/GlazeWM.Domain/UserConfigs/CommandParsingService.cs@@ -4,6 +4,7 @@ using System.Linq;using System.Text.RegularExpressions;using GlazeWM.Domain.Common.Commands;using GlazeWM.Domain.Common.Enums;+using GlazeWM.Domain.Common.Utils;using GlazeWM.Domain.Containers;using GlazeWM.Domain.Containers.Commands;using GlazeWM.Domain.UserConfigs.Commands;@@ -228,12 +229,12 @@ namespace GlazeWM.Domain.UserConfigs}/// <summary>- /// Whether a workspace exists with the given name.+ /// Whether a workspace exists with the given name+ /// or workspace name is part of focus workspace command./// </summary>private bool IsValidWorkspace(string workspaceName){- // Validate command "focus workspace next" or "focus workspace prev"- if (workspaceName == "next" || workspaceName == "prev" || workspaceName == "recent")+ if (Keywords.WorkspaceKeyswords.Contains(workspaceName)){return true;}