GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat(bar): reposition bar window on new monitor connections and disconnections
Lars Bergerd5cbd6c33035
diff --git a/GlazeWM.Bar/MainWindow.xaml.cs b/GlazeWM.Bar/MainWindow.xaml.csindex fc38637b..29b8c691 100644--- a/GlazeWM.Bar/MainWindow.xaml.cs+++ b/GlazeWM.Bar/MainWindow.xaml.cs@@ -1,9 +1,13 @@using System;+using System.Reactive.Linq;using System.Windows;using System.Windows.Interop;+using System.Windows.Threading;using GlazeWM.Domain.Monitors;+using GlazeWM.Domain.Monitors.Events;using GlazeWM.Domain.UserConfigs;using GlazeWM.Infrastructure;+using GlazeWM.Infrastructure.Bussing;using Microsoft.Extensions.DependencyInjection;using static GlazeWM.Infrastructure.WindowsApi.WindowsApiService;@@ -14,8 +18,12 @@ namespace GlazeWM.Bar/// </summary>public partial class MainWindow : Window{- private UserConfigService _userConfigService = ServiceLocator.Provider.GetRequiredService<UserConfigService>();+ private Bus _bus = ServiceLocator.Provider.GetRequiredService<Bus>();+ private UserConfigService _userConfigService =+ ServiceLocator.Provider.GetRequiredService<UserConfigService>();+private BarViewModel _barViewModel { get; }+ private Dispatcher _dispatcher => _barViewModel.Dispatcher;private Monitor _monitor => _barViewModel.Monitor;public MainWindow(BarViewModel barViewModel)@@ -24,6 +32,17 @@ namespace GlazeWM.BarDataContext = barViewModel;InitializeComponent();++ // Reposition window on monitor removals and additions.+ _bus.Events.Where(@event => @event is MonitorAddedEvent || @event is MonitorRemovedEvent)+ .Subscribe((@event) =>+ {+ _dispatcher.Invoke(() =>+ {+ var windowHandle = new WindowInteropHelper(this).Handle;+ PositionWindow(windowHandle);+ });+ });}protected override void OnSourceInitialized(EventArgs e)