Skip to content

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

feat(bar): adjust bar width according to monitor scale factor

Lars Bergerf9f4dcbb9681
diff --git a/LarsWM.Bar/BarManagerService.cs b/LarsWM.Bar/BarManagerService.cs
index b06ec223..f170b155 100644
--- a/LarsWM.Bar/BarManagerService.cs
+++ b/LarsWM.Bar/BarManagerService.cs
@@ -4,6 +4,7 @@ using LarsWM.Infrastructure.Bussing;
using System.Reactive.Linq;
using System;
using System.Threading;
+using LarsWM.Domain.UserConfigs;
namespace LarsWM.Bar
{
@@ -11,11 +12,13 @@ namespace LarsWM.Bar
{
private Bus _bus;
private WorkspaceService _workspaceService;
+ private UserConfigService _userConfigService;
- public BarManagerService(Bus bus, WorkspaceService workspaceService)
+ public BarManagerService(Bus bus, WorkspaceService workspaceService, UserConfigService userConfigService)
{
_bus = bus;
_workspaceService = workspaceService;
+ _userConfigService = userConfigService;
}
public void Init()
@@ -30,7 +33,7 @@ namespace LarsWM.Bar
{
application.Dispatcher.Invoke(() =>
{
- var bar = new MainWindow((@event as MonitorAddedEvent).AddedMonitor, _workspaceService, _bus);
+ var bar = new MainWindow((@event as MonitorAddedEvent).AddedMonitor, _workspaceService, _bus, _userConfigService);
bar.Show();
});
});
diff --git a/LarsWM.Bar/MainWindow.xaml.cs b/LarsWM.Bar/MainWindow.xaml.cs
index e661477a..0ab69612 100644
--- a/LarsWM.Bar/MainWindow.xaml.cs
+++ b/LarsWM.Bar/MainWindow.xaml.cs
@@ -9,6 +9,7 @@ using System;
using System.Windows;
using System.Windows.Controls;
using LarsWM.Domain.Containers.Events;
+using LarsWM.Domain.UserConfigs;
namespace LarsWM.Bar
{
@@ -19,22 +20,25 @@ namespace LarsWM.Bar
{
private Bus _bus { get; }
private WorkspaceService _workspaceService { get; }
- private static object _lock = new object();
+ private UserConfigService _userConfigService { get; }
private ObservableCollection<Workspace> _workspaces = new ObservableCollection<Workspace>();
- public MainWindow(Monitor monitor, WorkspaceService workspaceService, Bus bus)
+ public MainWindow(Monitor monitor, WorkspaceService workspaceService, Bus bus, UserConfigService userConfigService)
{
_bus = bus;
_workspaceService = workspaceService;
+ _userConfigService = userConfigService;
InitializeComponent();
// TODO: Bind padding, bg color, button bg color and font from user config.
Top = monitor.Y;
Left = monitor.X;
- Width = monitor.Width;
- // TODO: Change height to be set in XAML.
- Height = 50;
+ Height = _userConfigService.UserConfig.Bar.Height;
+
+ // WPF automatically changes the size of the bar based on display scale factor. This causes
+ // the bar width to overflow on scale factors > 100%, so need to adjust accordingly.
+ Width = Convert.ToInt32(monitor.Width / monitor.ScaleFactor);
RefreshState(monitor);