Skip to content

GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.

feat(domain): handle resizing of focused & sibling containers for horizontal parent containers

Larsfbb8390097ea
diff --git a/LarsWM.Domain/Windows/CommandHandlers/ResizeFocusedWindowHandler.cs b/LarsWM.Domain/Windows/CommandHandlers/ResizeFocusedWindowHandler.cs
index 92e9b05f..37e6089c 100644
--- a/LarsWM.Domain/Windows/CommandHandlers/ResizeFocusedWindowHandler.cs
+++ b/LarsWM.Domain/Windows/CommandHandlers/ResizeFocusedWindowHandler.cs
@@ -1,4 +1,9 @@
using System;
+using System.Linq;
+using LarsWM.Domain.Common.Enums;
+using LarsWM.Domain.Common.Models;
+using LarsWM.Domain.Containers;
+using LarsWM.Domain.Containers.Commands;
using LarsWM.Domain.UserConfigs;
using LarsWM.Domain.Windows.Commands;
using LarsWM.Infrastructure.Bussing;
@@ -7,22 +12,48 @@ namespace LarsWM.Domain.Windows.CommandHandlers
{
class ResizeFocusedWindowHandler : ICommandHandler<ResizeFocusedWindowCommand>
{
+ private IBus _bus;
private WindowService _windowService;
private UserConfigService _userConfigService;
+ private ContainerService _containerService;
- public ResizeFocusedWindowHandler(WindowService windowService, UserConfigService userConfigService)
+ public ResizeFocusedWindowHandler(IBus bus, WindowService windowService, UserConfigService userConfigService, ContainerService containerService)
{
+ _bus = bus;
_windowService = windowService;
_userConfigService = userConfigService;
+ _containerService = containerService;
}
public dynamic Handle(ResizeFocusedWindowCommand command)
{
- var resizePercentage = _userConfigService.UserConfig.ResizePercentage;
var focusedWindow = _windowService.FocusedWindow;
- var parent = focusedWindow.Parent;
+ var parent = focusedWindow.Parent as SplitContainer;
+ var siblings = parent.Children.Where(child => child != focusedWindow);
+
+ var resizePercentage = _userConfigService.UserConfig.ResizePercentage;
+ var layout = parent.Layout;
+
+ if (layout == Layout.Horizontal && command.Direction == Direction.Right)
+ {
+ focusedWindow.SizePercentage += resizePercentage;
+
+ foreach (var sibling in siblings)
+ sibling.SizePercentage -= resizePercentage / siblings.Count();
+ }
+
+ if (layout == Layout.Horizontal && command.Direction == Direction.Left)
+ {
+ focusedWindow.SizePercentage -= resizePercentage;
+
+ foreach (var sibling in siblings)
+ sibling.SizePercentage += resizePercentage / siblings.Count();
+ }
+
+ _containerService.SplitContainersToRedraw.Add(parent);
+ _bus.Invoke(new RedrawContainersCommand());
- throw new NotImplementedException();
+ return new CommandResponse(true, focusedWindow.Id);
}
}
}