Skip to content

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

feat(bar): sort workspaces displayed in bar component according to user config

Lars Bergerf48d3c4ffc93
diff --git a/GlazeWM.Bar/Components/WorkspacesComponentViewModel.cs b/GlazeWM.Bar/Components/WorkspacesComponentViewModel.cs
index 9ddf2e88..503423b0 100644
--- a/GlazeWM.Bar/Components/WorkspacesComponentViewModel.cs
+++ b/GlazeWM.Bar/Components/WorkspacesComponentViewModel.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reactive.Linq;
@@ -23,9 +24,22 @@ namespace GlazeWM.Bar.Components
private Monitor _monitor => _parentViewModel.Monitor;
private WorkspacesComponentConfig _config => _componentConfig as WorkspacesComponentConfig;
private readonly Bus _bus = ServiceLocator.Provider.GetRequiredService<Bus>();
+ private readonly UserConfigService _userConfigService =
+ ServiceLocator.Provider.GetRequiredService<UserConfigService>();
public ObservableCollection<Workspace> Workspaces =>
- new ObservableCollection<Workspace>(_monitor.Children.Cast<Workspace>());
+ new ObservableCollection<Workspace>(_orderedWorkspaces);
+
+ /// <summary>
+ /// Get workspaces of the current monitor sorted in the order they appear in the user's config.
+ /// </summary>
+ private IEnumerable<Workspace> _orderedWorkspaces => _monitor.Children
+ .Cast<Workspace>()
+ .OrderBy((workspace) =>
+ _userConfigService.UserConfig.Workspaces.FindIndex(
+ (workspaceConfig) => workspaceConfig.Name == workspace.Name
+ )
+ );
public string FocusedWorkspaceBackground => _config.FocusedWorkspaceBackground;
public string FocusedWorkspaceForeground => _config.FocusedWorkspaceForeground ?? Foreground;