GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat(domain,ipc): change `Container.Id` to guid; change `Container.Type` to enum
Lars Berger155f89a2d1d6
diff --git a/GlazeWM.App.IpcServer/IpcMessageHandler.cs b/GlazeWM.App.IpcServer/IpcMessageHandler.csindex a9435a8f..97b59fb4 100644--- a/GlazeWM.App.IpcServer/IpcMessageHandler.cs+++ b/GlazeWM.App.IpcServer/IpcMessageHandler.cs@@ -118,7 +118,7 @@ namespace GlazeWM.App.IpcServerprivate bool? HandleInvokeCommandMessage(InvokeCommandMessage message){var contextContainer =- _containerService.GetContainerById(message.ContextContainerId) ??+ _containerService.GetContainerById(Guid.Parse(message.ContextContainerId)) ??_containerService.FocusedContainer;var commandString = CommandParsingService.FormatCommand(message.Command);diff --git a/GlazeWM.Domain/Common/ContainerType.cs b/GlazeWM.Domain/Common/ContainerType.csnew file mode 100644index 00000000..3e4a5971--- /dev/null+++ b/GlazeWM.Domain/Common/ContainerType.cs@@ -0,0 +1,11 @@+namespace GlazeWM.Domain.Common+{+ public enum ContainerType+ {+ Root,+ Monitor,+ Workspace,+ Split,+ Window,+ }+}diff --git a/GlazeWM.Domain/Containers/Container.cs b/GlazeWM.Domain/Containers/Container.csindex 4a9fa4dd..cfbb91fd 100644--- a/GlazeWM.Domain/Containers/Container.cs+++ b/GlazeWM.Domain/Containers/Container.cs@@ -1,7 +1,7 @@using System;using System.Collections.Generic;using System.Linq;-using GlazeWM.Infrastructure.Utils;+using GlazeWM.Domain.Common;using GlazeWM.Infrastructure.WindowsApi;namespace GlazeWM.Domain.Containers@@ -9,14 +9,20 @@ namespace GlazeWM.Domain.Containerspublic abstract class Container{/// <summary>- /// A unique identifier for the particular container. Implementation varies between container- /// types (eg. windows use their handle, whereas monitors use device name).+ /// A unique identifier for the container./// </summary>- public abstract string Id { get; init; }+ public Guid Id { get; } = Guid.NewGuid();++ /// <summary>+ /// Derived container type (eg. `ContainerType.Monitor`).+ /// </summary>+ public abstract ContainerType Type { get; }+public virtual int Height { get; set; }public virtual int Width { get; set; }public virtual int X { get; set; }public virtual int Y { get; set; }+public Container Parent { get; set; }public List<Container> Children { get; set; } = new List<Container>();@@ -44,12 +50,6 @@ namespace GlazeWM.Domain.Containers/// </summary>public int Index => Parent.Children.IndexOf(this);- /// <summary>- /// Friendly name of the derived container type (eg. `workspace`). For CLI and IPC- /// usage.- /// </summary>- public string Type => CasingUtil.PascalToSnake(GetType().Name);-/// <summary>/// Get the last focused descendant by traversing downwards./// </summary>diff --git a/GlazeWM.Domain/Containers/ContainerService.cs b/GlazeWM.Domain/Containers/ContainerService.csindex 9914c308..0e338a22 100644--- a/GlazeWM.Domain/Containers/ContainerService.cs+++ b/GlazeWM.Domain/Containers/ContainerService.cs@@ -51,7 +51,7 @@ namespace GlazeWM.Domain.Containers_userConfigService = userConfigService;}- public Container GetContainerById(string id)+ public Container GetContainerById(Guid id){return ContainerTree.SelfAndDescendants.FirstOrDefault(container => container.Id == id);}diff --git a/GlazeWM.Domain/Containers/JsonContainerConverter.cs b/GlazeWM.Domain/Containers/JsonContainerConverter.csindex 91b8a863..c7bd5939 100644--- a/GlazeWM.Domain/Containers/JsonContainerConverter.cs+++ b/GlazeWM.Domain/Containers/JsonContainerConverter.cs@@ -73,7 +73,8 @@ namespace GlazeWM.Domain.Containerswriter.WriteNumber(JsonParser.ChangeCasing("Y", options), value.Y);writer.WriteNumber(JsonParser.ChangeCasing("Width", options), value.Width);writer.WriteNumber(JsonParser.ChangeCasing("Height", options), value.Height);- writer.WriteString(JsonParser.ChangeCasing("Type", options), value.Type);+ writer.WritePropertyName(JsonParser.ChangeCasing("Type", options));+ JsonSerializer.Serialize(writer, value.Type, options);writer.WriteNumber(JsonParser.ChangeCasing("FocusIndex", options),value.FocusIndexdiff --git a/GlazeWM.Domain/Containers/RootContainer.cs b/GlazeWM.Domain/Containers/RootContainer.csindex 1076dc0c..8a3add5f 100644--- a/GlazeWM.Domain/Containers/RootContainer.cs+++ b/GlazeWM.Domain/Containers/RootContainer.cs@@ -1,9 +1,10 @@-using System;+using GlazeWM.Domain.Common;namespace GlazeWM.Domain.Containers{public sealed class RootContainer : Container{- public override string Id { get; init; } = $"root_container/{new Guid()}";+ /// <inheritdoc />+ public override ContainerType Type { get; } = ContainerType.Root;}}diff --git a/GlazeWM.Domain/Containers/SplitContainer.cs b/GlazeWM.Domain/Containers/SplitContainer.csindex b08d4392..e3fab625 100644--- a/GlazeWM.Domain/Containers/SplitContainer.cs+++ b/GlazeWM.Domain/Containers/SplitContainer.cs@@ -1,4 +1,4 @@-using System;+using GlazeWM.Domain.Common;using GlazeWM.Domain.Common.Enums;using GlazeWM.Infrastructure;@@ -6,7 +6,9 @@ namespace GlazeWM.Domain.Containers{public class SplitContainer : Container, IResizable{- public override string Id { get; init; } = $"split_container/{new Guid()}";+ /// <inheritdoc />+ public override ContainerType Type { get; } = ContainerType.Split;+public Layout Layout { get; set; } = Layout.Horizontal;public double SizePercentage { get; set; } = 1;diff --git a/GlazeWM.Domain/Monitors/Monitor.cs b/GlazeWM.Domain/Monitors/Monitor.csindex b0398d28..75b94020 100644--- a/GlazeWM.Domain/Monitors/Monitor.cs+++ b/GlazeWM.Domain/Monitors/Monitor.cs@@ -1,3 +1,4 @@+using GlazeWM.Domain.Common;using GlazeWM.Domain.Containers;using GlazeWM.Domain.Workspaces;@@ -5,7 +6,9 @@ namespace GlazeWM.Domain.Monitors{public sealed class Monitor : Container{- public override string Id { get; init; }+ /// <inheritdoc />+ public override ContainerType Type { get; } = ContainerType.Monitor;+public string DeviceName { get; set; }public override int Width { get; set; }public override int Height { get; set; }@@ -16,14 +19,8 @@ namespace GlazeWM.Domain.Monitorspublic uint Dpi => MonitorService.GetMonitorDpi(this);public double ScaleFactor => Dpi / 96.0;- public Monitor(- string deviceName,- int width,- int height,- int x,- int y)+ public Monitor(string deviceName, int width, int height, int x, int y){- Id = $"monitor/{deviceName}";DeviceName = deviceName;Width = width;Height = height;diff --git a/GlazeWM.Domain/Windows/Window.cs b/GlazeWM.Domain/Windows/Window.csindex b7024504..7f605fc6 100644--- a/GlazeWM.Domain/Windows/Window.cs+++ b/GlazeWM.Domain/Windows/Window.cs@@ -1,4 +1,5 @@using System;+using GlazeWM.Domain.Common;using GlazeWM.Domain.Containers;using GlazeWM.Domain.Workspaces;using GlazeWM.Infrastructure.WindowsApi;@@ -8,7 +9,9 @@ namespace GlazeWM.Domain.Windows{public abstract class Window : Container{- public override string Id { get; init; }+ /// <inheritdoc />+ public override ContainerType Type { get; } = ContainerType.Window;+public IntPtr Handle { get; }/// <summary>@@ -31,7 +34,6 @@ namespace GlazeWM.Domain.Windowsprotected Window(IntPtr handle, Rect floatingPlacement, RectDelta borderDelta){- Id = $"window/{handle}";Handle = handle;FloatingPlacement = floatingPlacement;BorderDelta = borderDelta;diff --git a/GlazeWM.Domain/Workspaces/Workspace.cs b/GlazeWM.Domain/Workspaces/Workspace.csindex 376fe240..63ac9986 100644--- a/GlazeWM.Domain/Workspaces/Workspace.cs+++ b/GlazeWM.Domain/Workspaces/Workspace.cs@@ -1,4 +1,5 @@using System;+using GlazeWM.Domain.Common;using GlazeWM.Domain.Common.Enums;using GlazeWM.Domain.Containers;using GlazeWM.Domain.Monitors;@@ -11,7 +12,9 @@ namespace GlazeWM.Domain.Workspaces{public sealed class Workspace : SplitContainer{- public override string Id { get; init; }+ /// <inheritdoc />+ public override ContainerType Type { get; } = ContainerType.Workspace;+public string Name { get; set; }private readonly UserConfigService _userConfigService =@@ -93,7 +96,6 @@ namespace GlazeWM.Domain.Workspacespublic Workspace(string name, Layout layout){Layout = layout;- Id = $"workspace/{name}";Name = name;}}