Skip to content

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

feat: add command for toggling tiling direction (#209)

blam32e7221be7fd
diff --git a/GlazeWM.Bootstrapper/sample-config.yaml b/GlazeWM.Bootstrapper/sample-config.yaml
index 8489304d..4280d201 100644
--- a/GlazeWM.Bootstrapper/sample-config.yaml
+++ b/GlazeWM.Bootstrapper/sample-config.yaml
@@ -125,9 +125,7 @@ keybindings:
binding: "Alt+R"
# Change tiling direction. This determines where new tiling windows will be inserted.
- - command: "tiling direction horizontal"
- binding: "Alt+Shift+V"
- - command: "tiling direction vertical"
+ - command: "toggle tiling direction"
binding: "Alt+V"
# Change focus between floating / tiling windows.
diff --git a/GlazeWM.Domain/Containers/CommandHandlers/ToggleContainerLayoutHandler.cs b/GlazeWM.Domain/Containers/CommandHandlers/ToggleContainerLayoutHandler.cs
new file mode 100644
index 00000000..aa4eb702
--- /dev/null
+++ b/GlazeWM.Domain/Containers/CommandHandlers/ToggleContainerLayoutHandler.cs
@@ -0,0 +1,25 @@
+using GlazeWM.Domain.Common.Enums;
+using GlazeWM.Domain.Containers.Commands;
+using GlazeWM.Infrastructure.Bussing;
+
+namespace GlazeWM.Domain.Containers.CommandHandlers
+{
+ internal sealed class ToggleContainerLayoutHandler : ICommandHandler<ToggleContainerLayoutCommand>
+ {
+ private readonly Bus _bus;
+
+ public ToggleContainerLayoutHandler(Bus bus)
+ {
+ _bus = bus;
+ }
+ public CommandResponse Handle(ToggleContainerLayoutCommand command)
+ {
+ var container = command.Container;
+ var currentLayout = (container as SplitContainer)?.Layout
+ ?? (container.Parent as SplitContainer).Layout;
+ var newLayout = currentLayout == Layout.Horizontal ? Layout.Vertical : Layout.Horizontal;
+ _bus.Invoke(new ChangeContainerLayoutCommand(container, newLayout));
+ return CommandResponse.Ok;
+ }
+ }
+}
diff --git a/GlazeWM.Domain/Containers/Commands/ToggleContainerLayoutCommand.cs b/GlazeWM.Domain/Containers/Commands/ToggleContainerLayoutCommand.cs
new file mode 100644
index 00000000..c682fe4c
--- /dev/null
+++ b/GlazeWM.Domain/Containers/Commands/ToggleContainerLayoutCommand.cs
@@ -0,0 +1,14 @@
+using GlazeWM.Infrastructure.Bussing;
+
+namespace GlazeWM.Domain.Containers.Commands
+{
+ public class ToggleContainerLayoutCommand : Command
+ {
+ public Container Container { get; }
+
+ public ToggleContainerLayoutCommand(Container container)
+ {
+ Container = container;
+ }
+ }
+}
diff --git a/GlazeWM.Domain/DependencyInjection.cs b/GlazeWM.Domain/DependencyInjection.cs
index ef87a872..4fbe6613 100644
--- a/GlazeWM.Domain/DependencyInjection.cs
+++ b/GlazeWM.Domain/DependencyInjection.cs
@@ -41,6 +41,7 @@ namespace GlazeWM.Domain
services.AddSingleton<ICommandHandler<AttachContainerCommand>, AttachContainerHandler>();
services.AddSingleton<ICommandHandler<CenterCursorOnRectCommand>, CenterCursorOnRectHandler>();
services.AddSingleton<ICommandHandler<ChangeContainerLayoutCommand>, ChangeContainerLayoutHandler>();
+ services.AddSingleton<ICommandHandler<ToggleContainerLayoutCommand>, ToggleContainerLayoutHandler>();
services.AddSingleton<ICommandHandler<DetachAndResizeContainerCommand>, DetachAndResizeContainerHandler>();
services.AddSingleton<ICommandHandler<DetachContainerCommand>, DetachContainerHandler>();
services.AddSingleton<ICommandHandler<FlattenSplitContainerCommand>, FlattenSplitContainerHandler>();
diff --git a/GlazeWM.Domain/UserConfigs/CommandParsingService.cs b/GlazeWM.Domain/UserConfigs/CommandParsingService.cs
index 8384b58e..4906216d 100644
--- a/GlazeWM.Domain/UserConfigs/CommandParsingService.cs
+++ b/GlazeWM.Domain/UserConfigs/CommandParsingService.cs
@@ -105,6 +105,7 @@ namespace GlazeWM.Domain.UserConfigs
{
"vertical" => new ChangeContainerLayoutCommand(subjectContainer, Layout.Vertical),
"horizontal" => new ChangeContainerLayoutCommand(subjectContainer, Layout.Horizontal),
+ "toggle" => new ToggleContainerLayoutCommand(subjectContainer),
_ => throw new ArgumentException(null, nameof(commandParts)),
},
_ => throw new ArgumentException(null, nameof(commandParts)),