GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat(domain): allow floating windows to be moved in `MoveFocusedWindowToWorkspaceHandler`
Lars Berger947cc5a19b0d
diff --git a/GlazeWM.Domain/Workspaces/CommandHandlers/MoveFocusedWindowToWorkspaceHandler.cs b/GlazeWM.Domain/Workspaces/CommandHandlers/MoveFocusedWindowToWorkspaceHandler.csindex 817de37d..7d697cbd 100644--- a/GlazeWM.Domain/Workspaces/CommandHandlers/MoveFocusedWindowToWorkspaceHandler.cs+++ b/GlazeWM.Domain/Workspaces/CommandHandlers/MoveFocusedWindowToWorkspaceHandler.cs@@ -4,6 +4,7 @@ using GlazeWM.Domain.Containers;using GlazeWM.Domain.Windows;using GlazeWM.Domain.Monitors;using GlazeWM.Domain.Containers.Commands;+using GlazeWM.Infrastructure.WindowsApi;namespace GlazeWM.Domain.Workspaces.CommandHandlers{@@ -30,7 +31,7 @@ namespace GlazeWM.Domain.Workspaces.CommandHandlerspublic CommandResponse Handle(MoveFocusedWindowToWorkspaceCommand command){var workspaceName = command.WorkspaceName;- var focusedWindow = _containerService.FocusedContainer as TilingWindow;+ var focusedWindow = _containerService.FocusedContainer as Window;// Ignore cases where focused container is not a window or not in foreground.if (focusedWindow == null || !_containerService.IsFocusSynced)@@ -45,6 +46,53 @@ namespace GlazeWM.Domain.Workspaces.CommandHandlersif (_monitorService.HasDpiDifference(currentWorkspace, targetWorkspace))focusedWindow.HasPendingDpiAdjustment = true;+ if (focusedWindow is FloatingWindow)+ MoveFloatingWindowToWorkspace(focusedWindow as FloatingWindow, targetWorkspace);++ else+ MoveTilingWindowToWorkspace(focusedWindow as TilingWindow, targetWorkspace);++ // Reassign focus to descendant within the current workspace.+ _bus.Invoke(new FocusWorkspaceCommand(currentWorkspace.Name));++ _containerService.ContainersToRedraw.Add(currentWorkspace);+ _containerService.ContainersToRedraw.Add(targetWorkspace);+ _bus.Invoke(new RedrawContainersCommand());++ return CommandResponse.Ok;+ }++ private void MoveFloatingWindowToWorkspace(FloatingWindow focusedWindow, Workspace targetWorkspace)+ {+ var currentWorkspace = focusedWindow.Parent;+ var currentMonitor = currentWorkspace.Parent;+ var targetMonitor = targetWorkspace.Parent;++ // If floating window is moved to a different workspace on the same monitor, there is no need+ // to adjust its position.+ if (currentMonitor != targetMonitor)+ {+ var relativeX = focusedWindow.X - currentWorkspace.X + (focusedWindow.Width / 2);+ var relativeY = focusedWindow.Y - currentWorkspace.Y + (focusedWindow.Height / 2);++ // TODO: Clean this up.+ var updatedPlacement = new WindowRect+ {+ Left = targetWorkspace.X + (relativeX * targetWorkspace.Width / currentWorkspace.Width - (focusedWindow.Width / 2)),+ Right = targetWorkspace.X + (relativeX * targetWorkspace.Width / currentWorkspace.Width - (focusedWindow.Width / 2)) + focusedWindow.Width,+ Top = targetWorkspace.Y + (relativeY * targetWorkspace.Height / currentWorkspace.Height - (focusedWindow.Height / 2)),+ Bottom = targetWorkspace.Y + (relativeY * targetWorkspace.Height / currentWorkspace.Height - (focusedWindow.Height / 2)) + focusedWindow.Height,+ };++ focusedWindow.FloatingPlacement = updatedPlacement;+ }++ // Change the window's parent workspace.+ _bus.Invoke(new MoveContainerWithinTreeCommand(focusedWindow, targetWorkspace, false));+ }++ private void MoveTilingWindowToWorkspace(TilingWindow focusedWindow, Workspace targetWorkspace)+ {var insertionTarget = targetWorkspace.LastFocusedDescendantOfType(typeof(IResizable));// Insert the focused window into the target workspace.@@ -59,15 +107,6 @@ namespace GlazeWM.Domain.Workspaces.CommandHandlerstrue));-- // Reassign focus to descendant within the current workspace.- _bus.Invoke(new FocusWorkspaceCommand(currentWorkspace.Name));-- _containerService.ContainersToRedraw.Add(currentWorkspace);- _containerService.ContainersToRedraw.Add(targetWorkspace);- _bus.Invoke(new RedrawContainersCommand());-- return CommandResponse.Ok;}/// <summary>