GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat(domain): rename `CreateFocusStackCommand` -> `SetFocusedDescendant`; push to start of focus order instead of setting `LastFocusedChild`
Lars Berger12a6b15af3be
diff --git a/LarsWM.Domain/Containers/CommandHandlers/CreateFocusStackHandler.cs b/LarsWM.Domain/Containers/CommandHandlers/CreateFocusStackHandler.csdeleted file mode 100644index 648198a0..00000000--- a/LarsWM.Domain/Containers/CommandHandlers/CreateFocusStackHandler.cs+++ /dev/null@@ -1,44 +0,0 @@-using LarsWM.Domain.Containers.Commands;-using LarsWM.Domain.Workspaces.Events;-using LarsWM.Infrastructure.Bussing;--namespace LarsWM.Domain.Containers.CommandHandlers-{- class CreateFocusStackHandler : ICommandHandler<CreateFocusStackCommand>- {- private Bus _bus;- private ContainerService _containerService;-- public CreateFocusStackHandler(Bus bus, ContainerService containerService)- {- _bus = bus;- _containerService = containerService;- }-- public dynamic Handle(CreateFocusStackCommand command)- {- var target = command.FocusedContainer;- var focusedContainer = _containerService.FocusedContainer;-- if (target == focusedContainer)- return CommandResponse.Ok;-- _containerService.FocusedContainer = target;-- // Traverse upwards, creating a focus stack from the focused container.- while (target.Parent != null)- {- target.Parent.LastFocusedChild = target;- target = target.Parent;- }-- // Mark the end of the focus stack. Prevents a workspace from referencing- // a closed window if the last window in a workspace is closed.- target.LastFocusedChild = null;-- _bus.RaiseEvent(new FocusChangedEvent(command.FocusedContainer));-- return CommandResponse.Ok;- }- }-}diff --git a/LarsWM.Domain/Containers/CommandHandlers/SetFocusedDescendantHandler.cs b/LarsWM.Domain/Containers/CommandHandlers/SetFocusedDescendantHandler.csnew file mode 100644index 00000000..50c46772--- /dev/null+++ b/LarsWM.Domain/Containers/CommandHandlers/SetFocusedDescendantHandler.cs@@ -0,0 +1,40 @@+using LarsWM.Domain.Containers.Commands;+using LarsWM.Domain.Workspaces.Events;+using LarsWM.Infrastructure.Bussing;+using LarsWM.Infrastructure.Utils;++namespace LarsWM.Domain.Containers.CommandHandlers+{+ class SetFocusedDescendantHandler : ICommandHandler<SetFocusedDescendantCommand>+ {+ private Bus _bus;+ private ContainerService _containerService;++ public SetFocusedDescendantHandler(Bus bus, ContainerService containerService)+ {+ _bus = bus;+ _containerService = containerService;+ }++ public dynamic Handle(SetFocusedDescendantCommand command)+ {+ var focusDescendant = command.FocusedDescendant;++ // TODO: This should be moved to somewhere else.+ _containerService.FocusedContainer = focusDescendant;++ // Traverse upwards, setting the container as the last focused.+ var target = focusDescendant;+ while (target.Parent != null)+ {+ target.Parent.ChildFocusOrder.MoveToFront(target);+ target = target.Parent;+ }++ // TODO: This should be moved to somewhere else.+ _bus.RaiseEvent(new FocusChangedEvent(focusDescendant));++ return CommandResponse.Ok;+ }+ }+}diff --git a/LarsWM.Domain/Containers/Commands/CreateFocusStackCommand.cs b/LarsWM.Domain/Containers/Commands/CreateFocusStackCommand.csdeleted file mode 100644index 1123cb4f..00000000--- a/LarsWM.Domain/Containers/Commands/CreateFocusStackCommand.cs+++ /dev/null@@ -1,14 +0,0 @@-using LarsWM.Infrastructure.Bussing;--namespace LarsWM.Domain.Containers.Commands-{- public class CreateFocusStackCommand : Command- {- public Container FocusedContainer { get; }-- public CreateFocusStackCommand(Container focusedContainer)- {- FocusedContainer = focusedContainer;- }- }-}diff --git a/LarsWM.Domain/Containers/Commands/SetFocusedDescendantCommand.cs b/LarsWM.Domain/Containers/Commands/SetFocusedDescendantCommand.csnew file mode 100644index 00000000..39de80b1--- /dev/null+++ b/LarsWM.Domain/Containers/Commands/SetFocusedDescendantCommand.cs@@ -0,0 +1,14 @@+using LarsWM.Infrastructure.Bussing;++namespace LarsWM.Domain.Containers.Commands+{+ public class SetFocusedDescendantCommand : Command+ {+ public Container FocusedDescendant { get; }++ public SetFocusedDescendantCommand(Container focusedDescendant)+ {+ FocusedDescendant = focusedDescendant;+ }+ }+}diff --git a/LarsWM.Domain/DependencyInjection.cs b/LarsWM.Domain/DependencyInjection.csindex e73cea42..55cdf3f1 100644--- a/LarsWM.Domain/DependencyInjection.cs+++ b/LarsWM.Domain/DependencyInjection.cs@@ -29,7 +29,7 @@ namespace LarsWM.Domainservices.AddSingleton<WorkspaceService>();services.AddSingleton<AttachContainerHandler>();services.AddSingleton<ChangeContainerLayoutHandler>();- services.AddSingleton<CreateFocusStackHandler>();+ services.AddSingleton<SetFocusedDescendantHandler>();services.AddSingleton<DetachContainerHandler>();services.AddSingleton<RedrawContainersHandler>();services.AddSingleton<ReplaceContainerHandler>();@@ -63,7 +63,7 @@ namespace LarsWM.Domainbus.RegisterCommandHandler<SwapContainersHandler>();bus.RegisterCommandHandler<AddMonitorHandler>();bus.RegisterCommandHandler<AttachWorkspaceToMonitorHandler>();- bus.RegisterCommandHandler<CreateFocusStackHandler>();+ bus.RegisterCommandHandler<SetFocusedDescendantHandler>();bus.RegisterCommandHandler<DetachWorkspaceFromMonitorHandler>();bus.RegisterCommandHandler<EvaluateUserConfigHandler>();bus.RegisterCommandHandler<AddInitialWindowsHandler>();diff --git a/LarsWM.Domain/Windows/CommandHandlers/FocusWindowHandler.cs b/LarsWM.Domain/Windows/CommandHandlers/FocusWindowHandler.csindex 38c3da93..5fec5370 100644--- a/LarsWM.Domain/Windows/CommandHandlers/FocusWindowHandler.cs+++ b/LarsWM.Domain/Windows/CommandHandlers/FocusWindowHandler.cs@@ -25,7 +25,7 @@ namespace LarsWM.Domain.Windows.CommandHandlersreturn CommandResponse.Ok;// Create a focus stack pointing to the newly focused window.- _bus.Invoke(new CreateFocusStackCommand(window));+ _bus.Invoke(new SetFocusedDescendantCommand(window));SetForegroundWindow(window.Hwnd);diff --git a/LarsWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs b/LarsWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.csindex f9f33858..1ff88346 100644--- a/LarsWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs+++ b/LarsWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs@@ -53,7 +53,7 @@ namespace LarsWM.Domain.Workspaces.CommandHandlersif (!workspaceToFocus.HasChildren()){// Create a focus stack pointing to the workspace.- _bus.Invoke(new CreateFocusStackCommand(workspaceToFocus));+ _bus.Invoke(new SetFocusedDescendantCommand(workspaceToFocus));return CommandResponse.Ok;}