Skip to content

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

refactor(domain): create `RootContainer` for representing the root node of container tree

Lars Berger0790d437ccfa
diff --git a/GlazeWM.Domain/Containers/ContainerService.cs b/GlazeWM.Domain/Containers/ContainerService.cs
index 807df875..2d3cbcba 100644
--- a/GlazeWM.Domain/Containers/ContainerService.cs
+++ b/GlazeWM.Domain/Containers/ContainerService.cs
@@ -13,7 +13,7 @@ namespace GlazeWM.Domain.Containers
/// The root node of the container tree. Monitors are the children of the root node, followed
/// by workspaces, then split containers/windows.
/// </summary>
- public Container ContainerTree = new();
+ public RootContainer ContainerTree = new();
/// <summary>
/// Containers (and their descendants) to redraw on the next invocation of
diff --git a/GlazeWM.Domain/Containers/RootContainer.cs b/GlazeWM.Domain/Containers/RootContainer.cs
new file mode 100644
index 00000000..3281e06a
--- /dev/null
+++ b/GlazeWM.Domain/Containers/RootContainer.cs
@@ -0,0 +1,6 @@
+namespace GlazeWM.Domain.Containers
+{
+ public sealed class RootContainer : Container
+ {
+ }
+}
diff --git a/GlazeWM.Domain/JsonContainerConverter.cs b/GlazeWM.Domain/JsonContainerConverter.cs
index fbfda779..4b5498fd 100644
--- a/GlazeWM.Domain/JsonContainerConverter.cs
+++ b/GlazeWM.Domain/JsonContainerConverter.cs
@@ -13,6 +13,11 @@ namespace GlazeWM.Domain.Containers
{
public class JsonContainerConverter : JsonConverter<Container>
{
+ public override bool CanConvert(Type typeToConvert)
+ {
+ return typeof(Container).IsAssignableFrom(typeToConvert);
+ }
+
public override Container Read(
ref Utf8JsonReader reader,
Type typeToConvert,
@@ -31,9 +36,9 @@ namespace GlazeWM.Domain.Containers
// Get the type of container (eg. "Workspace", "MinimizedWindow").
var typeDiscriminator = jsonObject.GetProperty("__type").ToString();
- var newContainer = typeDiscriminator switch
+ Container newContainer = typeDiscriminator switch
{
- "Container" => new Container(),
+ "RootContainer" => new RootContainer(),
"Monitor" => new Monitor(
jsonObject.GetProperty("DeviceName").GetString(),
jsonObject.GetProperty("Width").GetInt32(),
@@ -103,7 +108,7 @@ namespace GlazeWM.Domain.Containers
writer.WriteString("__type", value.GetType().Name);
// Handle focus index for root container.
- var focusIndex = value.Parent is not null ? value.FocusIndex : 0;
+ var focusIndex = value is RootContainer ? 0 : value.FocusIndex;
writer.WriteNumber("FocusIndex", focusIndex);
switch (value)