GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat: noop keybindings on ignored windows (#89)
lars-bergered9534cd8b43
diff --git a/GlazeWM.Domain/Containers/CommandHandlers/ChangeFocusedContainerLayoutHandler.cs b/GlazeWM.Domain/Containers/CommandHandlers/ChangeFocusedContainerLayoutHandler.csdeleted file mode 100644index 25eb9df5..00000000--- a/GlazeWM.Domain/Containers/CommandHandlers/ChangeFocusedContainerLayoutHandler.cs+++ /dev/null@@ -1,28 +0,0 @@-using GlazeWM.Domain.Containers.Commands;-using GlazeWM.Infrastructure.Bussing;--namespace GlazeWM.Domain.Containers.CommandHandlers-{- internal class ChangeFocusedContainerLayoutHandler : ICommandHandler<ChangeFocusedContainerLayoutCommand>- {- private readonly Bus _bus;- private readonly ContainerService _containerService;-- public ChangeFocusedContainerLayoutHandler(Bus bus, ContainerService containerService)- {- _bus = bus;- _containerService = containerService;- }-- public CommandResponse Handle(ChangeFocusedContainerLayoutCommand command)- {- if (!_containerService.IsFocusSynced)- return CommandResponse.Ok;-- var focusedContainer = _containerService.FocusedContainer;- _bus.Invoke(new ChangeContainerLayoutCommand(focusedContainer, command.NewLayout));-- return CommandResponse.Ok;- }- }-}diff --git a/GlazeWM.Domain/Containers/Commands/ChangeFocusedContainerLayoutCommand.cs b/GlazeWM.Domain/Containers/Commands/ChangeFocusedContainerLayoutCommand.csdeleted file mode 100644index 208f096f..00000000--- a/GlazeWM.Domain/Containers/Commands/ChangeFocusedContainerLayoutCommand.cs+++ /dev/null@@ -1,15 +0,0 @@-using GlazeWM.Domain.Common.Enums;-using GlazeWM.Infrastructure.Bussing;--namespace GlazeWM.Domain.Containers.Commands-{- public class ChangeFocusedContainerLayoutCommand : Command- {- public Layout NewLayout { get; }-- public ChangeFocusedContainerLayoutCommand(Layout newLayout)- {- NewLayout = newLayout;- }- }-}diff --git a/GlazeWM.Domain/DependencyInjection.cs b/GlazeWM.Domain/DependencyInjection.csindex da42c7a2..6b12b33f 100644--- a/GlazeWM.Domain/DependencyInjection.cs+++ b/GlazeWM.Domain/DependencyInjection.cs@@ -38,7 +38,6 @@ namespace GlazeWM.Domainservices.AddSingleton<ICommandHandler<AttachAndResizeContainerCommand>, AttachAndResizeContainerHandler>();services.AddSingleton<ICommandHandler<AttachContainerCommand>, AttachContainerHandler>();services.AddSingleton<ICommandHandler<ChangeContainerLayoutCommand>, ChangeContainerLayoutHandler>();- services.AddSingleton<ICommandHandler<ChangeFocusedContainerLayoutCommand>, ChangeFocusedContainerLayoutHandler>();services.AddSingleton<ICommandHandler<DetachAndResizeContainerCommand>, DetachAndResizeContainerHandler>();services.AddSingleton<ICommandHandler<DetachContainerCommand>, DetachContainerHandler>();services.AddSingleton<ICommandHandler<FlattenSplitContainerCommand>, FlattenSplitContainerHandler>();@@ -54,22 +53,20 @@ namespace GlazeWM.Domainservices.AddSingleton<ICommandHandler<EvaluateUserConfigCommand>, EvaluateUserConfigHandler>();services.AddSingleton<ICommandHandler<RegisterKeybindingsCommand>, RegisterKeybindingsHandler>();services.AddSingleton<ICommandHandler<AddWindowCommand>, AddWindowHandler>();- services.AddSingleton<ICommandHandler<CloseFocusedWindowCommand>, CloseFocusedWindowHandler>();+ services.AddSingleton<ICommandHandler<CloseWindowCommand>, CloseWindowHandler>();services.AddSingleton<ICommandHandler<FocusWindowCommand>, FocusWindowHandler>();- services.AddSingleton<ICommandHandler<MoveFocusedWindowCommand>, MoveFocusedWindowHandler>();+ services.AddSingleton<ICommandHandler<MoveWindowCommand>, MoveWindowHandler>();services.AddSingleton<ICommandHandler<RemoveWindowCommand>, RemoveWindowHandler>();- services.AddSingleton<ICommandHandler<ResizeFocusedWindowCommand>, ResizeFocusedWindowHandler>();- services.AddSingleton<ICommandHandler<ResizeFocusedWindowBordersCommand>, ResizeFocusedWindowBordersHandler>();+ services.AddSingleton<ICommandHandler<ResizeWindowCommand>, ResizeWindowHandler>();+ services.AddSingleton<ICommandHandler<ResizeWindowBordersCommand>, ResizeWindowBordersHandler>();services.AddSingleton<ICommandHandler<SetFloatingCommand>, SetFloatingHandler>();- services.AddSingleton<ICommandHandler<SetFocusedWindowFloatingCommand>, SetFocusedWindowFloatingHandler>();services.AddSingleton<ICommandHandler<ShowAllWindowsCommand>, ShowAllWindowsHandler>();services.AddSingleton<ICommandHandler<ToggleFloatingCommand>, ToggleFloatingHandler>();- services.AddSingleton<ICommandHandler<ToggleFocusedWindowFloatingCommand>, ToggleFocusedWindowFloatingHandler>();services.AddSingleton<ICommandHandler<ActivateWorkspaceCommand>, ActivateWorkspaceHandler>();services.AddSingleton<ICommandHandler<DeactivateWorkspaceCommand>, DeactivateWorkspaceHandler>();services.AddSingleton<ICommandHandler<DisplayWorkspaceCommand>, DisplayWorkspaceHandler>();services.AddSingleton<ICommandHandler<FocusWorkspaceCommand>, FocusWorkspaceHandler>();- services.AddSingleton<ICommandHandler<MoveFocusedWindowToWorkspaceCommand>, MoveFocusedWindowToWorkspaceHandler>();+ services.AddSingleton<ICommandHandler<MoveWindowToWorkspaceCommand>, MoveWindowToWorkspaceHandler>();services.AddSingleton<IEventHandler<DisplaySettingsChangedEvent>, DisplaySettingsChangedHandler>();services.AddSingleton<IEventHandler<WindowDestroyedEvent>, WindowDestroyedHandler>();diff --git a/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.cs b/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.csindex e9c772e8..1161e025 100644--- a/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.cs+++ b/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.cs@@ -1,3 +1,5 @@+using System.Linq;+using GlazeWM.Domain.Containers;using GlazeWM.Domain.UserConfigs.Commands;using GlazeWM.Infrastructure.Bussing;using GlazeWM.Infrastructure.WindowsApi;@@ -7,36 +9,53 @@ namespace GlazeWM.Domain.UserConfigs.CommandHandlersinternal class RegisterKeybindingsHandler : ICommandHandler<RegisterKeybindingsCommand>{private readonly Bus _bus;- private readonly KeybindingService _keybindingService;private readonly CommandParsingService _commandParsingService;+ private readonly ContainerService _containerService;+ private readonly KeybindingService _keybindingService;- public RegisterKeybindingsHandler(Bus bus, KeybindingService keybindingService, CommandParsingService commandParsingService)+ public RegisterKeybindingsHandler(+ Bus bus,+ CommandParsingService commandParsingService,+ ContainerService containerService,+ KeybindingService keybindingService+ ){_bus = bus;- _keybindingService = keybindingService;_commandParsingService = commandParsingService;+ _containerService = containerService;+ _keybindingService = keybindingService;}public CommandResponse Handle(RegisterKeybindingsCommand command){foreach (var keybindingConfig in command.Keybindings){- // Parse command strings defined in keybinding config. Calling `ToList()` is necessary here,- // otherwise parsing errors get delayed until keybinding is invoked instead of at startup.- var parsedCommands = keybindingConfig.CommandList.ConvertAll(commandString =>- {- commandString = CommandParsingService.FormatCommand(commandString);- return _commandParsingService.ParseCommand(commandString);- });+ // Format command strings defined in keybinding config.+ var formattedCommandStrings = keybindingConfig.CommandList.Select(+ commandString => CommandParsingService.FormatCommand(commandString)+ );++ foreach (var commandString in formattedCommandStrings)+ _commandParsingService.ValidateCommand(commandString);// Register all keybindings for a command sequence.foreach (var binding in keybindingConfig.BindingList)_keybindingService.AddGlobalKeybinding(binding, () =>{- // Invoke commands in sequence on keybinding press. Use `dynamic` to resolve the- // command type at runtime and allow multiple dispatch.- foreach (var parsedCommand in parsedCommands)+ // Avoid invoking keybinding if focus is not synced (eg. if an unmanaged window has+ // focus).+ if (!_containerService.IsFocusSynced)+ return;++ // Invoke commands in sequence on keybinding press.+ foreach (var commandString in formattedCommandStrings)+ {+ var subjectContainer = _containerService.FocusedContainer;++ // Use `dynamic` to resolve the command type at runtime and allow multiple dispatch.+ var parsedCommand = _commandParsingService.ParseCommand(commandString, subjectContainer);_bus.Invoke((dynamic)parsedCommand);+ }});}diff --git a/GlazeWM.Domain/UserConfigs/CommandParsingService.cs b/GlazeWM.Domain/UserConfigs/CommandParsingService.csindex 407f8dfc..624ad800 100644--- a/GlazeWM.Domain/UserConfigs/CommandParsingService.cs+++ b/GlazeWM.Domain/UserConfigs/CommandParsingService.cs@@ -3,10 +3,13 @@ using System.Linq;using System.Text.RegularExpressions;using GlazeWM.Domain.Common.Commands;using GlazeWM.Domain.Common.Enums;+using GlazeWM.Domain.Containers;using GlazeWM.Domain.Containers.Commands;+using GlazeWM.Domain.Windows;using GlazeWM.Domain.Windows.Commands;using GlazeWM.Domain.Workspaces.Commands;using GlazeWM.Infrastructure.Bussing;+using GlazeWM.Infrastructure.Bussing.Commands;using GlazeWM.Infrastructure.Exceptions;using GlazeWM.Infrastructure.Utils;using GlazeWM.Infrastructure.WindowsApi;@@ -29,24 +32,11 @@ namespace GlazeWM.Domain.UserConfigsreturn multipleSpacesRegex.Replace(formattedCommandString, " ");}- public Command ParseCommand(string commandString)+ public void ValidateCommand(string commandString){try{- var commandParts = commandString.Split(" ");-- return commandParts[0] switch- {- "layout" => ParseLayoutCommand(commandParts),- "focus" => ParseFocusCommand(commandParts),- "move" => ParseMoveCommand(commandParts),- "resize" => ParseResizeCommand(commandParts),- "set" => ParseSetCommand(commandParts),- "toggle" => ParseToggleCommand(commandParts),- "exit" => ParseExitCommand(commandParts),- "close" => new CloseFocusedWindowCommand(),- _ => throw new ArgumentException(null, nameof(commandString)),- };+ ParseCommand(commandString, null);}catch{@@ -54,12 +44,32 @@ namespace GlazeWM.Domain.UserConfigs}}- private static Command ParseLayoutCommand(string[] commandParts)+ public Command ParseCommand(string commandString, Container subjectContainer)+ {+ var commandParts = commandString.Split(" ");++ return commandParts[0] switch+ {+ "layout" => ParseLayoutCommand(commandParts, subjectContainer),+ "focus" => ParseFocusCommand(commandParts),+ "move" => ParseMoveCommand(commandParts, subjectContainer),+ "resize" => ParseResizeCommand(commandParts, subjectContainer),+ "set" => ParseSetCommand(commandParts, subjectContainer),+ "toggle" => ParseToggleCommand(commandParts, subjectContainer),+ "exit" => ParseExitCommand(commandParts),+ "close" => subjectContainer is Window+ ? new CloseWindowCommand(subjectContainer as Window)+ : new NoopCommand(),+ _ => throw new ArgumentException(null, nameof(commandString)),+ };+ }++ private static Command ParseLayoutCommand(string[] commandParts, Container subjectContainer){return commandParts[1] switch{- "vertical" => new ChangeFocusedContainerLayoutCommand(Layout.VERTICAL),- "horizontal" => new ChangeFocusedContainerLayoutCommand(Layout.HORIZONTAL),+ "vertical" => new ChangeContainerLayoutCommand(subjectContainer, Layout.VERTICAL),+ "horizontal" => new ChangeContainerLayoutCommand(subjectContainer, Layout.HORIZONTAL),_ => throw new ArgumentException(null, nameof(commandParts)),};}@@ -72,51 +82,73 @@ namespace GlazeWM.Domain.UserConfigs"right" => new FocusInDirectionCommand(Direction.RIGHT),"up" => new FocusInDirectionCommand(Direction.UP),"down" => new FocusInDirectionCommand(Direction.DOWN),- "workspace" => new FocusWorkspaceCommand(ValidateWorkspaceName(commandParts[2])),+ "workspace" when IsValidWorkspace(commandParts[2]) =>+ new FocusWorkspaceCommand(commandParts[2]),_ => throw new ArgumentException(null, nameof(commandParts)),};}- private Command ParseMoveCommand(string[] commandParts)+ private Command ParseMoveCommand(string[] commandParts, Container subjectContainer){return commandParts[1] switch{- "left" => new MoveFocusedWindowCommand(Direction.LEFT),- "right" => new MoveFocusedWindowCommand(Direction.RIGHT),- "up" => new MoveFocusedWindowCommand(Direction.UP),- "down" => new MoveFocusedWindowCommand(Direction.DOWN),- "to" => new MoveFocusedWindowToWorkspaceCommand(ValidateWorkspaceName(commandParts[3])),+ "left" => subjectContainer is Window+ ? new MoveWindowCommand(subjectContainer as Window, Direction.LEFT)+ : new NoopCommand(),+ "right" => subjectContainer is Window+ ? new MoveWindowCommand(subjectContainer as Window, Direction.RIGHT)+ : new NoopCommand(),+ "up" => subjectContainer is Window+ ? new MoveWindowCommand(subjectContainer as Window, Direction.UP)+ : new NoopCommand(),+ "down" => subjectContainer is Window+ ? new MoveWindowCommand(subjectContainer as Window, Direction.DOWN)+ : new NoopCommand(),+ "to" when IsValidWorkspace(commandParts[3]) => subjectContainer is Window+ ? new MoveWindowToWorkspaceCommand(subjectContainer as Window, commandParts[3])+ : new NoopCommand(),_ => throw new ArgumentException(null, nameof(commandParts)),};}- private static Command ParseResizeCommand(string[] commandParts)+ private static Command ParseResizeCommand(string[] commandParts, Container subjectContainer){return commandParts[1] switch{- "height" => new ResizeFocusedWindowCommand(ResizeDimension.HEIGHT, commandParts[2]),- "width" => new ResizeFocusedWindowCommand(ResizeDimension.WIDTH, commandParts[2]),- "borders" => new ResizeFocusedWindowBordersCommand(- ShorthandToRectDelta(string.Join(" ", commandParts[2..]))- ),+ "height" => subjectContainer is Window+ ? new ResizeWindowCommand(subjectContainer as Window, ResizeDimension.HEIGHT, commandParts[2])+ : new NoopCommand(),+ "width" => subjectContainer is Window+ ? new ResizeWindowCommand(subjectContainer as Window, ResizeDimension.WIDTH, commandParts[2])+ : new NoopCommand(),+ "borders" => subjectContainer is Window+ ? new ResizeWindowBordersCommand(+ subjectContainer as Window,+ ShorthandToRectDelta(string.Join(" ", commandParts[2..]))+ )+ : new NoopCommand(),_ => throw new ArgumentException(null, nameof(commandParts)),};}- private static Command ParseSetCommand(string[] commandParts)+ private static Command ParseSetCommand(string[] commandParts, Container subjectContainer){return commandParts[1] switch{- "floating" => new SetFocusedWindowFloatingCommand(),+ "floating" => subjectContainer is Window+ ? new SetFloatingCommand(subjectContainer as Window)+ : new NoopCommand(),_ => throw new ArgumentException(null, nameof(commandParts)),};}- private static Command ParseToggleCommand(string[] commandParts)+ private static Command ParseToggleCommand(string[] commandParts, Container subjectContainer){return commandParts[1] switch{- "floating" => new ToggleFocusedWindowFloatingCommand(),+ "floating" => subjectContainer is Window+ ? new ToggleFloatingCommand(subjectContainer as Window)+ : new NoopCommand(),"focus" => commandParts[2] switch{"mode" => new ToggleFocusModeCommand(),@@ -136,18 +168,12 @@ namespace GlazeWM.Domain.UserConfigs}/// <summary>- /// Checks whether a workspace exists with the given name.+ /// Whether a workspace exists with the given name./// </summary>- /// <returns>The workspace name if valid.</returns>- /// <exception cref="ArgumentException"></exception>- private string ValidateWorkspaceName(string workspaceName)+ private bool IsValidWorkspace(string workspaceName){var workspaceConfig = _userConfigService.GetWorkspaceConfigByName(workspaceName);-- if (workspaceConfig == null)- throw new ArgumentException(null, nameof(workspaceName));-- return workspaceName;+ return workspaceConfig is not null;}private static RectDelta ShorthandToRectDelta(string shorthand)diff --git a/GlazeWM.Domain/Windows/CommandHandlers/AddWindowHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/AddWindowHandler.csindex cd528200..47c928fb 100644--- a/GlazeWM.Domain/Windows/CommandHandlers/AddWindowHandler.cs+++ b/GlazeWM.Domain/Windows/CommandHandlers/AddWindowHandler.cs@@ -94,7 +94,7 @@ namespace GlazeWM.Domain.Windows.CommandHandlers_bus.Invoke(new FocusWindowCommand(window));var parsedCommands = commandStrings- .Select(commandString => _commandParsingService.ParseCommand(commandString))+ .Select(commandString => _commandParsingService.ParseCommand(commandString, window)).ToList();// Invoke commands in the matching window rules. Use `dynamic` to resolve the command typediff --git a/GlazeWM.Domain/Windows/CommandHandlers/CloseFocusedWindowHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/CloseFocusedWindowHandler.csdeleted file mode 100644index 8290d6b1..00000000--- a/GlazeWM.Domain/Windows/CommandHandlers/CloseFocusedWindowHandler.cs+++ /dev/null@@ -1,31 +0,0 @@-using System;-using GlazeWM.Domain.Containers;-using GlazeWM.Domain.Windows.Commands;-using GlazeWM.Infrastructure.Bussing;-using static GlazeWM.Infrastructure.WindowsApi.WindowsApiService;--namespace GlazeWM.Domain.Windows.CommandHandlers-{- internal class CloseFocusedWindowHandler : ICommandHandler<CloseFocusedWindowCommand>- {- private readonly ContainerService _containerService;-- public CloseFocusedWindowHandler(ContainerService containerService)- {- _containerService = containerService;- }-- public CommandResponse Handle(CloseFocusedWindowCommand command)- {- var focusedWindow = _containerService.FocusedContainer as Window;-- // Ignore cases where focused container is not a window or not in foreground.- if (focusedWindow is null || !_containerService.IsFocusSynced)- return CommandResponse.Ok;-- SendMessage(focusedWindow.Hwnd, SendMessageType.WM_CLOSE, IntPtr.Zero, IntPtr.Zero);-- return CommandResponse.Ok;- }- }-}diff --git a/GlazeWM.Domain/Windows/CommandHandlers/CloseWindowHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/CloseWindowHandler.csnew file mode 100644index 00000000..4dbec608--- /dev/null+++ b/GlazeWM.Domain/Windows/CommandHandlers/CloseWindowHandler.cs@@ -0,0 +1,19 @@+using System;+using GlazeWM.Domain.Windows.Commands;+using GlazeWM.Infrastructure.Bussing;+using static GlazeWM.Infrastructure.WindowsApi.WindowsApiService;++namespace GlazeWM.Domain.Windows.CommandHandlers+{+ internal class CloseWindowHandler : ICommandHandler<CloseWindowCommand>+ {+ public CommandResponse Handle(CloseWindowCommand command)+ {+ var windowToClose = command.WindowToClose;++ SendMessage(windowToClose.Hwnd, SendMessageType.WM_CLOSE, IntPtr.Zero, IntPtr.Zero);++ return CommandResponse.Ok;+ }+ }+}diff --git a/GlazeWM.Domain/Windows/CommandHandlers/MoveFocusedWindowHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/MoveWindowHandler.cssimilarity index 52%rename from GlazeWM.Domain/Windows/CommandHandlers/MoveFocusedWindowHandler.csrename to GlazeWM.Domain/Windows/CommandHandlers/MoveWindowHandler.csindex 93de62d5..55f7efed 100644--- a/GlazeWM.Domain/Windows/CommandHandlers/MoveFocusedWindowHandler.cs+++ b/GlazeWM.Domain/Windows/CommandHandlers/MoveWindowHandler.cs@@ -10,13 +10,13 @@ using GlazeWM.Infrastructure.Bussing;namespace GlazeWM.Domain.Windows.CommandHandlers{- internal class MoveFocusedWindowHandler : ICommandHandler<MoveFocusedWindowCommand>+ internal class MoveWindowHandler : ICommandHandler<MoveWindowCommand>{private readonly Bus _bus;private readonly ContainerService _containerService;private readonly MonitorService _monitorService;- public MoveFocusedWindowHandler(+ public MoveWindowHandler(Bus bus,ContainerService containerService,MonitorService monitorService@@ -27,67 +27,68 @@ namespace GlazeWM.Domain.Windows.CommandHandlers_monitorService = monitorService;}- public CommandResponse Handle(MoveFocusedWindowCommand command)+ public CommandResponse Handle(MoveWindowCommand command){- var focusedWindow = _containerService.FocusedContainer as TilingWindow;+ var windowToMove = command.WindowToMove as TilingWindow;+ var direction = command.Direction;- // Ignore cases where focused container is not a tiling window.- if (focusedWindow is null)+ // Ignore cases where window is not tiling.+ if (windowToMove is null)return CommandResponse.Ok;- var direction = command.Direction;var layoutForDirection = direction.GetCorrespondingLayout();- var parentMatchesLayout = (focusedWindow.Parent as SplitContainer).Layout == direction.GetCorrespondingLayout();+ var parentMatchesLayout =+ (windowToMove.Parent as SplitContainer).Layout == direction.GetCorrespondingLayout();- if (parentMatchesLayout && HasSiblingInDirection(focusedWindow, direction))+ if (parentMatchesLayout && HasSiblingInDirection(windowToMove, direction)){- SwapSiblingContainers(focusedWindow, direction);+ SwapSiblingContainers(windowToMove, direction);return CommandResponse.Ok;}- // Attempt to the move focused window to workspace in given direction.- if (parentMatchesLayout && focusedWindow.Parent is Workspace)+ // Attempt to the move window to workspace in given direction.+ if (parentMatchesLayout && windowToMove.Parent is Workspace){- MoveToWorkspaceInDirection(focusedWindow, direction);+ MoveToWorkspaceInDirection(windowToMove, direction);return CommandResponse.Ok;}- // The focused window cannot be moved within the parent container, so traverse upwards to find- // a suitable ancestor to move to.- var ancestorWithLayout = focusedWindow.Parent.Ancestors.FirstOrDefault(+ // The window cannot be moved within the parent container, so traverse upwards to find a+ // suitable ancestor to move to.+ var ancestorWithLayout = windowToMove.Parent.Ancestors.FirstOrDefault(container => (container as SplitContainer)?.Layout == layoutForDirection) as SplitContainer;// Change the layout of the workspace to layout for direction.if (ancestorWithLayout == null){- ChangeWorkspaceLayout(focusedWindow, direction);+ ChangeWorkspaceLayout(windowToMove, direction);return CommandResponse.Ok;}- InsertIntoAncestor(focusedWindow, direction, ancestorWithLayout);+ InsertIntoAncestor(windowToMove, direction, ancestorWithLayout);return CommandResponse.Ok;}/// <summary>- /// Whether the focused window has a tiling sibling in the given direction.+ /// Whether the window has a tiling sibling in the given direction./// </summary>- private static bool HasSiblingInDirection(Window focusedWindow, Direction direction)+ private static bool HasSiblingInDirection(Window windowToMove, Direction direction){if (direction is Direction.UP or Direction.LEFT)- return focusedWindow != focusedWindow.SelfAndSiblingsOfType(typeof(IResizable)).First();+ return windowToMove != windowToMove.SelfAndSiblingsOfType(typeof(IResizable)).First();- return focusedWindow != focusedWindow.SelfAndSiblingsOfType(typeof(IResizable)).Last();+ return windowToMove != windowToMove.SelfAndSiblingsOfType(typeof(IResizable)).Last();}- private void SwapSiblingContainers(Window focusedWindow, Direction direction)+ private void SwapSiblingContainers(Window windowToMove, Direction direction){var siblingInDirection = direction is Direction.UP or Direction.LEFT- ? focusedWindow.GetPreviousSiblingOfType(typeof(IResizable))- : focusedWindow.GetNextSiblingOfType(typeof(IResizable));+ ? windowToMove.GetPreviousSiblingOfType(typeof(IResizable))+ : windowToMove.GetNextSiblingOfType(typeof(IResizable));- // Swap the focused window with sibling in given direction.+ // Swap the window with sibling in given direction.if (siblingInDirection is Window){var targetIndex = direction is Direction.UP or Direction.LEFT ?@@ -95,8 +96,8 @@ namespace GlazeWM.Domain.Windows.CommandHandlers_bus.Invoke(new MoveContainerWithinTreeCommand(- focusedWindow,- focusedWindow.Parent,+ windowToMove,+ windowToMove.Parent,targetIndex,false)@@ -106,66 +107,73 @@ namespace GlazeWM.Domain.Windows.CommandHandlersreturn;}- // Move the focused window into the sibling split container.- var targetDescendant = _containerService.GetDescendantInDirection(siblingInDirection, direction.Inverse());+ // Move the window into the sibling split container.+ var targetDescendant = _containerService.GetDescendantInDirection(+ siblingInDirection,+ direction.Inverse()+ );var targetParent = targetDescendant.Parent as SplitContainer;var layoutForDirection = direction.GetCorrespondingLayout();var insertionIndex = targetParent.Layout != layoutForDirection || direction == Direction.UP ||direction == Direction.LEFT ? targetDescendant.Index + 1 : targetDescendant.Index;- _bus.Invoke(new MoveContainerWithinTreeCommand(focusedWindow, targetParent, insertionIndex, true));+ _bus.Invoke(new MoveContainerWithinTreeCommand(windowToMove, targetParent, insertionIndex, true));_bus.Invoke(new RedrawContainersCommand());}- private void MoveToWorkspaceInDirection(Window focusedWindow, Direction direction)+ private void MoveToWorkspaceInDirection(Window windowToMove, Direction direction){- var focusedMonitor = _monitorService.GetFocusedMonitor();- var monitorInDirection = _monitorService.GetMonitorInDirection(direction, focusedMonitor);+ var monitor = MonitorService.GetMonitorFromChildContainer(windowToMove);+ var monitorInDirection = _monitorService.GetMonitorInDirection(direction, monitor);var workspaceInDirection = monitorInDirection?.DisplayedWorkspace;if (workspaceInDirection == null)return;// Since window is crossing monitors, adjustments might need to be made because of DPI.- if (MonitorService.HasDpiDifference(focusedWindow, workspaceInDirection))- focusedWindow.HasPendingDpiAdjustment = true;+ if (MonitorService.HasDpiDifference(windowToMove, workspaceInDirection))+ windowToMove.HasPendingDpiAdjustment = true;// Update floating placement since the window has to cross monitors.- focusedWindow.FloatingPlacement =- focusedWindow.FloatingPlacement.TranslateToCenter(workspaceInDirection.ToRectangle());+ windowToMove.FloatingPlacement =+ windowToMove.FloatingPlacement.TranslateToCenter(workspaceInDirection.ToRectangle());// TODO: Descend into container if possible.if (direction is Direction.UP or Direction.LEFT)- _bus.Invoke(new MoveContainerWithinTreeCommand(focusedWindow, workspaceInDirection, true));+ _bus.Invoke(new MoveContainerWithinTreeCommand(windowToMove, workspaceInDirection, true));else- _bus.Invoke(new MoveContainerWithinTreeCommand(focusedWindow, workspaceInDirection, 0, true));+ _bus.Invoke(new MoveContainerWithinTreeCommand(windowToMove, workspaceInDirection, 0, true));_bus.Invoke(new RedrawContainersCommand());// Refresh state in bar of which workspace has focus.- _bus.RaiseEvent(new FocusChangedEvent(focusedWindow));+ _bus.RaiseEvent(new FocusChangedEvent(windowToMove));}- private void ChangeWorkspaceLayout(Window focusedWindow, Direction direction)+ private void ChangeWorkspaceLayout(Window windowToMove, Direction direction){- var workspace = WorkspaceService.GetWorkspaceFromChildContainer(focusedWindow);+ var workspace = WorkspaceService.GetWorkspaceFromChildContainer(windowToMove);var layoutForDirection = direction.GetCorrespondingLayout();_bus.Invoke(new ChangeContainerLayoutCommand(workspace, layoutForDirection));// TODO: Should probably descend into sibling if possible.- if (HasSiblingInDirection(focusedWindow, direction))- SwapSiblingContainers(focusedWindow, direction);+ if (HasSiblingInDirection(windowToMove, direction))+ SwapSiblingContainers(windowToMove, direction);_bus.Invoke(new RedrawContainersCommand());}- private void InsertIntoAncestor(TilingWindow focusedWindow, Direction direction, Container ancestorWithLayout)+ private void InsertIntoAncestor(+ TilingWindow windowToMove,+ Direction direction,+ Container ancestorWithLayout+ ){- // Traverse up from `focusedWindow` to find container where the parent is `ancestorWithLayout`. Then,- // depending on the direction, insert before or after that container.- var insertionReference = focusedWindow.Ancestors+ // Traverse up from `windowToMove` to find container where the parent is `ancestorWithLayout`.+ // Then, depending on the direction, insert before or after that container.+ var insertionReference = windowToMove.Ancestors.FirstOrDefault(container => container.Parent == ancestorWithLayout);var insertionReferenceSibling = direction is Direction.UP or Direction.LEFT@@ -174,23 +182,26 @@ namespace GlazeWM.Domain.Windows.CommandHandlersif (insertionReferenceSibling is SplitContainer){- // Move the focused window into the adjacent split container.- var targetDescendant = _containerService.GetDescendantInDirection(insertionReferenceSibling, direction.Inverse());+ // Move the window into the adjacent split container.+ var targetDescendant = _containerService.GetDescendantInDirection(+ insertionReferenceSibling,+ direction.Inverse()+ );var targetParent = targetDescendant.Parent as SplitContainer;var layoutForDirection = direction.GetCorrespondingLayout();var insertionIndex = targetParent.Layout != layoutForDirection || direction == Direction.UP ||direction == Direction.LEFT ? targetDescendant.Index + 1 : targetDescendant.Index;- _bus.Invoke(new MoveContainerWithinTreeCommand(focusedWindow, targetParent, insertionIndex, true));+ _bus.Invoke(new MoveContainerWithinTreeCommand(windowToMove, targetParent, insertionIndex, true));}else{- // Move the focused window into the container above.+ // Move the window into the container above.var insertionIndex = (direction is Direction.UP or Direction.LEFT) ?insertionReference.Index : insertionReference.Index + 1;- _bus.Invoke(new MoveContainerWithinTreeCommand(focusedWindow, ancestorWithLayout, insertionIndex, true));+ _bus.Invoke(new MoveContainerWithinTreeCommand(windowToMove, ancestorWithLayout, insertionIndex, true));}_bus.Invoke(new RedrawContainersCommand());diff --git a/GlazeWM.Domain/Windows/CommandHandlers/ResizeFocusedWindowBordersHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/ResizeFocusedWindowBordersHandler.csdeleted file mode 100644index d5e2e958..00000000--- a/GlazeWM.Domain/Windows/CommandHandlers/ResizeFocusedWindowBordersHandler.cs+++ /dev/null@@ -1,47 +0,0 @@-using GlazeWM.Domain.Containers;-using GlazeWM.Domain.Containers.Commands;-using GlazeWM.Domain.Windows.Commands;-using GlazeWM.Infrastructure.Bussing;-using GlazeWM.Infrastructure.WindowsApi;--namespace GlazeWM.Domain.Windows.CommandHandlers-{- internal class ResizeFocusedWindowBordersHandler : ICommandHandler<ResizeFocusedWindowBordersCommand>- {- private readonly Bus _bus;- private readonly ContainerService _containerService;-- public ResizeFocusedWindowBordersHandler(Bus bus, ContainerService containerService)- {- _bus = bus;- _containerService = containerService;- }-- public CommandResponse Handle(ResizeFocusedWindowBordersCommand command)- {- var borderDelta = command.BorderDelta;- var focusedWindow = _containerService.FocusedContainer as Window;-- // Ignore cases where focused container is not a window.- if (focusedWindow == null)- return CommandResponse.Ok;-- // Adjust the existing border delta of the window.- focusedWindow.BorderDelta = new RectDelta(- focusedWindow.BorderDelta.DeltaLeft + borderDelta.DeltaLeft,- focusedWindow.BorderDelta.DeltaTop + borderDelta.DeltaTop,- focusedWindow.BorderDelta.DeltaRight + borderDelta.DeltaRight,- focusedWindow.BorderDelta.DeltaBottom + borderDelta.DeltaBottom- );-- if (focusedWindow is not TilingWindow)- return CommandResponse.Ok;-- // Only redraw the window if it's tiling.- _containerService.ContainersToRedraw.Add(focusedWindow);- _bus.Invoke(new RedrawContainersCommand());-- return CommandResponse.Ok;- }- }-}diff --git a/GlazeWM.Domain/Windows/CommandHandlers/ResizeWindowBordersHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/ResizeWindowBordersHandler.csnew file mode 100644index 00000000..d63fe06c--- /dev/null+++ b/GlazeWM.Domain/Windows/CommandHandlers/ResizeWindowBordersHandler.cs@@ -0,0 +1,43 @@+using GlazeWM.Domain.Containers;+using GlazeWM.Domain.Containers.Commands;+using GlazeWM.Domain.Windows.Commands;+using GlazeWM.Infrastructure.Bussing;+using GlazeWM.Infrastructure.WindowsApi;++namespace GlazeWM.Domain.Windows.CommandHandlers+{+ internal class ResizeWindowBordersHandler : ICommandHandler<ResizeWindowBordersCommand>+ {+ private readonly Bus _bus;+ private readonly ContainerService _containerService;++ public ResizeWindowBordersHandler(Bus bus, ContainerService containerService)+ {+ _bus = bus;+ _containerService = containerService;+ }++ public CommandResponse Handle(ResizeWindowBordersCommand command)+ {+ var borderDelta = command.BorderDelta;+ var windowToResize = command.WindowToResize;++ // Adjust the existing border delta of the window.+ windowToResize.BorderDelta = new RectDelta(+ windowToResize.BorderDelta.DeltaLeft + borderDelta.DeltaLeft,+ windowToResize.BorderDelta.DeltaTop + borderDelta.DeltaTop,+ windowToResize.BorderDelta.DeltaRight + borderDelta.DeltaRight,+ windowToResize.BorderDelta.DeltaBottom + borderDelta.DeltaBottom+ );++ if (windowToResize is not TilingWindow)+ return CommandResponse.Ok;++ // Only redraw the window if it's tiling.+ _containerService.ContainersToRedraw.Add(windowToResize);+ _bus.Invoke(new RedrawContainersCommand());++ return CommandResponse.Ok;+ }+ }+}diff --git a/GlazeWM.Domain/Windows/CommandHandlers/ResizeFocusedWindowHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/ResizeWindowHandler.cssimilarity index 78%rename from GlazeWM.Domain/Windows/CommandHandlers/ResizeFocusedWindowHandler.csrename to GlazeWM.Domain/Windows/CommandHandlers/ResizeWindowHandler.csindex 1b741464..c592bcec 100644--- a/GlazeWM.Domain/Windows/CommandHandlers/ResizeFocusedWindowHandler.cs+++ b/GlazeWM.Domain/Windows/CommandHandlers/ResizeWindowHandler.cs@@ -12,36 +12,35 @@ using GlazeWM.Infrastructure.Exceptions;namespace GlazeWM.Domain.Windows.CommandHandlers{- internal class ResizeFocusedWindowHandler : ICommandHandler<ResizeFocusedWindowCommand>+ internal class ResizeWindowHandler : ICommandHandler<ResizeWindowCommand>{private readonly Bus _bus;private readonly ContainerService _containerService;- public ResizeFocusedWindowHandler(Bus bus, ContainerService containerService)+ public ResizeWindowHandler(Bus bus, ContainerService containerService){_bus = bus;_containerService = containerService;}- public CommandResponse Handle(ResizeFocusedWindowCommand command)+ public CommandResponse Handle(ResizeWindowCommand command){var dimensionToResize = command.DimensionToResize;var resizeAmount = command.ResizeAmount;- var focusedWindow = _containerService.FocusedContainer as TilingWindow;+ var windowToResize = command.WindowToResize;- // Ignore cases where focused container is not a tiling window.- if (focusedWindow is null)+ // Ignore cases where window is not tiling.+ if (windowToResize is not TilingWindow)return CommandResponse.Ok;- var layout = (focusedWindow.Parent as SplitContainer).Layout;+ var layout = (windowToResize.Parent as SplitContainer).Layout;- // Get whether the parent of the focused window should be resized rather than the focused- // window itself.+ // Get whether the parent of the window should be resized rather than the window itself.var shouldResizeParent =(layout == Layout.HORIZONTAL && dimensionToResize == ResizeDimension.HEIGHT)|| (layout == Layout.VERTICAL && dimensionToResize == ResizeDimension.WIDTH);- var containerToResize = shouldResizeParent ? focusedWindow.Parent : focusedWindow;+ var containerToResize = shouldResizeParent ? windowToResize.Parent : windowToResize;// Get siblings that can be resized.var resizableSiblings = containerToResize.Siblings.Where(container => container is IResizable);diff --git a/GlazeWM.Domain/Windows/CommandHandlers/SetFocusedWindowFloatingHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/SetFocusedWindowFloatingHandler.csdeleted file mode 100644index dbacac4b..00000000--- a/GlazeWM.Domain/Windows/CommandHandlers/SetFocusedWindowFloatingHandler.cs+++ /dev/null@@ -1,31 +0,0 @@-using GlazeWM.Domain.Containers;-using GlazeWM.Domain.Windows.Commands;-using GlazeWM.Infrastructure.Bussing;--namespace GlazeWM.Domain.Windows.CommandHandlers-{- internal class SetFocusedWindowFloatingHandler : ICommandHandler<SetFocusedWindowFloatingCommand>- {- private readonly Bus _bus;- private readonly ContainerService _containerService;-- public SetFocusedWindowFloatingHandler(Bus bus, ContainerService containerService)- {- _bus = bus;- _containerService = containerService;- }-- public CommandResponse Handle(SetFocusedWindowFloatingCommand command)- {- var focusedWindow = _containerService.FocusedContainer as Window;-- // Ignore cases where focused container is not a window or not in foreground.- if (focusedWindow == null || !_containerService.IsFocusSynced)- return CommandResponse.Ok;-- _bus.Invoke(new SetFloatingCommand(focusedWindow));-- return CommandResponse.Ok;- }- }-}diff --git a/GlazeWM.Domain/Windows/CommandHandlers/ToggleFocusedWindowFloatingHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/ToggleFocusedWindowFloatingHandler.csdeleted file mode 100644index 0f4c0dbc..00000000--- a/GlazeWM.Domain/Windows/CommandHandlers/ToggleFocusedWindowFloatingHandler.cs+++ /dev/null@@ -1,31 +0,0 @@-using GlazeWM.Domain.Containers;-using GlazeWM.Domain.Windows.Commands;-using GlazeWM.Infrastructure.Bussing;--namespace GlazeWM.Domain.Windows.CommandHandlers-{- internal class ToggleFocusedWindowFloatingHandler : ICommandHandler<ToggleFocusedWindowFloatingCommand>- {- private readonly Bus _bus;- private readonly ContainerService _containerService;-- public ToggleFocusedWindowFloatingHandler(Bus bus, ContainerService containerService)- {- _bus = bus;- _containerService = containerService;- }-- public CommandResponse Handle(ToggleFocusedWindowFloatingCommand command)- {- var focusedWindow = _containerService.FocusedContainer as Window;-- // Ignore cases where focused container is not a window or not in foreground.- if (focusedWindow is null || !_containerService.IsFocusSynced)- return CommandResponse.Ok;-- _bus.Invoke(new ToggleFloatingCommand(focusedWindow));-- return CommandResponse.Ok;- }- }-}diff --git a/GlazeWM.Domain/Windows/Commands/CloseFocusedWindowCommand.cs b/GlazeWM.Domain/Windows/Commands/CloseFocusedWindowCommand.csdeleted file mode 100644index 0d6cb6d4..00000000--- a/GlazeWM.Domain/Windows/Commands/CloseFocusedWindowCommand.cs+++ /dev/null@@ -1,8 +0,0 @@-using GlazeWM.Infrastructure.Bussing;--namespace GlazeWM.Domain.Windows.Commands-{- public class CloseFocusedWindowCommand : Command- {- }-}diff --git a/GlazeWM.Domain/Windows/Commands/CloseWindowCommand.cs b/GlazeWM.Domain/Windows/Commands/CloseWindowCommand.csnew file mode 100644index 00000000..c599dc42--- /dev/null+++ b/GlazeWM.Domain/Windows/Commands/CloseWindowCommand.cs@@ -0,0 +1,14 @@+using GlazeWM.Infrastructure.Bussing;++namespace GlazeWM.Domain.Windows.Commands+{+ public class CloseWindowCommand : Command+ {+ public Window WindowToClose { get; }++ public CloseWindowCommand(Window windowToClose)+ {+ WindowToClose = windowToClose;+ }+ }+}diff --git a/GlazeWM.Domain/Windows/Commands/MoveFocusedWindowCommand.cs b/GlazeWM.Domain/Windows/Commands/MoveWindowCommand.cssimilarity index 52%rename from GlazeWM.Domain/Windows/Commands/MoveFocusedWindowCommand.csrename to GlazeWM.Domain/Windows/Commands/MoveWindowCommand.csindex 15392a57..6d5895a5 100644--- a/GlazeWM.Domain/Windows/Commands/MoveFocusedWindowCommand.cs+++ b/GlazeWM.Domain/Windows/Commands/MoveWindowCommand.cs@@ -3,12 +3,14 @@ using GlazeWM.Infrastructure.Bussing;namespace GlazeWM.Domain.Windows.Commands{- public class MoveFocusedWindowCommand : Command+ public class MoveWindowCommand : Command{+ public Window WindowToMove { get; }public Direction Direction { get; }- public MoveFocusedWindowCommand(Direction direction)+ public MoveWindowCommand(Window windowToMove, Direction direction){+ WindowToMove = windowToMove;Direction = direction;}}diff --git a/GlazeWM.Domain/Windows/Commands/ResizeFocusedWindowBordersCommand.cs b/GlazeWM.Domain/Windows/Commands/ResizeWindowBordersCommand.cssimilarity index 50%rename from GlazeWM.Domain/Windows/Commands/ResizeFocusedWindowBordersCommand.csrename to GlazeWM.Domain/Windows/Commands/ResizeWindowBordersCommand.csindex 2be2927a..b263c07c 100644--- a/GlazeWM.Domain/Windows/Commands/ResizeFocusedWindowBordersCommand.cs+++ b/GlazeWM.Domain/Windows/Commands/ResizeWindowBordersCommand.cs@@ -3,12 +3,14 @@ using GlazeWM.Infrastructure.WindowsApi;namespace GlazeWM.Domain.Windows.Commands{- public class ResizeFocusedWindowBordersCommand : Command+ public class ResizeWindowBordersCommand : Command{+ public Window WindowToResize { get; }public RectDelta BorderDelta { get; }- public ResizeFocusedWindowBordersCommand(RectDelta borderDelta)+ public ResizeWindowBordersCommand(Window windowToResize, RectDelta borderDelta){+ WindowToResize = windowToResize;BorderDelta = borderDelta;}}diff --git a/GlazeWM.Domain/Windows/Commands/ResizeFocusedWindowCommand.cs b/GlazeWM.Domain/Windows/Commands/ResizeWindowCommand.cssimilarity index 55%rename from GlazeWM.Domain/Windows/Commands/ResizeFocusedWindowCommand.csrename to GlazeWM.Domain/Windows/Commands/ResizeWindowCommand.csindex b8f13ad6..4ca7057a 100644--- a/GlazeWM.Domain/Windows/Commands/ResizeFocusedWindowCommand.cs+++ b/GlazeWM.Domain/Windows/Commands/ResizeWindowCommand.cs@@ -3,13 +3,19 @@ using GlazeWM.Infrastructure.Bussing;namespace GlazeWM.Domain.Windows.Commands{- public class ResizeFocusedWindowCommand : Command+ public class ResizeWindowCommand : Command{+ public Window WindowToResize { get; }public ResizeDimension DimensionToResize { get; }public string ResizeAmount { get; }- public ResizeFocusedWindowCommand(ResizeDimension dimensionToResize, string resizeAmount)+ public ResizeWindowCommand(+ Window windowToResize,+ ResizeDimension dimensionToResize,+ string resizeAmount+ ){+ WindowToResize = windowToResize;DimensionToResize = dimensionToResize;ResizeAmount = resizeAmount;}diff --git a/GlazeWM.Domain/Windows/Commands/SetFocusedWindowFloatingCommand.cs b/GlazeWM.Domain/Windows/Commands/SetFocusedWindowFloatingCommand.csdeleted file mode 100644index 41650b45..00000000--- a/GlazeWM.Domain/Windows/Commands/SetFocusedWindowFloatingCommand.cs+++ /dev/null@@ -1,8 +0,0 @@-using GlazeWM.Infrastructure.Bussing;--namespace GlazeWM.Domain.Windows.Commands-{- public class SetFocusedWindowFloatingCommand : Command- {- }-}diff --git a/GlazeWM.Domain/Windows/Commands/ToggleFocusedWindowFloatingCommand.cs b/GlazeWM.Domain/Windows/Commands/ToggleFocusedWindowFloatingCommand.csdeleted file mode 100644index b5c1c8f0..00000000--- a/GlazeWM.Domain/Windows/Commands/ToggleFocusedWindowFloatingCommand.cs+++ /dev/null@@ -1,8 +0,0 @@-using GlazeWM.Infrastructure.Bussing;--namespace GlazeWM.Domain.Windows.Commands-{- public class ToggleFocusedWindowFloatingCommand : Command- {- }-}diff --git a/GlazeWM.Domain/Workspaces/CommandHandlers/MoveFocusedWindowToWorkspaceHandler.cs b/GlazeWM.Domain/Workspaces/CommandHandlers/MoveWindowToWorkspaceHandler.cssimilarity index 52%rename from GlazeWM.Domain/Workspaces/CommandHandlers/MoveFocusedWindowToWorkspaceHandler.csrename to GlazeWM.Domain/Workspaces/CommandHandlers/MoveWindowToWorkspaceHandler.csindex b8dcf2f7..6e967c7b 100644--- a/GlazeWM.Domain/Workspaces/CommandHandlers/MoveFocusedWindowToWorkspaceHandler.cs+++ b/GlazeWM.Domain/Workspaces/CommandHandlers/MoveWindowToWorkspaceHandler.cs@@ -7,53 +7,47 @@ using GlazeWM.Domain.Containers.Commands;namespace GlazeWM.Domain.Workspaces.CommandHandlers{- internal class MoveFocusedWindowToWorkspaceHandler : ICommandHandler<MoveFocusedWindowToWorkspaceCommand>+ internal class MoveWindowToWorkspaceHandler : ICommandHandler<MoveWindowToWorkspaceCommand>{private readonly Bus _bus;private readonly WorkspaceService _workspaceService;- private readonly MonitorService _monitorService;private readonly ContainerService _containerService;- public MoveFocusedWindowToWorkspaceHandler(+ public MoveWindowToWorkspaceHandler(Bus bus,WorkspaceService workspaceService,- MonitorService monitorService,ContainerService containerService){_bus = bus;_workspaceService = workspaceService;- _monitorService = monitorService;_containerService = containerService;}- public CommandResponse Handle(MoveFocusedWindowToWorkspaceCommand command)+ public CommandResponse Handle(MoveWindowToWorkspaceCommand command){+ var windowToMove = command.WindowToMove;var workspaceName = command.WorkspaceName;- var focusedWindow = _containerService.FocusedContainer as Window;- // Ignore cases where focused container is not a window or not in foreground.- if (focusedWindow == null || !_containerService.IsFocusSynced)- return CommandResponse.Ok;-- var currentWorkspace = _workspaceService.GetFocusedWorkspace();+ var currentWorkspace = WorkspaceService.GetWorkspaceFromChildContainer(windowToMove);+ var currentMonitor = MonitorService.GetMonitorFromChildContainer(currentWorkspace);var targetWorkspace = _workspaceService.GetActiveWorkspaceByName(workspaceName)- ?? ActivateWorkspace(workspaceName);+ ?? ActivateWorkspace(workspaceName, currentMonitor);// Since target workspace could be on a different monitor, adjustments might need to be made// because of DPI.if (MonitorService.HasDpiDifference(currentWorkspace, targetWorkspace))- focusedWindow.HasPendingDpiAdjustment = true;+ windowToMove.HasPendingDpiAdjustment = true;// Update floating placement if the window has to cross monitors.if (targetWorkspace.Parent != currentWorkspace.Parent)- focusedWindow.FloatingPlacement =- focusedWindow.FloatingPlacement.TranslateToCenter(targetWorkspace.ToRectangle());+ windowToMove.FloatingPlacement =+ windowToMove.FloatingPlacement.TranslateToCenter(targetWorkspace.ToRectangle());- if (focusedWindow is TilingWindow)- MoveTilingWindowToWorkspace(focusedWindow as TilingWindow, targetWorkspace);+ if (windowToMove is TilingWindow)+ MoveTilingWindowToWorkspace(windowToMove as TilingWindow, targetWorkspace);else- _bus.Invoke(new MoveContainerWithinTreeCommand(focusedWindow, targetWorkspace, false));+ _bus.Invoke(new MoveContainerWithinTreeCommand(windowToMove, targetWorkspace, false));// Reassign focus to descendant within the current workspace._bus.Invoke(new FocusWorkspaceCommand(currentWorkspace.Name));@@ -65,17 +59,17 @@ namespace GlazeWM.Domain.Workspaces.CommandHandlersreturn CommandResponse.Ok;}- private void MoveTilingWindowToWorkspace(TilingWindow focusedWindow, Workspace targetWorkspace)+ private void MoveTilingWindowToWorkspace(TilingWindow windowToMove, Workspace targetWorkspace){var insertionTarget = targetWorkspace.LastFocusedDescendantOfType(typeof(IResizable));- // Insert the focused window into the target workspace.+ // Insert the window into the target workspace.if (insertionTarget == null)- _bus.Invoke(new MoveContainerWithinTreeCommand(focusedWindow, targetWorkspace, true));+ _bus.Invoke(new MoveContainerWithinTreeCommand(windowToMove, targetWorkspace, true));else_bus.Invoke(new MoveContainerWithinTreeCommand(- focusedWindow,+ windowToMove,insertionTarget.Parent,insertionTarget.Index + 1,true@@ -83,14 +77,9 @@ namespace GlazeWM.Domain.Workspaces.CommandHandlers);}- /// <summary>- /// Activate a given workspace on the currently focused monitor.- /// </summary>- private Workspace ActivateWorkspace(string workspaceName)+ private Workspace ActivateWorkspace(string workspaceName, Monitor targetMonitor){- var focusedMonitor = _monitorService.GetFocusedMonitor();- _bus.Invoke(new ActivateWorkspaceCommand(workspaceName, focusedMonitor));-+ _bus.Invoke(new ActivateWorkspaceCommand(workspaceName, targetMonitor));return _workspaceService.GetActiveWorkspaceByName(workspaceName);}}diff --git a/GlazeWM.Domain/Workspaces/Commands/MoveFocusedWindowToWorkspaceCommand.cs b/GlazeWM.Domain/Workspaces/Commands/MoveFocusedWindowToWorkspaceCommand.csdeleted file mode 100644index 94775f05..00000000--- a/GlazeWM.Domain/Workspaces/Commands/MoveFocusedWindowToWorkspaceCommand.cs+++ /dev/null@@ -1,14 +0,0 @@-using GlazeWM.Infrastructure.Bussing;--namespace GlazeWM.Domain.Workspaces.Commands-{- internal class MoveFocusedWindowToWorkspaceCommand : Command- {- public string WorkspaceName { get; }-- public MoveFocusedWindowToWorkspaceCommand(string workspaceName)- {- WorkspaceName = workspaceName;- }- }-}diff --git a/GlazeWM.Domain/Workspaces/Commands/MoveWindowToWorkspaceCommand.cs b/GlazeWM.Domain/Workspaces/Commands/MoveWindowToWorkspaceCommand.csnew file mode 100644index 00000000..df1e677a--- /dev/null+++ b/GlazeWM.Domain/Workspaces/Commands/MoveWindowToWorkspaceCommand.cs@@ -0,0 +1,17 @@+using GlazeWM.Domain.Windows;+using GlazeWM.Infrastructure.Bussing;++namespace GlazeWM.Domain.Workspaces.Commands+{+ internal class MoveWindowToWorkspaceCommand : Command+ {+ public Window WindowToMove { get; }+ public string WorkspaceName { get; }++ public MoveWindowToWorkspaceCommand(Window windowToMove, string workspaceName)+ {+ WindowToMove = windowToMove;+ WorkspaceName = workspaceName;+ }+ }+}diff --git a/GlazeWM.Infrastructure/Bussing/CommandHandlers/NoopHandler.cs b/GlazeWM.Infrastructure/Bussing/CommandHandlers/NoopHandler.csnew file mode 100644index 00000000..c7ae0fec--- /dev/null+++ b/GlazeWM.Infrastructure/Bussing/CommandHandlers/NoopHandler.cs@@ -0,0 +1,12 @@+using GlazeWM.Infrastructure.Bussing.Commands;++namespace GlazeWM.Infrastructure.Bussing.CommandHandlers+{+ internal class NoopHandler : ICommandHandler<NoopCommand>+ {+ public CommandResponse Handle(NoopCommand command)+ {+ return CommandResponse.Ok;+ }+ }+}diff --git a/GlazeWM.Infrastructure/Bussing/Commands/NoopCommand.cs b/GlazeWM.Infrastructure/Bussing/Commands/NoopCommand.csnew file mode 100644index 00000000..9bab5ca6--- /dev/null+++ b/GlazeWM.Infrastructure/Bussing/Commands/NoopCommand.cs@@ -0,0 +1,6 @@+namespace GlazeWM.Infrastructure.Bussing.Commands+{+ public class NoopCommand : Command+ {+ }+}diff --git a/GlazeWM.Infrastructure/DependencyInjection.cs b/GlazeWM.Infrastructure/DependencyInjection.csindex 8e42de64..331fa643 100644--- a/GlazeWM.Infrastructure/DependencyInjection.cs+++ b/GlazeWM.Infrastructure/DependencyInjection.cs@@ -1,4 +1,6 @@using GlazeWM.Infrastructure.Bussing;+using GlazeWM.Infrastructure.Bussing.CommandHandlers;+using GlazeWM.Infrastructure.Bussing.Commands;using GlazeWM.Infrastructure.WindowsApi;using GlazeWM.Infrastructure.Yaml;using Microsoft.Extensions.DependencyInjection;@@ -16,6 +18,8 @@ namespace GlazeWM.Infrastructureservices.AddSingleton<WindowEventService>();services.AddSingleton<YamlDeserializationService>();+ services.AddSingleton<ICommandHandler<NoopCommand>, NoopHandler>();+// TODO: Change WindowsApiService to be compatible with DI.return services;