Skip to content

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

feat(bar): handle fallbacks to root bar config for certain component config properties

Lars Bergercd227755b973
diff --git a/GlazeWM.Bar/Components/ClockComponentViewModel.cs b/GlazeWM.Bar/Components/ClockComponentViewModel.cs
index 4fdfdfd3..83ac04fb 100644
--- a/GlazeWM.Bar/Components/ClockComponentViewModel.cs
+++ b/GlazeWM.Bar/Components/ClockComponentViewModel.cs
@@ -7,7 +7,7 @@ namespace GlazeWM.Bar.Components
{
public class ClockComponentViewModel : ComponentViewModel
{
- private ClockComponentConfig _config => _baseConfig as ClockComponentConfig;
+ private ClockComponentConfig _config => _componentConfig as ClockComponentConfig;
private string _timeFormatting => _config.TimeFormatting;
/// <summary>
diff --git a/GlazeWM.Bar/Components/ComponentViewModel.cs b/GlazeWM.Bar/Components/ComponentViewModel.cs
index f2832856..97e884b3 100644
--- a/GlazeWM.Bar/Components/ComponentViewModel.cs
+++ b/GlazeWM.Bar/Components/ComponentViewModel.cs
@@ -7,21 +7,22 @@ namespace GlazeWM.Bar.Components
{
public class ComponentViewModel : ViewModelBase
{
- private BarService _barService = ServiceLocator.Provider.GetRequiredService<BarService>();
protected readonly BarViewModel _parentViewModel;
- public readonly BarComponentConfig _baseConfig;
- public string Background => _baseConfig.Background;
- public string FontFamily => _baseConfig.FontFamily;
- public string FontSize => _baseConfig.FontSize;
- public string BorderColor => _baseConfig.BorderColor;
- public string BorderWidth => _barService.ShorthandToXamlProperty(_baseConfig.BorderWidth);
- public string Padding => _barService.ShorthandToXamlProperty(_baseConfig.Padding);
- public string Margin => _barService.ShorthandToXamlProperty(_baseConfig.Margin);
+ protected readonly BarComponentConfig _componentConfig;
+ protected readonly BarService _barService = ServiceLocator.Provider.GetRequiredService<BarService>();
+
+ public string Background => _componentConfig.Background ?? _parentViewModel.Background;
+ public string FontFamily => _componentConfig.FontFamily ?? _parentViewModel.FontFamily;
+ public string FontSize => _componentConfig.FontSize ?? _parentViewModel.FontSize;
+ public string BorderColor => _componentConfig.BorderColor;
+ public string BorderWidth => _barService.ShorthandToXamlProperty(_componentConfig.BorderWidth);
+ public string Padding => _barService.ShorthandToXamlProperty(_componentConfig.Padding);
+ public string Margin => _barService.ShorthandToXamlProperty(_componentConfig.Margin);
public ComponentViewModel(BarViewModel parentViewModel, BarComponentConfig baseConfig)
{
_parentViewModel = parentViewModel;
- _baseConfig = baseConfig;
+ _componentConfig = baseConfig;
}
}
}
diff --git a/GlazeWM.Bar/Components/WorkspacesComponent.xaml b/GlazeWM.Bar/Components/WorkspacesComponent.xaml
index 6f2a4cf5..f1caff07 100644
--- a/GlazeWM.Bar/Components/WorkspacesComponent.xaml
+++ b/GlazeWM.Bar/Components/WorkspacesComponent.xaml
@@ -19,9 +19,9 @@
<Button
x:Name="WorkspaceButton"
Content="{Binding Name}"
- Background="{Binding DataContext.Config.DefaultWorkspaceBackground, ElementName=Self}"
- Foreground="{Binding DataContext.Config.DefaultWorkspaceForeground, ElementName=Self}"
- BorderBrush="{Binding DataContext.Config.DefaultWorkspaceBorderColor, ElementName=Self}"
+ Background="{Binding DataContext.DefaultWorkspaceBackground, ElementName=Self}"
+ Foreground="{Binding DataContext.DefaultWorkspaceForeground, ElementName=Self}"
+ BorderBrush="{Binding DataContext.DefaultWorkspaceBorderColor, ElementName=Self}"
BorderThickness="0"
Cursor="Hand"
MinWidth="{Binding ActualHeight, RelativeSource={RelativeSource Self}}"
@@ -34,15 +34,15 @@
<Setter
TargetName="WorkspaceButton"
Property="Background"
- Value="{Binding DataContext.Config.DisplayedWorkspaceBackground, ElementName=Self}" />
+ Value="{Binding DataContext.DisplayedWorkspaceBackground, ElementName=Self}" />
<Setter
TargetName="WorkspaceButton"
Property="Foreground"
- Value="{Binding DataContext.Config.DisplayedWorkspaceForeground, ElementName=Self}" />
+ Value="{Binding DataContext.DisplayedWorkspaceForeground, ElementName=Self}" />
<Setter
TargetName="WorkspaceButton"
Property="BorderBrush"
- Value="{Binding DataContext.Config.DisplayedWorkspaceBorderColor, ElementName=Self}" />
+ Value="{Binding DataContext.DisplayedWorkspaceBorderColor, ElementName=Self}" />
<Setter
TargetName="WorkspaceButton"
Property="BorderThickness"
@@ -55,15 +55,15 @@
<Setter
TargetName="WorkspaceButton"
Property="Background"
- Value="{Binding DataContext.Config.FocusedWorkspaceBackground, ElementName=Self}" />
+ Value="{Binding DataContext.FocusedWorkspaceBackground, ElementName=Self}" />
<Setter
TargetName="WorkspaceButton"
Property="Foreground"
- Value="{Binding DataContext.Config.FocusedWorkspaceForeground, ElementName=Self}" />
+ Value="{Binding DataContext.FocusedWorkspaceForeground, ElementName=Self}" />
<Setter
TargetName="WorkspaceButton"
Property="BorderBrush"
- Value="{Binding DataContext.Config.FocusedWorkspaceBorderColor, ElementName=Self}" />
+ Value="{Binding DataContext.FocusedWorkspaceBorderColor, ElementName=Self}" />
<Setter
TargetName="WorkspaceButton"
Property="BorderThickness"
diff --git a/GlazeWM.Bar/Components/WorkspacesComponentViewModel.cs b/GlazeWM.Bar/Components/WorkspacesComponentViewModel.cs
index 546c540a..2d8e9ea7 100644
--- a/GlazeWM.Bar/Components/WorkspacesComponentViewModel.cs
+++ b/GlazeWM.Bar/Components/WorkspacesComponentViewModel.cs
@@ -16,14 +16,29 @@ namespace GlazeWM.Bar.Components
{
public class WorkspacesComponentViewModel : ComponentViewModel
{
- public WorkspacesComponentConfig Config => _baseConfig as WorkspacesComponentConfig;
- private Bus _bus = ServiceLocator.Provider.GetRequiredService<Bus>();
private Dispatcher _dispatcher => _parentViewModel.Dispatcher;
private Monitor _monitor => _parentViewModel.Monitor;
+ private WorkspacesComponentConfig _config => _componentConfig as WorkspacesComponentConfig;
+ private readonly Bus _bus = ServiceLocator.Provider.GetRequiredService<Bus>();
public ObservableCollection<Workspace> Workspaces =>
new ObservableCollection<Workspace>(_monitor.Children.Cast<Workspace>());
+ public string FocusedWorkspaceBorderWidth => _config.FocusedWorkspaceBorderWidth;
+ public string FocusedWorkspaceBorderColor => _config.FocusedWorkspaceBorderColor;
+ public string FocusedWorkspaceBackground => _config.FocusedWorkspaceBackground;
+ public string FocusedWorkspaceForeground => _config.FocusedWorkspaceForeground;
+
+ public string DisplayedWorkspaceBorderWidth => _config.DisplayedWorkspaceBorderWidth;
+ public string DisplayedWorkspaceBorderColor => _config.DisplayedWorkspaceBorderColor;
+ public string DisplayedWorkspaceBackground => _config.DisplayedWorkspaceBackground;
+ public string DisplayedWorkspaceForeground => _config.DisplayedWorkspaceForeground;
+
+ public string DefaultWorkspaceBorderWidth => _config.DefaultWorkspaceBorderWidth;
+ public string DefaultWorkspaceBorderColor => _config.DefaultWorkspaceBorderColor;
+ public string DefaultWorkspaceBackground => _config.DefaultWorkspaceBackground ?? Background;
+ public string DefaultWorkspaceForeground => _config.DefaultWorkspaceForeground;
+
public WorkspacesComponentViewModel(BarViewModel parentViewModel, WorkspacesComponentConfig config) : base(parentViewModel, config)
{
var workspacesChangedEvent = _bus.Events.Where((@event) =>