Skip to content

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

feat: add image bar component (#323)

blam19da71743093
diff --git a/GlazeWM.Bar/BarViewModel.cs b/GlazeWM.Bar/BarViewModel.cs
index 9b5bfa07..84ccd8e5 100644
--- a/GlazeWM.Bar/BarViewModel.cs
+++ b/GlazeWM.Bar/BarViewModel.cs
@@ -105,6 +105,7 @@ namespace GlazeWM.Bar
WorkspacesComponentConfig wcc => new WorkspacesComponentViewModel(this, wcc),
WindowTitleComponentConfig wtcc => new WindowTitleComponentViewModel(this, wtcc),
VolumeComponentConfig vcc => new VolumeComponentViewModel(this, vcc),
+ ImageComponentConfig bscc => new ImageComponentViewModel(this, bscc),
SystemTrayComponentConfig stcc => new SystemTrayComponentViewModel(this, stcc),
CpuComponentConfig cpupc => new CpuComponentViewModel(this, cpupc),
GpuComponentConfig gpupc => new GpuComponentViewModel(this, gpupc),
diff --git a/GlazeWM.Bar/Components/ComponentPortal.xaml b/GlazeWM.Bar/Components/ComponentPortal.xaml
index 6b36b65d..48434851 100644
--- a/GlazeWM.Bar/Components/ComponentPortal.xaml
+++ b/GlazeWM.Bar/Components/ComponentPortal.xaml
@@ -61,6 +61,10 @@
Padding="{Binding Padding}"
Background="{Binding Background}" />
</DataTemplate>
+ <DataTemplate DataType="{x:Type components:ImageComponentViewModel}">
+ <components:ImageComponent
+ Padding="{Binding Padding}"
+ Background="{Binding Background}" />
<DataTemplate DataType="{x:Type components:CpuComponentViewModel}">
<components:CpuComponent
Padding="{Binding Padding}"
diff --git a/GlazeWM.Bar/Components/ImageComponent.xaml b/GlazeWM.Bar/Components/ImageComponent.xaml
new file mode 100644
index 00000000..fa3e37fd
--- /dev/null
+++ b/GlazeWM.Bar/Components/ImageComponent.xaml
@@ -0,0 +1,10 @@
+<UserControl
+ x:Class="GlazeWM.Bar.Components.ImageComponent"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:local="clr-namespace:GlazeWM.Bar.Components"
+ mc:Ignorable="d">
+ <Image Source="{Binding Source}" />
+</UserControl>
diff --git a/GlazeWM.Bar/Components/ImageComponent.xaml.cs b/GlazeWM.Bar/Components/ImageComponent.xaml.cs
new file mode 100644
index 00000000..55aa005b
--- /dev/null
+++ b/GlazeWM.Bar/Components/ImageComponent.xaml.cs
@@ -0,0 +1,15 @@
+using System.Windows.Controls;
+
+namespace GlazeWM.Bar.Components
+{
+ /// <summary>
+ /// Interaction logic for ImageComponent.xaml
+ /// </summary>
+ public partial class ImageComponent : UserControl
+ {
+ public ImageComponent()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/GlazeWM.Bar/Components/ImageComponentViewModel.cs b/GlazeWM.Bar/Components/ImageComponentViewModel.cs
new file mode 100644
index 00000000..3f8910a3
--- /dev/null
+++ b/GlazeWM.Bar/Components/ImageComponentViewModel.cs
@@ -0,0 +1,17 @@
+using GlazeWM.Domain.UserConfigs;
+
+namespace GlazeWM.Bar.Components
+{
+ public class ImageComponentViewModel : ComponentViewModel
+ {
+ private ImageComponentConfig _config => _componentConfig as ImageComponentConfig;
+
+ public string Source => _config.Source;
+
+ public ImageComponentViewModel(
+ BarViewModel parentViewModel,
+ ImageComponentConfig config) : base(parentViewModel, config)
+ {
+ }
+ }
+}
diff --git a/GlazeWM.Domain/UserConfigs/BarComponentConfigConverter.cs b/GlazeWM.Domain/UserConfigs/BarComponentConfigConverter.cs
index 538b6dc6..7d6e3bf9 100644
--- a/GlazeWM.Domain/UserConfigs/BarComponentConfigConverter.cs
+++ b/GlazeWM.Domain/UserConfigs/BarComponentConfigConverter.cs
@@ -63,6 +63,11 @@ namespace GlazeWM.Domain.UserConfigs
jsonObject.RootElement.ToString(),
options
),
+ "image" =>
+ JsonSerializer.Deserialize<ImageComponentConfig>(
+ jsonObject.RootElement.ToString(),
+ options
+ ),
"weather" =>
JsonSerializer.Deserialize<WeatherComponentConfig>(
jsonObject.RootElement.ToString(),
diff --git a/GlazeWM.Domain/UserConfigs/ImageComponentConfig.cs b/GlazeWM.Domain/UserConfigs/ImageComponentConfig.cs
new file mode 100644
index 00000000..b053dad4
--- /dev/null
+++ b/GlazeWM.Domain/UserConfigs/ImageComponentConfig.cs
@@ -0,0 +1,10 @@
+namespace GlazeWM.Domain.UserConfigs
+{
+ public class ImageComponentConfig : BarComponentConfig
+ {
+ /// <summary>
+ /// Path to image
+ /// </summary>
+ public string Source { get; set; }
+ }
+}