Skip to content

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

feat(domain): allow focus window/workspace handlers to be called with the currently focused window/workspace

Lars Bergerdbfc247f0a10
diff --git a/LarsWM.Domain/Windows/CommandHandlers/FocusWindowHandler.cs b/LarsWM.Domain/Windows/CommandHandlers/FocusWindowHandler.cs
index 22aad9e1..3ba9c91c 100644
--- a/LarsWM.Domain/Windows/CommandHandlers/FocusWindowHandler.cs
+++ b/LarsWM.Domain/Windows/CommandHandlers/FocusWindowHandler.cs
@@ -22,16 +22,14 @@ namespace LarsWM.Domain.Windows.CommandHandlers
{
var window = command.Window;
- if (window == _containerService.FocusedContainer)
- return CommandResponse.Ok;
-
- // Adjust focus order of ancestors.
+ // Update focused container state.
_bus.Invoke(new SetFocusedDescendantCommand(window));
-
- SetForegroundWindow(window.Hwnd);
-
_bus.RaiseEvent(new FocusChangedEvent(window));
+ // Set as foreground window if it's not already set.
+ if (window.Hwnd != GetForegroundWindow())
+ SetForegroundWindow(window.Hwnd);
+
return CommandResponse.Ok;
}
}
diff --git a/LarsWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs b/LarsWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs
index 11fe6f0e..f73a5e64 100644
--- a/LarsWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs
+++ b/LarsWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs
@@ -38,16 +38,15 @@ namespace LarsWM.Domain.Workspaces.CommandHandlers
// isn't a container that has focus.
var focusedWorkspace = _workspaceService.GetFocusedWorkspace();
- if (workspaceToFocus == focusedWorkspace)
- return CommandResponse.Ok;
-
- // Whether the focused workspace is the only workspace on the monitor.
- var isOnlyWorkspace = focusedWorkspace.Parent.Children.Count() == 1
- && workspaceToFocus.Parent != focusedWorkspace.Parent;
+ // Whether the focused workspace has siblings other than the target workspace.
+ var focusedHasSiblings = focusedWorkspace.Siblings
+ .Where(sibling => sibling != workspaceToFocus)
+ .Count() > 0;
- // Destroy the currently focused workspace if it's empty.
+ // Destroy the currently focused workspace if it's empty. Cannot destroy empty workspaces
+ // if they're the last workspace on the monitor.
// TODO: Avoid destroying the workspace if `Workspace.KeepAlive` is enabled.
- if (!focusedWorkspace.HasChildren() && !isOnlyWorkspace)
+ if (!focusedWorkspace.HasChildren() && focusedHasSiblings)
_bus.Invoke(new DetachWorkspaceFromMonitorCommand(focusedWorkspace));
// Display the containers of the workspace to switch focus to.