GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat: add "set tiling" command (#180)
lars-berger2a10fe973a7a
diff --git a/GlazeWM.Domain/DependencyInjection.cs b/GlazeWM.Domain/DependencyInjection.csindex 562c6890..80829eb4 100644--- a/GlazeWM.Domain/DependencyInjection.cs+++ b/GlazeWM.Domain/DependencyInjection.cs@@ -64,8 +64,9 @@ namespace GlazeWM.Domainservices.AddSingleton<ICommandHandler<RunWindowRulesCommand>, RunWindowRulesHandler>();services.AddSingleton<ICommandHandler<ResizeWindowBordersCommand>, ResizeWindowBordersHandler>();services.AddSingleton<ICommandHandler<SetFloatingCommand>, SetFloatingHandler>();- services.AddSingleton<ICommandHandler<SetMinimizedCommand>, SetMinimizedHandler>();services.AddSingleton<ICommandHandler<SetMaximizedCommand>, SetMaximizedHandler>();+ services.AddSingleton<ICommandHandler<SetMinimizedCommand>, SetMinimizedHandler>();+ services.AddSingleton<ICommandHandler<SetTilingCommand>, SetTilingHandler>();services.AddSingleton<ICommandHandler<ShowAllWindowsCommand>, ShowAllWindowsHandler>();services.AddSingleton<ICommandHandler<ToggleFloatingCommand>, ToggleFloatingHandler>();services.AddSingleton<ICommandHandler<ToggleMaximizedCommand>, ToggleMaximizedHandler>();diff --git a/GlazeWM.Domain/UserConfigs/CommandParsingService.cs b/GlazeWM.Domain/UserConfigs/CommandParsingService.csindex 1f7528c0..1664dd4d 100644--- a/GlazeWM.Domain/UserConfigs/CommandParsingService.cs+++ b/GlazeWM.Domain/UserConfigs/CommandParsingService.cs@@ -1,4 +1,4 @@-using System;+using System;using System.Collections.Generic;using System.Linq;using System.Text.RegularExpressions;@@ -200,6 +200,9 @@ namespace GlazeWM.Domain.UserConfigs"maximized" => subjectContainer is Window? new SetMaximizedCommand(subjectContainer as Window): new NoopCommand(),+ "tiling" => subjectContainer is Window+ ? new SetTilingCommand(subjectContainer as Window)+ : new NoopCommand(),_ => throw new ArgumentException(null, nameof(commandParts)),};}diff --git a/GlazeWM.Domain/Windows/CommandHandlers/SetTilingHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/SetTilingHandler.csnew file mode 100644index 00000000..4b1b8bf4--- /dev/null+++ b/GlazeWM.Domain/Windows/CommandHandlers/SetTilingHandler.cs@@ -0,0 +1,58 @@+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+{+ internal class SetTilingHandler : ICommandHandler<SetTilingCommand>+ {+ private readonly Bus _bus;++ public SetTilingHandler(Bus bus)+ {+ _bus = bus;+ }++ public CommandResponse Handle(SetTilingCommand command)+ {+ var window = command.Window;++ if (window is TilingWindow)+ return CommandResponse.Ok;++ // Keep reference to the window's ancestor workspace prior to detaching.+ var workspace = WorkspaceService.GetWorkspaceFromChildContainer(window);++ var insertionTarget = workspace.LastFocusedDescendantOfType<IResizable>();++ var tilingWindow = new TilingWindow(+ window.Handle,+ window.FloatingPlacement,+ window.BorderDelta,+ 0+ );++ // Replace the original window with the created tiling window.+ _bus.Invoke(new ReplaceContainerCommand(tilingWindow, window.Parent, window.Index));++ // Insert the created tiling window after the last focused descendant of the workspace.+ if (insertionTarget is null)+ _bus.Invoke(new MoveContainerWithinTreeCommand(tilingWindow, workspace, 0, true));+ else+ _bus.Invoke(+ new MoveContainerWithinTreeCommand(+ tilingWindow,+ insertionTarget.Parent,+ insertionTarget.Index + 1,+ true+ )+ );++ _bus.Invoke(new RedrawContainersCommand());++ return CommandResponse.Ok;+ }+ }+}diff --git a/GlazeWM.Domain/Windows/CommandHandlers/ToggleFloatingHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/ToggleFloatingHandler.csindex c83644b3..f7b0d906 100644--- a/GlazeWM.Domain/Windows/CommandHandlers/ToggleFloatingHandler.cs+++ b/GlazeWM.Domain/Windows/CommandHandlers/ToggleFloatingHandler.cs@@ -1,7 +1,4 @@-using GlazeWM.Domain.Containers;-using GlazeWM.Domain.Containers.Commands;-using GlazeWM.Domain.Windows.Commands;-using GlazeWM.Domain.Workspaces;+using GlazeWM.Domain.Windows.Commands;using GlazeWM.Infrastructure.Bussing;namespace GlazeWM.Domain.Windows.CommandHandlers@@ -20,49 +17,11 @@ namespace GlazeWM.Domain.Windows.CommandHandlersvar window = command.Window;if (window is FloatingWindow)- UnsetFloating(window as FloatingWindow);+ _bus.Invoke(new SetTilingCommand(window));else_bus.Invoke(new SetFloatingCommand(window));return CommandResponse.Ok;}-- 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<IResizable>();-- var tilingWindow = new TilingWindow(- floatingWindow.Handle,- floatingWindow.FloatingPlacement,- floatingWindow.BorderDelta,- 0- );-- _bus.Invoke(- new ReplaceContainerCommand(- tilingWindow,- floatingWindow.Parent,- floatingWindow.Index- )- );-- // Insert the created tiling window after the last focused descendant of the workspace.- if (insertionTarget == null)- _bus.Invoke(new MoveContainerWithinTreeCommand(tilingWindow, workspace, 0, true));- else- _bus.Invoke(- new MoveContainerWithinTreeCommand(- tilingWindow,- insertionTarget.Parent,- insertionTarget.Index + 1,- true- )- );-- _bus.Invoke(new RedrawContainersCommand());- }}}diff --git a/GlazeWM.Domain/Windows/Commands/SetTilingCommand.cs b/GlazeWM.Domain/Windows/Commands/SetTilingCommand.csnew file mode 100644index 00000000..f141b151--- /dev/null+++ b/GlazeWM.Domain/Windows/Commands/SetTilingCommand.cs@@ -0,0 +1,14 @@+using GlazeWM.Infrastructure.Bussing;++namespace GlazeWM.Domain.Windows.Commands+{+ public class SetTilingCommand : Command+ {+ public Window Window { get; }++ public SetTilingCommand(Window window)+ {+ Window = window;+ }+ }+}