GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat: add separate "set floating" command (#68)
lars-berger4ebcfd4c0cef
diff --git a/GlazeWM.Domain/DependencyInjection.cs b/GlazeWM.Domain/DependencyInjection.csindex 5337b7a5..da42c7a2 100644--- a/GlazeWM.Domain/DependencyInjection.cs+++ b/GlazeWM.Domain/DependencyInjection.cs@@ -60,6 +60,8 @@ namespace GlazeWM.Domainservices.AddSingleton<ICommandHandler<RemoveWindowCommand>, RemoveWindowHandler>();services.AddSingleton<ICommandHandler<ResizeFocusedWindowCommand>, ResizeFocusedWindowHandler>();services.AddSingleton<ICommandHandler<ResizeFocusedWindowBordersCommand>, ResizeFocusedWindowBordersHandler>();+ 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>();diff --git a/GlazeWM.Domain/UserConfigs/CommandParsingService.cs b/GlazeWM.Domain/UserConfigs/CommandParsingService.csindex bc9c7f33..97aee2bd 100644--- a/GlazeWM.Domain/UserConfigs/CommandParsingService.cs+++ b/GlazeWM.Domain/UserConfigs/CommandParsingService.cs@@ -39,6 +39,7 @@ namespace GlazeWM.Domain.UserConfigs"focus" => ParseFocusCommand(commandParts),"move" => ParseMoveCommand(commandParts),"resize" => ParseResizeCommand(commandParts),+ "set" => ParseSetCommand(commandParts),"toggle" => ParseToggleCommand(commandParts),"exit" => ParseExitCommand(commandParts),"close" => new CloseFocusedWindowCommand(),@@ -100,6 +101,15 @@ namespace GlazeWM.Domain.UserConfigs};}+ private Command ParseSetCommand(string[] commandParts)+ {+ return commandParts[1] switch+ {+ "floating" => new SetFocusedWindowFloatingCommand(),+ _ => throw new ArgumentException(),+ };+ }+private Command ParseToggleCommand(string[] commandParts){return commandParts[1] switchdiff --git a/GlazeWM.Domain/Windows/CommandHandlers/SetFloatingHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/SetFloatingHandler.csnew file mode 100644index 00000000..6d70ace9--- /dev/null+++ b/GlazeWM.Domain/Windows/CommandHandlers/SetFloatingHandler.cs@@ -0,0 +1,48 @@+using GlazeWM.Domain.Containers;+using GlazeWM.Domain.Containers.Commands;+using GlazeWM.Domain.Windows.Commands;+using GlazeWM.Domain.Workspaces;+using GlazeWM.Infrastructure.Bussing;++namespace GlazeWM.Domain.Windows.CommandHandlers+{+ class SetFloatingHandler : ICommandHandler<SetFloatingCommand>+ {+ private readonly Bus _bus;+ private readonly WorkspaceService _workspaceService;++ public SetFloatingHandler(Bus bus, WorkspaceService workspaceService)+ {+ _bus = bus;+ _workspaceService = workspaceService;+ }++ public CommandResponse Handle(SetFloatingCommand command)+ {+ var window = command.Window;++ if (window is FloatingWindow)+ return CommandResponse.Ok;++ // Keep reference to the window's ancestor workspace prior to detaching.+ var workspace = _workspaceService.GetWorkspaceFromChildContainer(window);++ if (window is IResizable)+ _bus.Invoke(new MoveContainerWithinTreeCommand(window, workspace, true));+ else+ _bus.Invoke(new MoveContainerWithinTreeCommand(window, workspace, false));++ // Create a floating window and place it in the center of the workspace.+ var floatingWindow = new FloatingWindow(+ window.Hwnd,+ window.FloatingPlacement,+ window.BorderDelta+ );++ _bus.Invoke(new ReplaceContainerCommand(floatingWindow, window.Parent, window.Index));+ _bus.Invoke(new RedrawContainersCommand());++ return CommandResponse.Ok;+ }+ }+}diff --git a/GlazeWM.Domain/Windows/CommandHandlers/SetFocusedWindowFloatingHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/SetFocusedWindowFloatingHandler.csnew file mode 100644index 00000000..a8b6b6a4--- /dev/null+++ b/GlazeWM.Domain/Windows/CommandHandlers/SetFocusedWindowFloatingHandler.cs@@ -0,0 +1,31 @@+using GlazeWM.Domain.Containers;+using GlazeWM.Domain.Windows.Commands;+using GlazeWM.Infrastructure.Bussing;++namespace GlazeWM.Domain.Windows.CommandHandlers+{+ class SetFocusedWindowFloatingHandler : ICommandHandler<SetFocusedWindowFloatingCommand>+ {+ private Bus _bus;+ private 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/ToggleFloatingHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/ToggleFloatingHandler.csindex 2ff75687..43403f0f 100644--- a/GlazeWM.Domain/Windows/CommandHandlers/ToggleFloatingHandler.cs+++ b/GlazeWM.Domain/Windows/CommandHandlers/ToggleFloatingHandler.cs@@ -8,17 +8,13 @@ namespace GlazeWM.Domain.Windows.CommandHandlers{class ToggleFloatingHandler : ICommandHandler<ToggleFloatingCommand>{- private Bus _bus;- private WorkspaceService _workspaceService;- private WindowService _windowService;- private ContainerService _containerService;+ private readonly Bus _bus;+ private readonly WorkspaceService _workspaceService;- public ToggleFloatingHandler(Bus bus, WorkspaceService workspaceService, WindowService windowService, ContainerService containerService)+ public ToggleFloatingHandler(Bus bus, WorkspaceService workspaceService){_bus = bus;_workspaceService = workspaceService;- _windowService = windowService;- _containerService = containerService;}public CommandResponse Handle(ToggleFloatingCommand command)@@ -26,46 +22,27 @@ namespace GlazeWM.Domain.Windows.CommandHandlersvar window = command.Window;if (window is FloatingWindow)- DisableFloating(window as FloatingWindow);+ UnsetFloating(window as FloatingWindow);else- EnableFloating(window);+ _bus.Invoke(new SetFloatingCommand(window));return CommandResponse.Ok;}- private void EnableFloating(Window window)- {- // Keep reference to the window's ancestor workspace prior to detaching.- var workspace = _workspaceService.GetWorkspaceFromChildContainer(window);-- if (window is IResizable)- _bus.Invoke(new MoveContainerWithinTreeCommand(window, workspace, true));- else- _bus.Invoke(new MoveContainerWithinTreeCommand(window, workspace, false));-- // Create a floating window and place it in the center of the workspace.- var floatingWindow = new FloatingWindow(- window.Hwnd,- window.FloatingPlacement,- window.BorderDelta- );-- _bus.Invoke(new ReplaceContainerCommand(floatingWindow, window.Parent, window.Index));- _bus.Invoke(new RedrawContainersCommand());- }-- private void DisableFloating(FloatingWindow floatingWindow)+ private void UnsetFloating(FloatingWindow floatingWindow){// Keep reference to the window's ancestor workspace prior to detaching.var workspace = _workspaceService.GetWorkspaceFromChildContainer(floatingWindow);var insertionTarget = workspace.LastFocusedDescendantOfType(typeof(IResizable));- var tilingWindow = new TilingWindow(floatingWindow.Hwnd, floatingWindow.FloatingPlacement, floatingWindow.BorderDelta)- {- SizePercentage = 0- };+ var tilingWindow = new TilingWindow(+ floatingWindow.Hwnd,+ floatingWindow.FloatingPlacement,+ floatingWindow.BorderDelta,+ 0+ );_bus.Invoke(new ReplaceContainerCommand(tilingWindow, floatingWindow.Parent, floatingWindow.Index));diff --git a/GlazeWM.Domain/Windows/Commands/SetFloatingCommand.cs b/GlazeWM.Domain/Windows/Commands/SetFloatingCommand.csnew file mode 100644index 00000000..c16ff601--- /dev/null+++ b/GlazeWM.Domain/Windows/Commands/SetFloatingCommand.cs@@ -0,0 +1,14 @@+using GlazeWM.Infrastructure.Bussing;++namespace GlazeWM.Domain.Windows.Commands+{+ public class SetFloatingCommand : Command+ {+ public Window Window { get; }++ public SetFloatingCommand(Window window)+ {+ Window = window;+ }+ }+}diff --git a/GlazeWM.Domain/Windows/Commands/SetFocusedWindowFloatingCommand.cs b/GlazeWM.Domain/Windows/Commands/SetFocusedWindowFloatingCommand.csnew file mode 100644index 00000000..d275f7be--- /dev/null+++ b/GlazeWM.Domain/Windows/Commands/SetFocusedWindowFloatingCommand.cs@@ -0,0 +1,11 @@+using GlazeWM.Infrastructure.Bussing;++namespace GlazeWM.Domain.Windows.Commands+{+ public class SetFocusedWindowFloatingCommand : Command+ {+ public SetFocusedWindowFloatingCommand()+ {+ }+ }+}