GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat(domain): avoid changing focus to target workspace when moving focused window to workspace
Lars Bergere6dc3ab0e199
diff --git a/GlazeWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs b/GlazeWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.csindex 1d80df21..3a781ea2 100644--- a/GlazeWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs+++ b/GlazeWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs@@ -37,19 +37,19 @@ namespace GlazeWM.Domain.Workspaces.CommandHandlers// isn't a container that has focus.var focusedWorkspace = _workspaceService.GetFocusedWorkspace();+ // Display the containers of the workspace to switch focus to.+ _bus.Invoke(new DisplayWorkspaceCommand(workspaceToFocus));+// Whether the currently focused workspace is empty and should be detached. Cannot destroy// empty workspaces if they're the last workspace on the monitor or are pending focus.var shouldDestroyFocusedWorkspace = !focusedWorkspace.HasChildren()&& _containerService.PendingFocusContainer != focusedWorkspace- && focusedWorkspace.HasSiblings();+ && !focusedWorkspace.IsDisplayed;if (shouldDestroyFocusedWorkspace)// TODO: Avoid destroying the workspace if `Workspace.KeepAlive` is enabled._bus.Invoke(new DetachWorkspaceFromMonitorCommand(focusedWorkspace));- // Display the containers of the workspace to switch focus to.- _bus.Invoke(new DisplayWorkspaceCommand(workspaceToFocus));-// If workspace has no descendant windows, set focus to the workspace itself.if (!workspaceToFocus.HasChildren()){diff --git a/GlazeWM.Domain/Workspaces/CommandHandlers/MoveFocusedWindowToWorkspaceHandler.cs b/GlazeWM.Domain/Workspaces/CommandHandlers/MoveFocusedWindowToWorkspaceHandler.csindex 9991179a..d2d51d6d 100644--- a/GlazeWM.Domain/Workspaces/CommandHandlers/MoveFocusedWindowToWorkspaceHandler.cs+++ b/GlazeWM.Domain/Workspaces/CommandHandlers/MoveFocusedWindowToWorkspaceHandler.cs@@ -4,7 +4,6 @@ using GlazeWM.Domain.Containers;using GlazeWM.Domain.Windows;using GlazeWM.Domain.Monitors;using GlazeWM.Domain.Containers.Commands;-using GlazeWM.Domain.Containers.Events;using static GlazeWM.Infrastructure.WindowsApi.WindowsApiService;namespace GlazeWM.Domain.Workspaces.CommandHandlers@@ -34,32 +33,24 @@ namespace GlazeWM.Domain.Workspaces.CommandHandlersif (focusedWindow == null || foregroundWindow != focusedWindow.Hwnd)return CommandResponse.Ok;- var currentWorkspace = _workspaceService.GetWorkspaceFromChildContainer(focusedWindow);+ var currentWorkspace = _workspaceService.GetFocusedWorkspace();var targetWorkspace = _workspaceService.GetActiveWorkspaceByName(workspaceName)?? ActivateWorkspace(workspaceName);var insertionTarget = targetWorkspace.LastFocusedDescendant;+ // Insert the focused window into the target workspace.if (insertionTarget == null)_bus.Invoke(new AttachContainerCommand(targetWorkspace, focusedWindow));else_bus.Invoke(new AttachContainerCommand(insertionTarget.Parent as SplitContainer, focusedWindow, insertionTarget.Index + 1));- _containerService.SplitContainersToRedraw.Add(currentWorkspace);-- // Whether the current workspace is the only workspace on the monitor.- var isOnlyWorkspace = currentWorkspace.Parent.Children.Count == 1- && targetWorkspace.Parent != currentWorkspace.Parent;+ // Reassign focus to descendant within the current workspace.+ _bus.Invoke(new FocusWorkspaceCommand(currentWorkspace.Name));- // Destroy the current workspace if it's empty.- // TODO: Avoid destroying the workspace if `Workspace.KeepAlive` is enabled.- if (currentWorkspace != null && !currentWorkspace.HasChildren() && !isOnlyWorkspace)- _bus.Invoke(new DetachWorkspaceFromMonitorCommand(currentWorkspace));-- // Display the containers of the workspace to switch focus to.- _bus.Invoke(new DisplayWorkspaceCommand(targetWorkspace));+ _containerService.SplitContainersToRedraw.Add(currentWorkspace);+ _containerService.SplitContainersToRedraw.Add(targetWorkspace);_bus.Invoke(new RedrawContainersCommand());- _bus.RaiseEvent(new FocusChangedEvent(focusedWindow));return CommandResponse.Ok;}