Skip to content

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

feat(domain): progress on parsing polymorphic bar component configs

Lars Bergerdb7301c94c76
diff --git a/GlazeWM.Domain/UserConfigs/BarComponentConfig.cs b/GlazeWM.Domain/UserConfigs/BarComponentConfig.cs
index 53dbf61c..ce803b67 100644
--- a/GlazeWM.Domain/UserConfigs/BarComponentConfig.cs
+++ b/GlazeWM.Domain/UserConfigs/BarComponentConfig.cs
@@ -1,3 +1,4 @@
+using System;
using System.ComponentModel.DataAnnotations;
namespace GlazeWM.Domain.UserConfigs
@@ -8,5 +9,30 @@ namespace GlazeWM.Domain.UserConfigs
public string Type { get; set; }
public string Margin { get; set; } = "0 10 0 0";
+
+ public string TimeFormatting { get; set; }
+
+ /// <summary>
+ /// The YAML parsing library doesn't have proper support for polymorphic objects. Therefore,
+ /// a base class with all properties of derived classes is needed, which is then upcasted into
+ /// the correct type.
+ /// </summary>
+ public BarComponentConfig Upcast()
+ {
+ switch (Type)
+ {
+ case "workspaces":
+ return new WorkspacesComponentConfig();
+
+ case "clock":
+ return new ClockComponentConfig
+ {
+ TimeFormatting = TimeFormatting,
+ };
+
+ default:
+ throw new ArgumentException();
+ }
+ }
}
}
diff --git a/GlazeWM.Domain/UserConfigs/BarConfig.cs b/GlazeWM.Domain/UserConfigs/BarConfig.cs
index 2df0abea..c7691d2a 100644
--- a/GlazeWM.Domain/UserConfigs/BarConfig.cs
+++ b/GlazeWM.Domain/UserConfigs/BarConfig.cs
@@ -1,4 +1,5 @@
using System.Collections.Generic;
+using System.Linq;
namespace GlazeWM.Domain.UserConfigs
{
@@ -8,23 +9,15 @@ namespace GlazeWM.Domain.UserConfigs
public double Opacity { get; set; } = 0.9;
- public List<BarComponentConfig> ComponentsLeft = CreateMockComponentConfig();
- public List<BarComponentConfig> ComponentsCenter = new List<BarComponentConfig>();
- public List<BarComponentConfig> ComponentsRight = CreateMockComponentConfig();
-
- private static List<BarComponentConfig> CreateMockComponentConfig()
+ List<BarComponentConfig> _componentsLeft;
+ public List<BarComponentConfig> ComponentsLeft
{
- var sampleConfig1 = new WorkspacesComponentConfig()
- {
- Type = "workspaces",
- };
+ get { return _componentsLeft; }
+ set { _componentsLeft = value.Select(configs => configs.Upcast()).ToList(); }
+ }
- var sampleConfig2 = new ClockComponentConfig()
- {
- Type = "clock",
- };
+ public List<BarComponentConfig> ComponentsCenter { get; set; } = new List<BarComponentConfig>();
- return new List<BarComponentConfig> { sampleConfig1, sampleConfig2 };
- }
+ public List<BarComponentConfig> ComponentsRight { get; set; } = new List<BarComponentConfig>();
}
}
diff --git a/GlazeWM.Domain/UserConfigs/ClockComponentConfig.cs b/GlazeWM.Domain/UserConfigs/ClockComponentConfig.cs
index f7f6ffdf..d8b05c1d 100644
--- a/GlazeWM.Domain/UserConfigs/ClockComponentConfig.cs
+++ b/GlazeWM.Domain/UserConfigs/ClockComponentConfig.cs
@@ -2,5 +2,6 @@ namespace GlazeWM.Domain.UserConfigs
{
public class ClockComponentConfig : BarComponentConfig
{
+ public new string TimeFormatting { get; set; }
}
}