Skip to content

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

refactor(domain): clean up `RemoveWindowHandler`

Lars Bergercb7930e6bd66
diff --git a/LarsWM.Domain/Windows/CommandHandlers/RemoveWindowHandler.cs b/LarsWM.Domain/Windows/CommandHandlers/RemoveWindowHandler.cs
index a2442887..f08f2801 100644
--- a/LarsWM.Domain/Windows/CommandHandlers/RemoveWindowHandler.cs
+++ b/LarsWM.Domain/Windows/CommandHandlers/RemoveWindowHandler.cs
@@ -30,9 +30,7 @@ namespace LarsWM.Domain.Windows.CommandHandlers
_bus.Invoke(new DetachContainerCommand(window.Parent as SplitContainer, window));
// Search for a new container to set focus to.
- // TODO: Consider refactoring this by traversing upwards via `SelfAndAncestors` prior to detaching
- // and finding a `Window` or `Workspace` in ancestor's focused orders (excluding the window to detach).
- var containerToFocus = GetLastFocusedDescendant(parent) ?? GetLastFocusedDescendant(grandparent);
+ var containerToFocus = parent.LastFocusedDescendant ?? grandparent.LastFocusedDescendant;
// Note that the hook that fires when a window closes is actually called AFTER the OS has
// automatically switched focus to a new window. So therefore, changing focus here will
@@ -44,12 +42,5 @@ namespace LarsWM.Domain.Windows.CommandHandlers
return CommandResponse.Ok;
}
-
- private Container GetLastFocusedDescendant(Container container)
- {
- return container.SelfAndAncestors
- .FirstOrDefault(container => container.LastFocusedDescendant != null)
- ?.LastFocusedDescendant;
- }
}
}