GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat(boot): set focus to workspace on startup if there are no manageable windows
Lars Bergercbe47849e277
diff --git a/LarsWM.Bootstrapper/Startup.cs b/LarsWM.Bootstrapper/Startup.csindex 4ffea36e..3cab6f31 100644--- a/LarsWM.Bootstrapper/Startup.cs+++ b/LarsWM.Bootstrapper/Startup.cs@@ -1,9 +1,12 @@using LarsWM.Bar;+using LarsWM.Domain.Containers;using LarsWM.Domain.Monitors;using LarsWM.Domain.Monitors.Commands;using LarsWM.Domain.UserConfigs.Commands;using LarsWM.Domain.Windows;using LarsWM.Domain.Windows.Commands;+using LarsWM.Domain.Workspaces;+using LarsWM.Domain.Workspaces.Commands;using LarsWM.Infrastructure.Bussing;using LarsWM.Infrastructure.WindowsApi;using System.Linq;@@ -20,6 +23,7 @@ namespace LarsWM.Bootstrapperprivate WindowEventService _windowEventService;private WindowService _windowService;private BarManagerService _barManagerService;+ private WorkspaceService _workspaceService;public Startup(Bus bus,@@ -27,8 +31,8 @@ namespace LarsWM.BootstrapperKeybindingService keybindingService,WindowEventService windowEventService,WindowService windowService,- BarManagerService barManagerService- )+ BarManagerService barManagerService,+ WorkspaceService workspaceService){_bus = bus;_monitorService = monitorService;@@ -36,6 +40,7 @@ namespace LarsWM.Bootstrapper_windowEventService = windowEventService;_windowService = windowService;_barManagerService = barManagerService;+ _workspaceService = workspaceService;}public void Init()@@ -67,13 +72,19 @@ namespace LarsWM.Bootstrapper// Add initial windows to tree._bus.Invoke(new AddInitialWindowsCommand());- // GetForegroundWindow might return a handle that is not in tree. In that case, set- // focus to an arbitrary window.- var focusedWindow = _windowService.GetWindows().FirstOrDefault(w => w.Hwnd == GetForegroundWindow())- ?? _windowService.GetWindows().First();+ // `GetForegroundWindow` might return a handle that is not in tree. In that case, set+ // focus to an arbitrary window. If there are no manageable windows in the tree, set focus+ // to an arbitrary workspace.+ Container focusedContainer =+ _windowService.GetWindows().FirstOrDefault(window => window.Hwnd == GetForegroundWindow())+ ?? _windowService.GetWindows().FirstOrDefault() as Container+ ?? _workspaceService.GetActiveWorkspaces().FirstOrDefault() as Container;- _bus.Invoke(new FocusWindowCommand(focusedWindow));+ if (focusedContainer is Window)+ _bus.Invoke(new FocusWindowCommand(focusedContainer as Window));++ else if (focusedContainer is Workspace)+ _bus.Invoke(new FocusWorkspaceCommand((focusedContainer as Workspace).Name));}}}-