Skip to content

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

feat(domain): adjust focus order in `AttachContainerHandler`

Lars Berger7768e4bc837a
diff --git a/LarsWM.Domain/Containers/CommandHandlers/AttachContainerHandler.cs b/LarsWM.Domain/Containers/CommandHandlers/AttachContainerHandler.cs
index 02126672..3c16fff6 100644
--- a/LarsWM.Domain/Containers/CommandHandlers/AttachContainerHandler.cs
+++ b/LarsWM.Domain/Containers/CommandHandlers/AttachContainerHandler.cs
@@ -18,21 +18,25 @@ namespace LarsWM.Domain.Containers.CommandHandlers
public dynamic Handle(AttachContainerCommand command)
{
var parent = command.Parent;
- var newChild = command.ChildToAdd;
+ var childToAdd = command.ChildToAdd;
- if (newChild.Parent != null)
- _bus.Invoke(new DetachContainerCommand(newChild.Parent as SplitContainer, newChild));
+ if (childToAdd.Parent != null)
+ _bus.Invoke(new DetachContainerCommand(childToAdd.Parent as SplitContainer, childToAdd));
- // TODO: Adjust SizePercentage of current children.
- parent.Children.Insert(command.InsertPosition, newChild);
- newChild.Parent = parent;
+ parent.Children.Insert(command.InsertPosition, childToAdd);
+ childToAdd.Parent = parent;
+ // Adjust SizePercentage of self and siblings.
double defaultPercent = 1.0 / parent.Children.Count;
foreach (var child in parent.Children)
child.SizePercentage = defaultPercent;
_containerService.SplitContainersToRedraw.Add(parent);
+ // Adjust focus order of ancestors if the attached container is focused.
+ if (_containerService.FocusedContainer == childToAdd)
+ _bus.Invoke(new SetFocusedDescendantCommand(childToAdd));
+
return CommandResponse.Ok;
}
}