GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat(domain): avoid specifying whether to grow/shrink when resizing
Lars Berger20e577d42423
diff --git a/GlazeWM.Domain/Common/Enums/ResizeDimension.cs b/GlazeWM.Domain/Common/Enums/ResizeDimension.csnew file mode 100644index 00000000..c80e45c9--- /dev/null+++ b/GlazeWM.Domain/Common/Enums/ResizeDimension.cs@@ -0,0 +1,8 @@+namespace GlazeWM.Domain.Common.Enums+{+ public enum ResizeDimension+ {+ WIDTH,+ HEIGHT,+ }+}diff --git a/GlazeWM.Domain/Common/Enums/ResizeDirection.cs b/GlazeWM.Domain/Common/Enums/ResizeDirection.csdeleted file mode 100644index 0d49520f..00000000--- a/GlazeWM.Domain/Common/Enums/ResizeDirection.cs+++ /dev/null@@ -1,10 +0,0 @@-namespace GlazeWM.Domain.Common.Enums-{- public enum ResizeDirection- {- GROW_HEIGHT,- SHRINK_HEIGHT,- SHRINK_WIDTH,- GROW_WIDTH,- }-}diff --git a/GlazeWM.Domain/UserConfigs/CommandParsingService.cs b/GlazeWM.Domain/UserConfigs/CommandParsingService.csindex 829b8dc1..cb384536 100644--- a/GlazeWM.Domain/UserConfigs/CommandParsingService.cs+++ b/GlazeWM.Domain/UserConfigs/CommandParsingService.cs@@ -87,18 +87,8 @@ namespace GlazeWM.Domain.UserConfigs{return commandParts[1] switch{- "grow" => commandParts[2] switch- {- "height" => new ResizeFocusedWindowCommand(ResizeDirection.GROW_HEIGHT, commandParts[3]),- "width" => new ResizeFocusedWindowCommand(ResizeDirection.GROW_WIDTH, commandParts[3]),- _ => throw new ArgumentException(),- },- "shrink" => commandParts[2] switch- {- "height" => new ResizeFocusedWindowCommand(ResizeDirection.SHRINK_HEIGHT, commandParts[3]),- "width" => new ResizeFocusedWindowCommand(ResizeDirection.SHRINK_WIDTH, commandParts[3]),- _ => throw new ArgumentException(),- },+ "height" => new ResizeFocusedWindowCommand(ResizeDimension.HEIGHT, commandParts[2]),+ "width" => new ResizeFocusedWindowCommand(ResizeDimension.WIDTH, commandParts[2]),_ => throw new ArgumentException(),};}diff --git a/GlazeWM.Domain/Windows/CommandHandlers/ResizeFocusedWindowHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/ResizeFocusedWindowHandler.csindex d3a2cdeb..03abd77c 100644--- a/GlazeWM.Domain/Windows/CommandHandlers/ResizeFocusedWindowHandler.cs+++ b/GlazeWM.Domain/Windows/CommandHandlers/ResizeFocusedWindowHandler.cs@@ -25,7 +25,7 @@ namespace GlazeWM.Domain.Windows.CommandHandlerspublic CommandResponse Handle(ResizeFocusedWindowCommand command){- var resizeDirection = command.ResizeDirection;+ var dimensionToResize = command.DimensionToResize;var resizeAmount = command.ResizeAmount;var focusedWindow = _containerService.FocusedContainer as TilingWindow;@@ -35,12 +35,11 @@ namespace GlazeWM.Domain.Windows.CommandHandlersvar layout = (focusedWindow.Parent as SplitContainer).Layout;- // Whether the parent of the focused window should be resized rather than the focused window itself.+ // Get whether the parent of the focused window should be resized rather than the focused+ // window itself.var shouldResizeParent =- (layout == Layout.HORIZONTAL &&- (resizeDirection == ResizeDirection.SHRINK_HEIGHT || resizeDirection == ResizeDirection.GROW_HEIGHT)) ||- (layout == Layout.VERTICAL &&- (resizeDirection == ResizeDirection.SHRINK_WIDTH || resizeDirection == ResizeDirection.GROW_WIDTH));+ (layout == Layout.HORIZONTAL && dimensionToResize == ResizeDimension.HEIGHT)+ || (layout == Layout.VERTICAL && dimensionToResize == ResizeDimension.WIDTH);var containerToResize = shouldResizeParent ? focusedWindow.Parent : focusedWindow;@@ -53,19 +52,12 @@ namespace GlazeWM.Domain.Windows.CommandHandlers// Convert `resizeAmount` to a percentage to increase/decrease the window size by.var resizePercentage = ConvertToResizePercentage(resizeAmount);+ var resizeProportion = resizePercentage / 100;- switch (resizeDirection)- {- case ResizeDirection.GROW_WIDTH:- case ResizeDirection.GROW_HEIGHT:- ShrinkSizeOfSiblings(containerToResize, resizableSiblings, resizePercentage);- break;-- case ResizeDirection.SHRINK_WIDTH:- case ResizeDirection.SHRINK_HEIGHT:- GrowSizeOfSiblings(containerToResize, resizableSiblings, resizePercentage);- break;- }+ (containerToResize as IResizable).SizePercentage += resizeProportion;++ foreach (var sibling in resizableSiblings)+ (sibling as IResizable).SizePercentage -= resizeProportion / resizableSiblings.Count();_containerService.ContainersToRedraw.Add(containerToResize.Parent);_bus.Invoke(new RedrawContainersCommand());@@ -94,31 +86,5 @@ namespace GlazeWM.Domain.Windows.CommandHandlersthrow new FatalUserException($"Invalid resize amount {resizeAmount}.");}}-- private void GrowSizeOfSiblings(- Container containerToShrink,- IEnumerable<Container> resizableSiblings,- double resizePercentage- )- {- var resizeProportion = resizePercentage / 100;- (containerToShrink as IResizable).SizePercentage -= resizeProportion;-- foreach (var sibling in resizableSiblings)- (sibling as IResizable).SizePercentage += resizeProportion / resizableSiblings.Count();- }-- private void ShrinkSizeOfSiblings(- Container containerToGrow,- IEnumerable<Container> resizableSiblings,- double resizePercentage- )- {- var resizeProportion = resizePercentage / 100;- (containerToGrow as IResizable).SizePercentage += resizeProportion;-- foreach (var sibling in resizableSiblings)- (sibling as IResizable).SizePercentage -= resizeProportion / resizableSiblings.Count();- }}}diff --git a/GlazeWM.Domain/Windows/Commands/ResizeFocusedWindowCommand.cs b/GlazeWM.Domain/Windows/Commands/ResizeFocusedWindowCommand.csindex 5d963a41..b8f13ad6 100644--- a/GlazeWM.Domain/Windows/Commands/ResizeFocusedWindowCommand.cs+++ b/GlazeWM.Domain/Windows/Commands/ResizeFocusedWindowCommand.cs@@ -5,12 +5,12 @@ namespace GlazeWM.Domain.Windows.Commands{public class ResizeFocusedWindowCommand : Command{- public ResizeDirection ResizeDirection { get; }+ public ResizeDimension DimensionToResize { get; }public string ResizeAmount { get; }- public ResizeFocusedWindowCommand(ResizeDirection resizeDirection, string resizeAmount)+ public ResizeFocusedWindowCommand(ResizeDimension dimensionToResize, string resizeAmount){- ResizeDirection = resizeDirection;+ DimensionToResize = dimensionToResize;ResizeAmount = resizeAmount;}}