Skip to content

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

feat(domain): add `ChangeContainerLayoutCommand` argument for container to change * Instead of always using focused container. Also allows command to be called with empty workspaces.

Lars Berger1e930765bf80
diff --git a/LarsWM.Domain/Containers/CommandHandlers/ChangeContainerLayoutHandler.cs b/LarsWM.Domain/Containers/CommandHandlers/ChangeContainerLayoutHandler.cs
index 703ba26b..9cd1c9ba 100644
--- a/LarsWM.Domain/Containers/CommandHandlers/ChangeContainerLayoutHandler.cs
+++ b/LarsWM.Domain/Containers/CommandHandlers/ChangeContainerLayoutHandler.cs
@@ -1,4 +1,5 @@
using System.Linq;
+using LarsWM.Domain.Common.Enums;
using LarsWM.Domain.Containers.Commands;
using LarsWM.Domain.Windows;
using LarsWM.Domain.Workspaces;
@@ -21,46 +22,67 @@ namespace LarsWM.Domain.Containers.CommandHandlers
public CommandResponse Handle(ChangeContainerLayoutCommand command)
{
- var focusedContainer = _containerService.FocusedContainer;
- var parent = focusedContainer.Parent as SplitContainer;
-
+ var container = command.Container;
var newLayout = command.NewLayout;
+
+ if (container is Window)
+ ChangeWindowLayout(container as Window, newLayout);
+
+ else if (container is Workspace)
+ ChangeWorkspaceLayout(container as Workspace, newLayout);
+
+ return CommandResponse.Ok;
+ }
+
+ private void ChangeWindowLayout(Window window, Layout newLayout)
+ {
+ var parent = window.Parent as SplitContainer;
var currentLayout = parent.Layout;
if (currentLayout == newLayout)
- return CommandResponse.Ok;
+ return;
- var isFocusedOnlyChild = focusedContainer.Siblings.Count() == 0;
+ var isWindowOnlyChild = window.Siblings.Count() == 0;
- // If the focused window is an only child of a workspace, change layout of workspace.
- if (isFocusedOnlyChild && parent is Workspace)
+ // If the window is an only child of a workspace, change layout of the workspace.
+ if (isWindowOnlyChild && parent is Workspace)
{
- parent.Layout = newLayout;
- return CommandResponse.Ok;
+ ChangeWorkspaceLayout(parent as Workspace, newLayout);
+ return;
}
- // If the focused container is an only child and the parent is a normal split
- // container, then flatten the split container.
- if (isFocusedOnlyChild)
+ // If the window is an only child and the parent is a normal split container, then flatten
+ // the split container.
+ if (isWindowOnlyChild)
{
- _bus.Invoke(new ReplaceContainerCommand(parent.Parent, parent.Index, focusedContainer));
- _bus.Invoke(new RedrawContainersCommand());
- return CommandResponse.Ok;
+ _bus.Invoke(new ReplaceContainerCommand(parent.Parent, parent.Index, window));
+ return;
}
- // Create a new split container to wrap the focused container.
+ // Create a new split container to wrap the window.
var splitContainer = new SplitContainer
{
Layout = newLayout,
};
- // Replace the focused container with the new split container. The focused window has to be
- // attached to the split container after the replacement.
- _bus.Invoke(new ReplaceContainerCommand(parent, focusedContainer.Index, splitContainer));
- _bus.Invoke(new AttachContainerCommand(splitContainer, focusedContainer));
- _bus.Invoke(new RedrawContainersCommand());
+ // Replace the window with the wrapping split container. The window has to be attached to
+ // the split container after the replacement.
+ _bus.Invoke(new ReplaceContainerCommand(parent, window.Index, splitContainer));
+ _bus.Invoke(new AttachContainerCommand(splitContainer, window));
+ }
- return CommandResponse.Ok;
+ private void ChangeWorkspaceLayout(Workspace workspace, Layout newLayout)
+ {
+ var currentLayout = workspace.Layout;
+
+ if (currentLayout == newLayout)
+ return;
+
+ workspace.Layout = newLayout;
+
+ // TODO: Flatten any top-level split containers with the changed layout of the workspace.
+
+ _bus.Invoke(new RedrawContainersCommand());
}
}
}
diff --git a/LarsWM.Domain/Containers/Commands/ChangeContainerLayoutCommand.cs b/LarsWM.Domain/Containers/Commands/ChangeContainerLayoutCommand.cs
index 19a24db5..eeb48b60 100644
--- a/LarsWM.Domain/Containers/Commands/ChangeContainerLayoutCommand.cs
+++ b/LarsWM.Domain/Containers/Commands/ChangeContainerLayoutCommand.cs
@@ -1,15 +1,16 @@
using LarsWM.Domain.Common.Enums;
-using LarsWM.Domain.Common.Models;
using LarsWM.Infrastructure.Bussing;
namespace LarsWM.Domain.Containers.Commands
{
public class ChangeContainerLayoutCommand : Command
{
+ public Container Container { get; }
public Layout NewLayout { get; }
- public ChangeContainerLayoutCommand(Layout newLayout)
+ public ChangeContainerLayoutCommand(Container container, Layout newLayout)
{
+ Container = container;
NewLayout = newLayout;
}
}