GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat(domain): convert given resize amount to a percentage increase/decrease in `ResizeFocusedWindowHandler`
Lars Berger167acb167fc3
diff --git a/GlazeWM.Domain/Windows/CommandHandlers/ResizeFocusedWindowHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/ResizeFocusedWindowHandler.csindex f3860647..d3a2cdeb 100644--- a/GlazeWM.Domain/Windows/CommandHandlers/ResizeFocusedWindowHandler.cs+++ b/GlazeWM.Domain/Windows/CommandHandlers/ResizeFocusedWindowHandler.cs@@ -1,10 +1,11 @@-using System.Collections.Generic;+using System;+using System.Collections.Generic;+using System.Globalization;using System.Linq;-using System.Windows.Documents;+using System.Text.RegularExpressions;using GlazeWM.Domain.Common.Enums;using GlazeWM.Domain.Containers;using GlazeWM.Domain.Containers.Commands;-using GlazeWM.Domain.UserConfigs;using GlazeWM.Domain.Windows.Commands;using GlazeWM.Domain.Workspaces;using GlazeWM.Infrastructure.Bussing;@@ -14,18 +15,18 @@ namespace GlazeWM.Domain.Windows.CommandHandlersclass ResizeFocusedWindowHandler : ICommandHandler<ResizeFocusedWindowCommand>{private Bus _bus;- private UserConfigService _userConfigService;private ContainerService _containerService;- public ResizeFocusedWindowHandler(Bus bus, UserConfigService userConfigService, ContainerService containerService)+ public ResizeFocusedWindowHandler(Bus bus, ContainerService containerService){_bus = bus;- _userConfigService = userConfigService;_containerService = containerService;}public CommandResponse Handle(ResizeFocusedWindowCommand command){+ var resizeDirection = command.ResizeDirection;+ var resizeAmount = command.ResizeAmount;var focusedWindow = _containerService.FocusedContainer as TilingWindow;// Ignore cases where focused container is not a tiling window.@@ -33,7 +34,6 @@ namespace GlazeWM.Domain.Windows.CommandHandlersreturn CommandResponse.Ok;var layout = (focusedWindow.Parent as SplitContainer).Layout;- var resizeDirection = command.ResizeDirection;// Whether the parent of the focused window should be resized rather than the focused window itself.var shouldResizeParent =@@ -51,16 +51,19 @@ namespace GlazeWM.Domain.Windows.CommandHandlersif (resizableSiblings.Count() == 0 || containerToResize is Workspace)return CommandResponse.Ok;+ // Convert `resizeAmount` to a percentage to increase/decrease the window size by.+ var resizePercentage = ConvertToResizePercentage(resizeAmount);+switch (resizeDirection){case ResizeDirection.GROW_WIDTH:case ResizeDirection.GROW_HEIGHT:- ShrinkSizeOfSiblings(containerToResize, resizableSiblings);+ ShrinkSizeOfSiblings(containerToResize, resizableSiblings, resizePercentage);break;case ResizeDirection.SHRINK_WIDTH:case ResizeDirection.SHRINK_HEIGHT:- GrowSizeOfSiblings(containerToResize, resizableSiblings);+ GrowSizeOfSiblings(containerToResize, resizableSiblings, resizePercentage);break;}@@ -70,18 +73,48 @@ namespace GlazeWM.Domain.Windows.CommandHandlersreturn CommandResponse.Ok;}- private void GrowSizeOfSiblings(Container containerToShrink, IEnumerable<Container> resizableSiblings)+ private double ConvertToResizePercentage(string resizeAmount)+ {+ try+ {+ var matchedResizeAmount = new Regex(@"(.*)(%|ppt)").Match(resizeAmount);+ var amount = matchedResizeAmount.Groups[1].Value;+ var unit = matchedResizeAmount.Groups[2].Value;++ // TODO: Handle conversion from px to `SizePercentage`.+ return unit switch+ {+ "%" => Convert.ToDouble(amount, CultureInfo.InvariantCulture),+ "ppt" => Convert.ToDouble(amount, CultureInfo.InvariantCulture),+ _ => throw new ArgumentException(),+ };+ }+ catch+ {+ throw new FatalUserException($"Invalid resize amount {resizeAmount}.");+ }+ }++ private void GrowSizeOfSiblings(+ Container containerToShrink,+ IEnumerable<Container> resizableSiblings,+ double resizePercentage+ ){- var resizeProportion = _userConfigService.UserConfig.ResizeProportion;+ 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)+ private void ShrinkSizeOfSiblings(+ Container containerToGrow,+ IEnumerable<Container> resizableSiblings,+ double resizePercentage+ ){- var resizeProportion = _userConfigService.UserConfig.ResizeProportion;+ var resizeProportion = resizePercentage / 100;(containerToGrow as IResizable).SizePercentage += resizeProportion;foreach (var sibling in resizableSiblings)