Skip to content

GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.

feat: add support for launching user defined processes (#108)

Aryaman Marathe80ae84306771
diff --git a/GlazeWM.Domain/Common/CommandHandlers/StartProcessHandler.cs b/GlazeWM.Domain/Common/CommandHandlers/StartProcessHandler.cs
new file mode 100644
index 00000000..44e994db
--- /dev/null
+++ b/GlazeWM.Domain/Common/CommandHandlers/StartProcessHandler.cs
@@ -0,0 +1,23 @@
+using System.Diagnostics;
+using GlazeWM.Domain.Common.Commands;
+using GlazeWM.Infrastructure.Bussing;
+
+namespace GlazeWM.Domain.Common.CommandHandlers
+{
+ public class StartProcessHandler : ICommandHandler<StartProcessCommand>
+ {
+ public CommandResponse Handle(StartProcessCommand command)
+ {
+ using var process = new Process();
+ process.StartInfo = new ProcessStartInfo
+ {
+ FileName = command.ProcessName,
+ Arguments = string.Join(" ", command.Args),
+ UseShellExecute = true
+ };
+ process.Start();
+
+ return CommandResponse.Ok;
+ }
+ }
+}
diff --git a/GlazeWM.Domain/Common/Commands/StartProcessCommand.cs b/GlazeWM.Domain/Common/Commands/StartProcessCommand.cs
new file mode 100644
index 00000000..45273e5c
--- /dev/null
+++ b/GlazeWM.Domain/Common/Commands/StartProcessCommand.cs
@@ -0,0 +1,16 @@
+using GlazeWM.Infrastructure.Bussing;
+
+namespace GlazeWM.Domain.Common.Commands
+{
+ public class StartProcessCommand : Command
+ {
+ public string ProcessName { get; init; }
+ public string[] Args { get; init; }
+
+ public StartProcessCommand(string processName, string[] args)
+ {
+ ProcessName = processName;
+ Args = args;
+ }
+ }
+}
diff --git a/GlazeWM.Domain/DependencyInjection.cs b/GlazeWM.Domain/DependencyInjection.cs
index 036c8cb1..429de012 100644
--- a/GlazeWM.Domain/DependencyInjection.cs
+++ b/GlazeWM.Domain/DependencyInjection.cs
@@ -1,4 +1,4 @@
-using GlazeWM.Domain.Common.CommandHandlers;
+using GlazeWM.Domain.Common.CommandHandlers;
using GlazeWM.Domain.Common.Commands;
using GlazeWM.Domain.Containers;
using GlazeWM.Domain.Containers.CommandHandlers;
@@ -70,6 +70,7 @@ namespace GlazeWM.Domain
services.AddSingleton<ICommandHandler<DisplayWorkspaceCommand>, DisplayWorkspaceHandler>();
services.AddSingleton<ICommandHandler<FocusWorkspaceCommand>, FocusWorkspaceHandler>();
services.AddSingleton<ICommandHandler<MoveWindowToWorkspaceCommand>, MoveWindowToWorkspaceHandler>();
+ services.AddSingleton<ICommandHandler<StartProcessCommand>, StartProcessHandler>();
services.AddSingleton<IEventHandler<DisplaySettingsChangedEvent>, DisplaySettingsChangedHandler>();
services.AddSingleton<IEventHandler<WindowDestroyedEvent>, WindowDestroyedHandler>();
diff --git a/GlazeWM.Domain/UserConfigs/CommandParsingService.cs b/GlazeWM.Domain/UserConfigs/CommandParsingService.cs
index 0d1f0a30..2ce0a894 100644
--- a/GlazeWM.Domain/UserConfigs/CommandParsingService.cs
+++ b/GlazeWM.Domain/UserConfigs/CommandParsingService.cs
@@ -60,6 +60,9 @@ namespace GlazeWM.Domain.UserConfigs
"close" => subjectContainer is Window
? new CloseWindowCommand(subjectContainer as Window)
: new NoopCommand(),
+ "start" => new StartProcessCommand(
+ commandParts[1],
+ commandParts.Length > 2 ? commandParts[2..] : Array.Empty<string>()),
// TODO: Temporary hack to avoid errors during `ValidateCommand`.
"ignore" => new NoopCommand(),
_ => throw new ArgumentException(null, nameof(commandString)),