Skip to content

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

feat(boot): set currently focused window in state on startup

Larsad717d099662
diff --git a/LarsWM.Bootstrapper/Startup.cs b/LarsWM.Bootstrapper/Startup.cs
index c988bfc3..bc3896c2 100644
--- a/LarsWM.Bootstrapper/Startup.cs
+++ b/LarsWM.Bootstrapper/Startup.cs
@@ -7,6 +7,7 @@ using LarsWM.Domain.Windows.Commands;
using LarsWM.Infrastructure.Bussing;
using LarsWM.Infrastructure.WindowsApi;
using System;
+using System.Linq;
using System.Windows.Forms;
using static LarsWM.Infrastructure.WindowsApi.WindowsApiService;
@@ -19,14 +20,22 @@ namespace LarsWM.Bootstrapper
private KeybindingService _keybindingService;
private WindowEventService _windowEventService;
private WindowHooksHandler _windowHooksHandler;
+ private WindowService _windowService;
- public Startup(IBus bus, MonitorService monitorService, KeybindingService keybindingService, WindowEventService windowEventService, WindowHooksHandler windowHooksHandler)
+ public Startup(
+ IBus bus,
+ MonitorService monitorService,
+ KeybindingService keybindingService,
+ WindowEventService windowEventService,
+ WindowHooksHandler windowHooksHandler,
+ WindowService windowService)
{
_bus = bus;
_monitorService = monitorService;
_keybindingService = keybindingService;
_windowEventService = windowEventService;
_windowHooksHandler = windowHooksHandler;
+ _windowService = windowService;
}
public void Init()
@@ -54,6 +63,15 @@ namespace LarsWM.Bootstrapper
// Add initial windows to tree.
_bus.Invoke(new AddInitialWindowsCommand());
+
+ var focusedWindow = _windowService.GetWindows().FirstOrDefault(w => w.Hwnd == GetForegroundWindow());
+
+ // GetForegroundWindow might return a handle that is not in tree. Return first window in such cases.
+ if (focusedWindow == null)
+ focusedWindow = _windowService.GetWindows().First();
+
+ // Set currently focused window.
+ _bus.Invoke(new FocusWindowCommand(focusedWindow));
}
}
}