GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat(domain): get further ancestor if unable to swap in `MoveFocusedWindowHandler`
Lars Berger0f0230ef85b0
diff --git a/LarsWM.Domain/Windows/CommandHandlers/MoveFocusedWindowHandler.cs b/LarsWM.Domain/Windows/CommandHandlers/MoveFocusedWindowHandler.csindex bb2c6faa..5a08922e 100644--- a/LarsWM.Domain/Windows/CommandHandlers/MoveFocusedWindowHandler.cs+++ b/LarsWM.Domain/Windows/CommandHandlers/MoveFocusedWindowHandler.cs@@ -30,20 +30,22 @@ namespace LarsWM.Domain.Windows.CommandHandlersreturn CommandResponse.Ok;var direction = command.Direction;- var layoutForDirection = (direction == Direction.LEFT || direction == Direction.RIGHT)- ? Layout.Horizontal : Layout.Vertical;// The ancestor that the focused window should be moved within. This may simply be the parent of// the focused window, or it could be an ancestor further up the tree.- var ancestorWithLayout = focusedWindow.TraverseUpEnumeration()- .Where(container => (container as SplitContainer)?.Layout == layoutForDirection)- .FirstOrDefault() as SplitContainer;+ var ancestorWithLayout = GetContainerToMoveTo(focusedWindow, direction);// Change the layout of the workspace to `layoutForDirection`.if (ancestorWithLayout == null){var workspace = _workspaceService.GetWorkspaceFromChildContainer(focusedWindow);- workspace.Layout = layoutForDirection;+ workspace.Layout = GetLayoutForDirection(direction);++ // TODO: Should top-level split containers invert their layouts?+ // TODO: Should a new split container be created with the inverse layout to wrap all+ // elements other than the focused window?+ // TODO: If any top-level split containers match the new layout of the workspace,+ // then flatten them._containerService.SplitContainersToRedraw.Add(workspace);_bus.Invoke(new RedrawContainersCommand());@@ -60,6 +62,7 @@ namespace LarsWM.Domain.Windows.CommandHandlersfocusedWindow.SelfAndSiblings.ElementAtOrDefault(index - 1): focusedWindow.SelfAndSiblings.ElementAtOrDefault(index + 1);+ // TODO: Not sure whether this check is needed anymore.if (containerToSwap != null){_bus.Invoke(new SwapContainersCommand(focusedWindow, containerToSwap));@@ -83,5 +86,40 @@ namespace LarsWM.Domain.Windows.CommandHandlersreturn CommandResponse.Ok;}++ private Layout GetLayoutForDirection(Direction direction)+ {+ return (direction == Direction.LEFT || direction == Direction.RIGHT)+ ? Layout.Horizontal : Layout.Vertical;+ }++ private SplitContainer GetContainerToMoveTo(Window focusedWindow, Direction direction)+ {+ var layoutForDirection = GetLayoutForDirection(direction);++ return focusedWindow.TraverseUpEnumeration()+ .Where(ancestor =>+ {+ var isMatchingLayout = (ancestor as SplitContainer)?.Layout == layoutForDirection;++ if (!isMatchingLayout)+ return false;++ // Check whether it's possible to swap the focused window with a sibling.+ if (ancestor == focusedWindow.Parent)+ {+ var isFirstElement = focusedWindow == focusedWindow.SelfAndSiblings.First();+ var isLastElement = focusedWindow == focusedWindow.SelfAndSiblings.Last();++ if (direction == Direction.UP || direction == Direction.LEFT)+ return !isFirstElement;+ else+ return !isLastElement;+ }++ return true;+ })+ .FirstOrDefault() as SplitContainer;+ }}}