Skip to content

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

feat(domain): find a window of inverse type to focus in `ToggleFocusHandler`

Lars Berger2ff06ab17859
diff --git a/GlazeWM.Domain/Containers/CommandHandlers/ToggleFocusModeHandler.cs b/GlazeWM.Domain/Containers/CommandHandlers/ToggleFocusModeHandler.cs
index 252bf22f..f61ed915 100644
--- a/GlazeWM.Domain/Containers/CommandHandlers/ToggleFocusModeHandler.cs
+++ b/GlazeWM.Domain/Containers/CommandHandlers/ToggleFocusModeHandler.cs
@@ -1,5 +1,7 @@
using GlazeWM.Domain.Common.Enums;
using GlazeWM.Domain.Containers.Commands;
+using GlazeWM.Domain.Windows;
+using GlazeWM.Domain.Windows.Commands;
using GlazeWM.Domain.Workspaces;
using GlazeWM.Infrastructure.Bussing;
@@ -7,30 +9,41 @@ namespace GlazeWM.Domain.Containers.CommandHandlers
{
class ToggleFocusModeHandler : ICommandHandler<ToggleFocusModeCommand>
{
+ private Bus _bus;
private ContainerService _containerService;
private WorkspaceService _workspaceService;
- public ToggleFocusModeHandler(ContainerService containerService, WorkspaceService workspaceService)
+ public ToggleFocusModeHandler(Bus bus, ContainerService containerService, WorkspaceService workspaceService)
{
+ _bus = bus;
_containerService = containerService;
_workspaceService = workspaceService;
}
+
public CommandResponse Handle(ToggleFocusModeCommand command)
{
var currentFocusMode = _containerService.FocusMode;
var targetFocusMode = currentFocusMode == FocusMode.TILING
? FocusMode.FLOATING : FocusMode.TILING;
- if (targetFocusMode == FocusMode.TILING)
- {
- // TODO: Get last focused descendant of `TilingWindow` type.
- }
+ var focusedWorkspace = _workspaceService.GetFocusedWorkspace();
+
+ Window windowToFocus = null;
if (targetFocusMode == FocusMode.FLOATING)
- {
- var focusedWorkspace = _workspaceService.GetFocusedWorkspace();
- // TODO: Get last focused descendant of `FloatingWindow` type.
- }
+ // Get the last focused tiling window within the workspace.
+ windowToFocus = focusedWorkspace.LastFocusedDescendantOfType(typeof(FloatingWindow))
+ as Window;
+
+ else
+ // Get the last focused floating window within the workspace.
+ windowToFocus = focusedWorkspace.LastFocusedDescendantOfType(typeof(TilingWindow))
+ as Window;
+
+ if (windowToFocus == null)
+ return CommandResponse.Ok;
+
+ _bus.Invoke(new FocusWindowCommand(windowToFocus));
return CommandResponse.Ok;
}