Skip to content

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

feat(bar): conditionally show data template based on component config type

Lars Bergerefe50b1b586e
diff --git a/GlazeWM.Bar/BarViewModel.cs b/GlazeWM.Bar/BarViewModel.cs
index ca3f8282..532925c4 100644
--- a/GlazeWM.Bar/BarViewModel.cs
+++ b/GlazeWM.Bar/BarViewModel.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
@@ -20,6 +21,9 @@ namespace GlazeWM.Bar
public string BorderWidth { get; set; }
public string Padding { get; set; }
public double Opacity { get; set; }
+ public List<BarComponentConfig> ComponentsLeft { get; set; }
+ public List<BarComponentConfig> ComponentsCenter { get; set; }
+ public List<BarComponentConfig> ComponentsRight { get; set; }
private readonly Dispatcher _dispatcher;
private readonly Monitor _monitor;
private readonly BarConfig _barConfig;
@@ -40,6 +44,9 @@ namespace GlazeWM.Bar
BorderWidth = ShorthandToXamlProperty(_barConfig.BorderWidth);
Padding = ShorthandToXamlProperty(_barConfig.Padding);
Opacity = _barConfig.Opacity;
+ ComponentsLeft = _barConfig.ComponentsLeft;
+ ComponentsCenter = _barConfig.ComponentsCenter;
+ ComponentsRight = _barConfig.ComponentsRight;
UpdateWorkspaces();
}
diff --git a/GlazeWM.Bar/MainWindow.xaml b/GlazeWM.Bar/MainWindow.xaml
index 11380c17..a500a942 100644
--- a/GlazeWM.Bar/MainWindow.xaml
+++ b/GlazeWM.Bar/MainWindow.xaml
@@ -5,6 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:GlazeWM.Bar"
+ xmlns:domain="clr-namespace:GlazeWM.Domain.UserConfigs;assembly=GlazeWM.Domain"
mc:Ignorable="d"
WindowStyle="None"
ResizeMode="NoResize"
@@ -22,7 +23,7 @@
BorderThickness="{Binding BorderWidth}"
BorderBrush="{Binding BorderColor}">
<DockPanel Margin="{Binding Padding}">
- <ItemsControl ItemsSource="{Binding Workspaces}">
+ <ItemsControl ItemsSource="{Binding ComponentsLeft}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid
@@ -32,39 +33,20 @@
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
- <ItemsControl.ItemTemplate>
- <DataTemplate>
- <Button
- x:Name="WorkspaceButton"
- Click="OnWorkspaceButtonClick"
- Content="{Binding Name}"
- Background="#242424"
- Foreground="White"
- BorderBrush="Transparent"
- BorderThickness="0"
- MinWidth="{Binding ActualHeight, RelativeSource={RelativeSource Self}}"
- MinHeight="{Binding ActualWidth, RelativeSource={RelativeSource Self}}" />
-
- <DataTemplate.Triggers>
- <DataTrigger
- Binding="{Binding IsDisplayed}"
- Value="True">
- <Setter
- TargetName="WorkspaceButton"
- Property="Background"
- Value="#42403e" />
- </DataTrigger>
- <DataTrigger
- Binding="{Binding HasFocus}"
- Value="True">
- <Setter
- TargetName="WorkspaceButton"
- Property="Background"
- Value="#8192B3" />
- </DataTrigger>
- </DataTemplate.Triggers>
+ <ItemsControl.Resources>
+ <DataTemplate DataType="{x:Type domain:WorkspacesComponentConfig}">
+ <Rectangle
+ Width="50"
+ Height="50"
+ Fill="Red" />
+ </DataTemplate>
+ <DataTemplate DataType="{x:Type domain:ClockComponentConfig}">
+ <Rectangle
+ Width="50"
+ Height="50"
+ Fill="Blue" />
</DataTemplate>
- </ItemsControl.ItemTemplate>
+ </ItemsControl.Resources>
</ItemsControl>
</DockPanel>
</Border>