Skip to content

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

refactor(domain): avoid passing `Parent` arg to `DetachContainerCommand`

Lars Berger6e67716cc548
diff --git a/GlazeWM.Domain/Containers/CommandHandlers/AttachContainerHandler.cs b/GlazeWM.Domain/Containers/CommandHandlers/AttachContainerHandler.cs
index ad0b4a8b..03be3572 100644
--- a/GlazeWM.Domain/Containers/CommandHandlers/AttachContainerHandler.cs
+++ b/GlazeWM.Domain/Containers/CommandHandlers/AttachContainerHandler.cs
@@ -25,7 +25,7 @@ namespace GlazeWM.Domain.Containers.CommandHandlers
var isFocusedContainer = _containerService.FocusedContainer == childToAdd;
if (childToAdd.Parent != null)
- _bus.Invoke(new DetachContainerCommand(childToAdd.Parent as SplitContainer, childToAdd));
+ _bus.Invoke(new DetachContainerCommand(childToAdd));
parent.Children.Insert(command.InsertPosition, childToAdd);
childToAdd.Parent = parent;
diff --git a/GlazeWM.Domain/Containers/CommandHandlers/DetachContainerHandler.cs b/GlazeWM.Domain/Containers/CommandHandlers/DetachContainerHandler.cs
index 33bdc1a3..50640475 100644
--- a/GlazeWM.Domain/Containers/CommandHandlers/DetachContainerHandler.cs
+++ b/GlazeWM.Domain/Containers/CommandHandlers/DetachContainerHandler.cs
@@ -19,11 +19,11 @@ namespace GlazeWM.Domain.Containers.CommandHandlers
public CommandResponse Handle(DetachContainerCommand command)
{
- var parent = command.Parent;
var childToRemove = command.ChildToRemove;
+ var parent = childToRemove.Parent;
- parent.ChildFocusOrder.Remove(childToRemove);
parent.RemoveChild(childToRemove);
+ parent.ChildFocusOrder.Remove(childToRemove);
if (childToRemove is TilingWindow || childToRemove is SplitContainer)
AdjustSiblingSizes(parent);
@@ -31,7 +31,7 @@ namespace GlazeWM.Domain.Containers.CommandHandlers
return CommandResponse.Ok;
}
- private void AdjustSiblingSizes(SplitContainer parent)
+ private void AdjustSiblingSizes(Container parent)
{
// Siblings of the removed child.
var siblings = parent.Children;
@@ -43,7 +43,7 @@ namespace GlazeWM.Domain.Containers.CommandHandlers
// the split container as well.
if (isEmptySplitContainer)
{
- _bus.Invoke(new DetachContainerCommand(parent.Parent as SplitContainer, parent));
+ _bus.Invoke(new DetachContainerCommand(parent));
return;
}
@@ -56,7 +56,7 @@ namespace GlazeWM.Domain.Containers.CommandHandlers
foreach (var sibling in resizableSiblings)
(sibling as IResizable).SizePercentage = defaultPercent;
- _containerService.SplitContainersToRedraw.Add(parent);
+ _containerService.SplitContainersToRedraw.Add(parent as SplitContainer);
}
}
}
diff --git a/GlazeWM.Domain/Containers/Commands/DetachContainerCommand.cs b/GlazeWM.Domain/Containers/Commands/DetachContainerCommand.cs
index af55d0c7..12aea668 100644
--- a/GlazeWM.Domain/Containers/Commands/DetachContainerCommand.cs
+++ b/GlazeWM.Domain/Containers/Commands/DetachContainerCommand.cs
@@ -4,12 +4,10 @@ namespace GlazeWM.Domain.Containers.Commands
{
public class DetachContainerCommand : Command
{
- public SplitContainer Parent { get; }
public Container ChildToRemove { get; }
- public DetachContainerCommand(SplitContainer parent, Container childToRemove)
+ public DetachContainerCommand(Container childToRemove)
{
- Parent = parent;
ChildToRemove = childToRemove;
}
}
diff --git a/GlazeWM.Domain/Windows/CommandHandlers/RemoveWindowHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/RemoveWindowHandler.cs
index 533bd8a1..937a1783 100644
--- a/GlazeWM.Domain/Windows/CommandHandlers/RemoveWindowHandler.cs
+++ b/GlazeWM.Domain/Windows/CommandHandlers/RemoveWindowHandler.cs
@@ -29,7 +29,7 @@ namespace GlazeWM.Domain.Windows.CommandHandlers
var parent = window.Parent;
var grandparent = parent.Parent;
- _bus.Invoke(new DetachContainerCommand(window.Parent as SplitContainer, window));
+ _bus.Invoke(new DetachContainerCommand(window));
// Get container to switch focus to after the window has been removed. The OS automatically
// switches focus to a different window after closing, so by setting `PendingFocusContainer`