Skip to content

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

feat(bar): add `BarService` method for killing bar WPF app

Lars Berger8be3a5f5bbe8
diff --git a/GlazeWM.Bar/BarService.cs b/GlazeWM.Bar/BarService.cs
index 9598ff0b..24d5acec 100644
--- a/GlazeWM.Bar/BarService.cs
+++ b/GlazeWM.Bar/BarService.cs
@@ -11,6 +11,7 @@ namespace GlazeWM.Bar
public class BarService
{
private Bus _bus;
+ private App _application;
public BarService(Bus bus)
{
@@ -21,20 +22,20 @@ namespace GlazeWM.Bar
{
var thread = new Thread(() =>
{
- var application = new App();
+ _application = new App();
// Launch the bar window on the added monitor.
_bus.Events.Where(@event => @event is MonitorAddedEvent)
.Subscribe((@event) =>
{
- application.Dispatcher.Invoke(() =>
+ _application.Dispatcher.Invoke(() =>
{
var originalFocusedHandle = GetForegroundWindow();
var barViewModel = new BarViewModel()
{
Monitor = (@event as MonitorAddedEvent).AddedMonitor,
- Dispatcher = application.Dispatcher,
+ Dispatcher = _application.Dispatcher,
};
var barWindow = new MainWindow(barViewModel);
@@ -45,7 +46,7 @@ namespace GlazeWM.Bar
});
});
- application.Run();
+ _application.Run();
});
thread.Name = "GlazeWMBar";
@@ -53,6 +54,11 @@ namespace GlazeWM.Bar
thread.Start();
}
+ public void ExitApp()
+ {
+ _application.Dispatcher.Invoke(() => _application.Shutdown());
+ }
+
/// <summary>
/// Convert shorthand properties from user config (ie. `Padding`, `Margin`, and `BorderWidth`)
/// to be compatible with their equivalent XAML properties (ie. `Padding`, `Margin`, and