GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat(domain): always update all floating placements in `RefreshMonitorStateHandler`
Lars Berger81b25ec71746
diff --git a/GlazeWM.Domain/Monitors/CommandHandlers/RefreshMonitorStateHandler.cs b/GlazeWM.Domain/Monitors/CommandHandlers/RefreshMonitorStateHandler.csindex ccd6a626..d041f3af 100644--- a/GlazeWM.Domain/Monitors/CommandHandlers/RefreshMonitorStateHandler.cs+++ b/GlazeWM.Domain/Monitors/CommandHandlers/RefreshMonitorStateHandler.cs@@ -1,9 +1,10 @@-using System.Linq;+using System.Linq;using System.Windows.Forms;using GlazeWM.Domain.Containers;using GlazeWM.Domain.Containers.Commands;using GlazeWM.Domain.Monitors.Commands;using GlazeWM.Domain.Windows;+using GlazeWM.Domain.Workspaces;using GlazeWM.Infrastructure.Bussing;namespace GlazeWM.Domain.Monitors.CommandHandlers@@ -14,18 +15,21 @@ namespace GlazeWM.Domain.Monitors.CommandHandlersprivate MonitorService _monitorService;private ContainerService _containerService;private WindowService _windowService;+ private WorkspaceService _workspaceService;public RefreshMonitorStateHandler(Bus bus,MonitorService monitorService,ContainerService containerService,- WindowService windowService+ WindowService windowService,+ WorkspaceService workspaceService){_bus = bus;_monitorService = monitorService;_containerService = containerService;_windowService = windowService;+ _workspaceService = workspaceService;}public CommandResponse Handle(RefreshMonitorStateCommand command)@@ -61,11 +65,19 @@ namespace GlazeWM.Domain.Monitors.CommandHandlersforeach (var monitor in monitorsToRemove.ToList())_bus.Invoke(new RemoveMonitorCommand(monitor));- // Display setting changes can spread windows out sporadically, so mark all windows as needing- // a DPI adjustment (just in case).foreach (var window in _windowService.GetWindows())+ {+ // Display setting changes can spread windows out sporadically, so mark all windows as+ // needing a DPI adjustment (just in case).window.HasPendingDpiAdjustment = true;+ // Need to update floating position of moved windows when a monitor is disconnected or if+ // the primary display is changed. The primary display dictates the position of 0,0.+ var parentWorkspace = _workspaceService.GetWorkspaceFromChildContainer(window);+ window.FloatingPlacement =+ window.FloatingPlacement.TranslateToCenter(parentWorkspace.ToRectangle());+ }+// Redraw full container tree._containerService.ContainersToRedraw.Add(_containerService.ContainerTree);_bus.Invoke(new RedrawContainersCommand());diff --git a/GlazeWM.Domain/Monitors/CommandHandlers/RemoveMonitorHandler.cs b/GlazeWM.Domain/Monitors/CommandHandlers/RemoveMonitorHandler.csindex 76c9ac24..cc93feb8 100644--- a/GlazeWM.Domain/Monitors/CommandHandlers/RemoveMonitorHandler.cs+++ b/GlazeWM.Domain/Monitors/CommandHandlers/RemoveMonitorHandler.cs@@ -46,12 +46,6 @@ namespace GlazeWM.Domain.Monitors.CommandHandlers.Where(descendant => descendant is Window).Cast<Window>();- // Adjust floating position of moved windows.- // TODO: If primary monitor changes, does floating placement of all windows need to be updated?- foreach (var window in windows)- window.FloatingPlacement =- window.FloatingPlacement.TranslateToCenter(workspace.ToRectangle());-// Update workspaces displayed in bar window.// TODO: Consider creating separate event `WorkspaceMovedEvent`._bus.RaiseEvent(new WorkspaceActivatedEvent(workspace));