From 0e9828442dee090e1822b6e53c4982949a10ca9b Mon Sep 17 00:00:00 2001 From: Lars Berger Date: Mon, 9 Oct 2023 05:14:48 +0800 Subject: [PATCH] fix: move maximized windows to be top-level; handle minimize crash --- .../WindowLocationChangedHandler.cs | 22 ++++++++++++------- GlazeWM.Domain/Windows/WindowService.cs | 1 + 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/GlazeWM.Domain/Windows/EventHandlers/WindowLocationChangedHandler.cs b/GlazeWM.Domain/Windows/EventHandlers/WindowLocationChangedHandler.cs index f7eeb1682..7d914fa7f 100644 --- a/GlazeWM.Domain/Windows/EventHandlers/WindowLocationChangedHandler.cs +++ b/GlazeWM.Domain/Windows/EventHandlers/WindowLocationChangedHandler.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using GlazeWM.Domain.Containers; using GlazeWM.Domain.Containers.Commands; using GlazeWM.Domain.Monitors.Commands; @@ -46,8 +47,16 @@ private void HandleMaximizedWindow(IntPtr windowHandle) var windowPlacement = WindowService.GetPlacementOfHandle(windowHandle); var isMaximized = windowPlacement.ShowCommand == ShowWindowFlags.Maximize; + // Window is being maximized. if (isMaximized && window is not MaximizedWindow) { + // Move tiling windows to be direct children of workspace (in case they aren't already). + if (window is TilingWindow) + { + var workspace = WorkspaceService.GetWorkspaceFromChildContainer(window); + _bus.Invoke(new MoveContainerWithinTreeCommand(window, workspace, true)); + } + var previousState = WindowService.GetWindowType(window); var maximizedWindow = new MaximizedWindow( window.Handle, @@ -59,24 +68,20 @@ private void HandleMaximizedWindow(IntPtr windowHandle) Id = window.Id }; - if (!window.HasSiblings() && window.Parent is not Workspace) - _bus.Invoke(new FlattenSplitContainerCommand(window.Parent as SplitContainer)); - _bus.Invoke(new ReplaceContainerCommand(maximizedWindow, window.Parent, window.Index)); + + _containerService.ContainersToRedraw.Concat(window.Siblings); + _bus.Invoke(new RedrawContainersCommand()); } + // Window is being unmaximized. if (!isMaximized && window is MaximizedWindow) { var restoredWindow = CreateWindowFromPreviousState(window as MaximizedWindow); - _bus.Invoke(new ReplaceContainerCommand(restoredWindow, window.Parent, window.Index)); if (restoredWindow is not TilingWindow) - { - // Needed to reposition the floating window - _bus.Invoke(new RedrawContainersCommand()); return; - } var workspace = WorkspaceService.GetWorkspaceFromChildContainer(window); var insertionTarget = workspace.LastFocusedDescendantOfType(); @@ -99,6 +104,7 @@ private void HandleMaximizedWindow(IntPtr windowHandle) } } + // TODO: Share logic with `WindowMinimizedHandler`. private static Window CreateWindowFromPreviousState(MaximizedWindow window) { Window restoredWindow = window.PreviousState switch diff --git a/GlazeWM.Domain/Windows/WindowService.cs b/GlazeWM.Domain/Windows/WindowService.cs index 9bc92567c..de5a311e7 100644 --- a/GlazeWM.Domain/Windows/WindowService.cs +++ b/GlazeWM.Domain/Windows/WindowService.cs @@ -241,6 +241,7 @@ public static WindowType GetWindowType(Window window) { TilingWindow => WindowType.Tiling, FloatingWindow => WindowType.Floating, + MinimizedWindow => WindowType.Minimized, MaximizedWindow => WindowType.Maximized, FullscreenWindow => WindowType.Fullscreen, _ => throw new ArgumentException(null, nameof(window)),