Skip to content

Commit

Permalink
fix: move maximized windows to be top-level; handle minimize crash
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-berger committed Oct 8, 2023
1 parent 4328dc8 commit 0e98284
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using GlazeWM.Domain.Containers;
using GlazeWM.Domain.Containers.Commands;
using GlazeWM.Domain.Monitors.Commands;
Expand Down Expand Up @@ -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,
Expand All @@ -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<IResizable>();
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions GlazeWM.Domain/Windows/WindowService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down

0 comments on commit 0e98284

Please sign in to comment.