Skip to content

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

feat(domain): allow `AttachContainerCommand` to be used with parents that aren't split containers

Lars Bergere298b065589f
diff --git a/GlazeWM.Domain/Containers/CommandHandlers/MoveContainerWithinTreeHandler.cs b/GlazeWM.Domain/Containers/CommandHandlers/MoveContainerWithinTreeHandler.cs
index e2dc9586..255cc6a7 100644
--- a/GlazeWM.Domain/Containers/CommandHandlers/MoveContainerWithinTreeHandler.cs
+++ b/GlazeWM.Domain/Containers/CommandHandlers/MoveContainerWithinTreeHandler.cs
@@ -60,7 +60,7 @@ namespace GlazeWM.Domain.Containers.CommandHandlers
_bus.Invoke(new DetachContainerCommand(container));
- _bus.Invoke(new AttachContainerCommand(targetParent as SplitContainer, container, targetIndex));
+ _bus.Invoke(new AttachContainerCommand(targetParent, container, targetIndex));
// Set `container` as focused descendant within target subtree if its original subtree had
// focus more recently (even if the container is not the last focused within that subtree).
@@ -122,7 +122,7 @@ namespace GlazeWM.Domain.Containers.CommandHandlers
// top-level container to the right in a workspace.
var adjustedTargetIndex = shouldAdjustTargetIndex ? targetIndex - 1 : targetIndex;
- _bus.Invoke(new AttachContainerCommand(lowestCommonAncestor as SplitContainer, container, adjustedTargetIndex));
+ _bus.Invoke(new AttachContainerCommand(lowestCommonAncestor, container, adjustedTargetIndex));
lowestCommonAncestor.ChildFocusOrder.ShiftToIndex(originalFocusIndex, container);
}
diff --git a/GlazeWM.Domain/Containers/Commands/AttachContainerCommand.cs b/GlazeWM.Domain/Containers/Commands/AttachContainerCommand.cs
index 7ebaeb7d..caca9381 100644
--- a/GlazeWM.Domain/Containers/Commands/AttachContainerCommand.cs
+++ b/GlazeWM.Domain/Containers/Commands/AttachContainerCommand.cs
@@ -4,19 +4,19 @@ namespace GlazeWM.Domain.Containers.Commands
{
public class AttachContainerCommand : Command
{
- public SplitContainer Parent { get; }
+ public Container Parent { get; }
public Container ChildToAdd { get; }
public int InsertPosition { get; }
// Insert child as end element if `insertPosition` is not provided.
- public AttachContainerCommand(SplitContainer parent, Container childToAdd)
+ public AttachContainerCommand(Container parent, Container childToAdd)
{
Parent = parent;
ChildToAdd = childToAdd;
InsertPosition = parent.Children.Count;
}
- public AttachContainerCommand(SplitContainer parent, Container childToAdd, int insertPosition)
+ public AttachContainerCommand(Container parent, Container childToAdd, int insertPosition)
{
Parent = parent;
ChildToAdd = childToAdd;
diff --git a/GlazeWM.Domain/Windows/CommandHandlers/AddWindowHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/AddWindowHandler.cs
index 5558051b..df495055 100644
--- a/GlazeWM.Domain/Windows/CommandHandlers/AddWindowHandler.cs
+++ b/GlazeWM.Domain/Windows/CommandHandlers/AddWindowHandler.cs
@@ -106,13 +106,15 @@ namespace GlazeWM.Domain.Windows.CommandHandlers
// If the focused container is a workspace, attach the window as a child of the workspace.
if (focusedContainer is Workspace)
{
- _bus.Invoke(new AttachContainerCommand(focusedContainer as Workspace, window));
+ _bus.Invoke(new AttachContainerCommand(focusedContainer, window));
return;
}
// Attach the window as a sibling next to the focused window.
_bus.Invoke(new AttachContainerCommand(
- focusedContainer.Parent as SplitContainer, window, focusedContainer.Index + 1
+ focusedContainer.Parent,
+ window,
+ focusedContainer.Index + 1
));
}
}
diff --git a/GlazeWM.Domain/Windows/CommandHandlers/MoveFocusedWindowHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/MoveFocusedWindowHandler.cs
index 4ac3ad96..c2c07edf 100644
--- a/GlazeWM.Domain/Windows/CommandHandlers/MoveFocusedWindowHandler.cs
+++ b/GlazeWM.Domain/Windows/CommandHandlers/MoveFocusedWindowHandler.cs
@@ -172,7 +172,7 @@ namespace GlazeWM.Domain.Windows.CommandHandlers
var insertionIndex = (direction == Direction.UP || direction == Direction.LEFT) ?
insertionReference.Index : insertionReference.Index + 1;
- _bus.Invoke(new AttachContainerCommand(ancestorWithLayout as SplitContainer, focusedWindow, insertionIndex));
+ _bus.Invoke(new AttachContainerCommand(ancestorWithLayout, focusedWindow, insertionIndex));
}
_bus.Invoke(new RedrawContainersCommand());
diff --git a/GlazeWM.Domain/Workspaces/CommandHandlers/MoveFocusedWindowToWorkspaceHandler.cs b/GlazeWM.Domain/Workspaces/CommandHandlers/MoveFocusedWindowToWorkspaceHandler.cs
index b5a15546..f89af4e0 100644
--- a/GlazeWM.Domain/Workspaces/CommandHandlers/MoveFocusedWindowToWorkspaceHandler.cs
+++ b/GlazeWM.Domain/Workspaces/CommandHandlers/MoveFocusedWindowToWorkspaceHandler.cs
@@ -43,7 +43,7 @@ namespace GlazeWM.Domain.Workspaces.CommandHandlers
if (insertionTarget == null)
_bus.Invoke(new AttachContainerCommand(targetWorkspace, focusedWindow));
else
- _bus.Invoke(new AttachContainerCommand(insertionTarget.Parent as SplitContainer, focusedWindow, insertionTarget.Index + 1));
+ _bus.Invoke(new AttachContainerCommand(insertionTarget.Parent, focusedWindow, insertionTarget.Index + 1));
// Reassign focus to descendant within the current workspace.
_bus.Invoke(new FocusWorkspaceCommand(currentWorkspace.Name));