Skip to content

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

feat: tiling direction bar component (#193)

lars-berger6f4bebdde8c4
diff --git a/GlazeWM.Bar/BarViewModel.cs b/GlazeWM.Bar/BarViewModel.cs
index 7d49d129..e193cb3d 100644
--- a/GlazeWM.Bar/BarViewModel.cs
+++ b/GlazeWM.Bar/BarViewModel.cs
@@ -46,6 +46,7 @@ namespace GlazeWM.Bar
BindingModeComponentConfig bmc => new BindingModeComponentViewModel(this, bmc),
ClockComponentConfig ccc => new ClockComponentViewModel(this, ccc),
TextComponentConfig tcc => new TextComponentViewModel(this, tcc),
+ TilingDirectionComponentConfig tdc => new TilingDirectionComponentViewModel(this, tdc),
WorkspacesComponentConfig wcc => new WorkspacesComponentViewModel(this, wcc),
_ => throw new ArgumentOutOfRangeException(nameof(config)),
});
diff --git a/GlazeWM.Bar/Components/ComponentPortal.xaml b/GlazeWM.Bar/Components/ComponentPortal.xaml
index 2542a4ee..2cf75358 100644
--- a/GlazeWM.Bar/Components/ComponentPortal.xaml
+++ b/GlazeWM.Bar/Components/ComponentPortal.xaml
@@ -25,6 +25,9 @@
<DataTemplate DataType="{x:Type components:TextComponentViewModel}">
<components:TextComponent />
</DataTemplate>
+ <DataTemplate DataType="{x:Type components:TilingDirectionComponentViewModel}">
+ <components:TilingDirectionComponent />
+ </DataTemplate>
<DataTemplate DataType="{x:Type components:WorkspacesComponentViewModel}">
<components:WorkspacesComponent />
</DataTemplate>
diff --git a/GlazeWM.Bar/Components/TilingDirectionComponent.xaml b/GlazeWM.Bar/Components/TilingDirectionComponent.xaml
new file mode 100644
index 00000000..1d244c7a
--- /dev/null
+++ b/GlazeWM.Bar/Components/TilingDirectionComponent.xaml
@@ -0,0 +1,16 @@
+<UserControl
+ x:Class="GlazeWM.Bar.Components.TilingDirectionComponent"
+ 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">
+ <TextBlock
+ VerticalAlignment="Center"
+ Foreground="{Binding Foreground}"
+ FontFamily="{Binding FontFamily}"
+ FontWeight="{Binding FontWeight}"
+ FontSize="{Binding FontSize}"
+ Text="{Binding TilingDirectionString}" />
+</UserControl>
diff --git a/GlazeWM.Bar/Components/TilingDirectionComponent.xaml.cs b/GlazeWM.Bar/Components/TilingDirectionComponent.xaml.cs
new file mode 100644
index 00000000..a26d63d0
--- /dev/null
+++ b/GlazeWM.Bar/Components/TilingDirectionComponent.xaml.cs
@@ -0,0 +1,15 @@
+using System.Windows.Controls;
+
+namespace GlazeWM.Bar.Components
+{
+ /// <summary>
+ /// Interaction logic for TilingDirectionComponent.xaml
+ /// </summary>
+ public partial class TilingDirectionComponent : UserControl
+ {
+ public TilingDirectionComponent()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/GlazeWM.Bar/Components/TilingDirectionComponentViewModel.cs b/GlazeWM.Bar/Components/TilingDirectionComponentViewModel.cs
new file mode 100644
index 00000000..1c530c3e
--- /dev/null
+++ b/GlazeWM.Bar/Components/TilingDirectionComponentViewModel.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Reactive.Linq;
+using System.Windows.Threading;
+using GlazeWM.Domain.Common.Enums;
+using GlazeWM.Domain.Containers;
+using GlazeWM.Domain.Containers.Events;
+using GlazeWM.Domain.UserConfigs;
+using GlazeWM.Infrastructure;
+using GlazeWM.Infrastructure.Bussing;
+
+namespace GlazeWM.Bar.Components
+{
+ public class TilingDirectionComponentViewModel : ComponentViewModel
+ {
+ private Dispatcher _dispatcher => _parentViewModel.Dispatcher;
+ private readonly Bus _bus = ServiceLocator.GetRequiredService<Bus>();
+ private readonly ContainerService _containerService =
+ ServiceLocator.GetRequiredService<ContainerService>();
+
+ /// <summary>
+ /// The layout of the currently focused container. Can be null on app startup when
+ /// workspaces haven't been created yet.
+ /// </summary>
+ private Layout? _tilingDirection =>
+ (_containerService.FocusedContainer as SplitContainer)?.Layout ??
+ (_containerService.FocusedContainer.Parent as SplitContainer)?.Layout;
+
+ public string TilingDirectionString =>
+ _tilingDirection == Layout.VERTICAL ? "vertical" : "horizontal";
+
+ public TilingDirectionComponentViewModel(
+ BarViewModel parentViewModel,
+ TilingDirectionComponentConfig config) : base(parentViewModel, config)
+ {
+ _bus.Events.OfType<LayoutChangedEvent>().Subscribe(_ =>
+ _dispatcher.Invoke(() => OnPropertyChanged(nameof(TilingDirectionString)))
+ );
+ }
+ }
+}
diff --git a/GlazeWM.Bootstrapper/sample-config.yaml b/GlazeWM.Bootstrapper/sample-config.yaml
index dc1fe42b..5e721183 100644
--- a/GlazeWM.Bootstrapper/sample-config.yaml
+++ b/GlazeWM.Bootstrapper/sample-config.yaml
@@ -17,6 +17,10 @@ bar:
displayed_workspace_background: "#42403e"
default_workspace_background: "#101010"
components_right:
+ - type: "tiling direction"
+ background: "#ffffff33"
+ margin: "5 5 5 0"
+ padding: "0 5"
- type: "binding mode"
background: "#ffffff33"
margin: "5 5 5 0"
diff --git a/GlazeWM.Domain/Containers/CommandHandlers/ChangeContainerLayoutHandler.cs b/GlazeWM.Domain/Containers/CommandHandlers/ChangeContainerLayoutHandler.cs
index 28c3274b..7e55f4ce 100644
--- a/GlazeWM.Domain/Containers/CommandHandlers/ChangeContainerLayoutHandler.cs
+++ b/GlazeWM.Domain/Containers/CommandHandlers/ChangeContainerLayoutHandler.cs
@@ -1,6 +1,7 @@
using System.Linq;
using GlazeWM.Domain.Common.Enums;
using GlazeWM.Domain.Containers.Commands;
+using GlazeWM.Domain.Containers.Events;
using GlazeWM.Domain.Windows;
using GlazeWM.Domain.Workspaces;
using GlazeWM.Infrastructure.Bussing;
@@ -28,6 +29,8 @@ namespace GlazeWM.Domain.Containers.CommandHandlers
else if (container is Workspace)
ChangeWorkspaceLayout(container as Workspace, newLayout);
+ _bus.Emit(new LayoutChangedEvent(newLayout));
+
return CommandResponse.Ok;
}
diff --git a/GlazeWM.Domain/Containers/ContainerService.cs b/GlazeWM.Domain/Containers/ContainerService.cs
index b064d000..b7f7e21e 100644
--- a/GlazeWM.Domain/Containers/ContainerService.cs
+++ b/GlazeWM.Domain/Containers/ContainerService.cs
@@ -36,7 +36,7 @@ namespace GlazeWM.Domain.Containers
/// <summary>
/// Name of the currently active binding mode (if one is active).
/// </summary>
- public string ActiveBindingMode = null;
+ public string ActiveBindingMode { get; set; }
private readonly UserConfigService _userConfigService;
diff --git a/GlazeWM.Domain/Containers/Events/LayoutChangedEvent.cs b/GlazeWM.Domain/Containers/Events/LayoutChangedEvent.cs
new file mode 100644
index 00000000..612aa0f5
--- /dev/null
+++ b/GlazeWM.Domain/Containers/Events/LayoutChangedEvent.cs
@@ -0,0 +1,15 @@
+using GlazeWM.Domain.Common.Enums;
+using GlazeWM.Infrastructure.Bussing;
+
+namespace GlazeWM.Domain.Containers.Events
+{
+ public class LayoutChangedEvent : Event
+ {
+ public Layout NewLayout { get; }
+
+ public LayoutChangedEvent(Layout newLayout)
+ {
+ NewLayout = newLayout;
+ }
+ }
+}
diff --git a/GlazeWM.Domain/UserConfigs/BarComponentConfigConverter.cs b/GlazeWM.Domain/UserConfigs/BarComponentConfigConverter.cs
index 64c0db24..5c687cb2 100644
--- a/GlazeWM.Domain/UserConfigs/BarComponentConfigConverter.cs
+++ b/GlazeWM.Domain/UserConfigs/BarComponentConfigConverter.cs
@@ -33,6 +33,11 @@ namespace GlazeWM.Domain.UserConfigs
jsonObject.RootElement.ToString(),
options
),
+ "tiling direction" =>
+ JsonSerializer.Deserialize<TilingDirectionComponentConfig>(
+ jsonObject.RootElement.ToString(),
+ options
+ ),
"workspaces" =>
JsonSerializer.Deserialize<WorkspacesComponentConfig>(
jsonObject.RootElement.ToString(),
diff --git a/GlazeWM.Domain/UserConfigs/TilingDirectionComponentConfig.cs b/GlazeWM.Domain/UserConfigs/TilingDirectionComponentConfig.cs
new file mode 100644
index 00000000..29d42868
--- /dev/null
+++ b/GlazeWM.Domain/UserConfigs/TilingDirectionComponentConfig.cs
@@ -0,0 +1,6 @@
+namespace GlazeWM.Domain.UserConfigs
+{
+ public class TilingDirectionComponentConfig : BarComponentConfig
+ {
+ }
+}