GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat: add customizable separator between bar components (#218)
Aryaman Maratheab3411016ee2
diff --git a/GlazeWM.Bar/BarViewModel.cs b/GlazeWM.Bar/BarViewModel.csindex 79ac9bb7..b758859f 100644--- a/GlazeWM.Bar/BarViewModel.cs+++ b/GlazeWM.Bar/BarViewModel.cs@@ -5,6 +5,7 @@ using GlazeWM.Bar.Common;using GlazeWM.Bar.Components;using GlazeWM.Domain.Monitors;using GlazeWM.Domain.UserConfigs;+using GlazeWM.Infrastructure.Utils;namespace GlazeWM.Bar{@@ -25,20 +26,51 @@ namespace GlazeWM.Barpublic string Padding => XamlHelper.FormatRectShorthand(BarConfig.Padding);public double Opacity => BarConfig.Opacity;+ private TextComponentViewModel _componentSeparatorLeft => new(+ this, new TextComponentConfig+ {+ Text = BarConfig.ComponentSeparator.LabelLeft+ ?? BarConfig.ComponentSeparator.Label+ }+ );++ private TextComponentViewModel _componentSeparatorCenter => new(+ this, new TextComponentConfig+ {+ Text = BarConfig.ComponentSeparator.LabelCenter+ ?? BarConfig.ComponentSeparator.Label+ }+ );++ private TextComponentViewModel _componentSeparatorRight => new(+ this, new TextComponentConfig+ {+ Text = BarConfig.ComponentSeparator.LabelRight+ ?? BarConfig.ComponentSeparator.Label+ }+ );+public List<ComponentViewModel> ComponentsLeft =>- CreateComponentViewModels(BarConfig.ComponentsLeft);+ InsertComponentSeparator(+ CreateComponentViewModels(BarConfig.ComponentsLeft),+ _componentSeparatorLeft);public List<ComponentViewModel> ComponentsCenter =>- CreateComponentViewModels(BarConfig.ComponentsCenter);+ InsertComponentSeparator(+ CreateComponentViewModels(BarConfig.ComponentsRight),+ _componentSeparatorCenter);public List<ComponentViewModel> ComponentsRight =>- CreateComponentViewModels(BarConfig.ComponentsRight);+ InsertComponentSeparator(+ CreateComponentViewModels(BarConfig.ComponentsRight),+ _componentSeparatorRight);- public BarViewModel(Monitor monitor, Dispatcher dispatcher, BarConfig barConfig)+ private static List<ComponentViewModel> InsertComponentSeparator(+ List<ComponentViewModel> componentViewModels, TextComponentViewModel componentSeparator+ ){- Monitor = monitor;- Dispatcher = dispatcher;- BarConfig = barConfig;+ componentViewModels.Intersperse(componentSeparator);+ return componentViewModels;}private List<ComponentViewModel> CreateComponentViewModels(@@ -56,5 +88,12 @@ namespace GlazeWM.Bar_ => throw new ArgumentOutOfRangeException(nameof(config)),});}++ public BarViewModel(Monitor monitor, Dispatcher dispatcher, BarConfig barConfig)+ {+ Monitor = monitor;+ Dispatcher = dispatcher;+ BarConfig = barConfig;+ }}}diff --git a/GlazeWM.Bar/MainWindow.xaml.cs b/GlazeWM.Bar/MainWindow.xaml.csindex 351dffd3..e1b3b8c4 100644--- a/GlazeWM.Bar/MainWindow.xaml.cs+++ b/GlazeWM.Bar/MainWindow.xaml.cs@@ -19,9 +19,6 @@ namespace GlazeWM.Barpublic partial class MainWindow : Window{private readonly Bus _bus = ServiceLocator.GetRequiredService<Bus>();- private readonly UserConfigService _userConfigService =- ServiceLocator.GetRequiredService<UserConfigService>();-private BarViewModel _barViewModel { get; }private Dispatcher _dispatcher => _barViewModel.Dispatcher;private Monitor _monitor => _barViewModel.Monitor;diff --git a/GlazeWM.Bootstrapper/sample-config.yaml b/GlazeWM.Bootstrapper/sample-config.yamlindex a1a8237b..aff190e6 100644--- a/GlazeWM.Bootstrapper/sample-config.yaml+++ b/GlazeWM.Bootstrapper/sample-config.yaml@@ -16,6 +16,8 @@ bar:font_family: "Segoe UI"font_size: "13px"padding: "4px 6px"+ component_separator:+ label: " | "components_left:- type: "workspaces"focused_workspace_background: "#ffffff33"diff --git a/GlazeWM.Domain/UserConfigs/BarComponentSeparatorConfig.cs b/GlazeWM.Domain/UserConfigs/BarComponentSeparatorConfig.csnew file mode 100755index 00000000..b2e72480--- /dev/null+++ b/GlazeWM.Domain/UserConfigs/BarComponentSeparatorConfig.cs@@ -0,0 +1,10 @@+namespace GlazeWM.Domain.UserConfigs+{+ public class BarComponentSeparatorConfig+ {+ public string Label { get; set; } = "";+ public string LabelLeft { get; set; } = "";+ public string LabelCenter { get; set; } = "";+ public string LabelRight { get; set; } = "";+ }+}diff --git a/GlazeWM.Domain/UserConfigs/BarConfig.cs b/GlazeWM.Domain/UserConfigs/BarConfig.csindex 7a5aca5d..de28d45f 100644--- a/GlazeWM.Domain/UserConfigs/BarConfig.cs+++ b/GlazeWM.Domain/UserConfigs/BarConfig.cs@@ -22,6 +22,8 @@ namespace GlazeWM.Domain.UserConfigspublic string BorderColor { get; set; } = "blue";+ public BarComponentSeparatorConfig ComponentSeparator { get; set; } = new();+/// <summary>/// Width of the border in pixels. To set a different border width for each side, specify four/// values (eg. "5 0 5 0"). The borders widths apply to the top, right, bottom, and left in thatdiff --git a/GlazeWM.Infrastructure/Utils/ListExtensions.cs b/GlazeWM.Infrastructure/Utils/ListExtensions.csindex b1d1c992..762d6982 100644--- a/GlazeWM.Infrastructure/Utils/ListExtensions.cs+++ b/GlazeWM.Infrastructure/Utils/ListExtensions.cs@@ -35,5 +35,16 @@ namespace GlazeWM.Infrastructure.Utils{ShiftToIndex(source, 0, value);}++ /// <summary>+ /// Insert a value between each element of a list.+ /// </summary>+ public static void Intersperse<T>(this IList<T> source, T value)+ {+ for (var i = 1; i < source.Count; i += 2)+ {+ source.Insert(i, value);+ }+ }}}diff --git a/README.md b/README.mdindex 14c2a319..54cb6fc2 100644--- a/README.md+++ b/README.md@@ -154,6 +154,15 @@ bar:# "Shorthand properties" for more info.padding: "1 6 1 6"+ # Separators between components within the bar. label is used for each section+ # of the bar unless label_{left,centre,right} are explictly set, in which case+ # they are preferred over default.+ component_separators:+ label: " | "+ # label_left: ""+ # label_center: ""+ # label_right: ""+# Components to display on the left side of the bar.components_left:- type: "workspaces"@@ -246,9 +255,9 @@ There are three labels available that can be customized:**Example usage:**```yaml- type: "battery"- draining: " {battery_level}% remaining "- power_saver: " {battery_level}% (power saver) "- charging: " {battery_level}% (charging) "+ draining: "{battery_level}% remaining"+ power_saver: "{battery_level}% (power saver)"+ charging: "{battery_level}% (charging)"```## Window rules