Skip to content

Commit

Permalink
fixup! fix: maximized windows stay maximized when new windows are cre…
Browse files Browse the repository at this point in the history
…ated and after switching worskpaces
  • Loading branch information
phisko committed Oct 4, 2023
1 parent 1298f8e commit c6cd4a1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 11 deletions.
11 changes: 0 additions & 11 deletions GlazeWM.Domain/Windows/CommandHandlers/SetMaximizedHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,6 @@ public CommandResponse Handle(SetMaximizedCommand command)
var window = command.Window;

ShowWindow(window.Handle, ShowWindowFlags.Maximize);
var maximizedWindow = new MaximizedWindow(
window.Handle,
window.FloatingPlacement,
window.BorderDelta
)
{
Id = window.Id
};

_bus.Invoke(new ReplaceContainerCommand(maximizedWindow, window.Parent, window.Index));

return CommandResponse.Ok;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using GlazeWM.Domain.Containers.Commands;
using GlazeWM.Domain.Monitors.Commands;
using GlazeWM.Infrastructure.Bussing;
using GlazeWM.Infrastructure.Common.Events;
using static GlazeWM.Infrastructure.WindowsApi.WindowsApiService;

namespace GlazeWM.Domain.Windows.EventHandlers
{
Expand All @@ -20,11 +22,53 @@ public void Handle(WindowLocationChangedEvent @event)
{
var windowHandle = @event.WindowHandle;

HandleMaximizedWindow(windowHandle);

if (!_windowService.AppBarHandles.Contains(windowHandle))
return;

_bus.Invoke(new RefreshMonitorStateCommand());
_bus.Invoke(new RedrawContainersCommand());
}

private void HandleMaximizedWindow(IntPtr windowHandle)
{
var window = _windowService.GetWindowByHandle(windowHandle);
if (window is null)
return;

var windowPlacement = WindowService.GetPlacementOfHandle(windowHandle);
var isMaximized = windowPlacement.ShowCommand == ShowWindowFlags.Maximize;

if (isMaximized && window is not MaximizedWindow)
{
var maximizedWindow = new MaximizedWindow(
window.Handle,
window.FloatingPlacement,
window.BorderDelta
)
{
Id = window.Id
};

_bus.Invoke(new ReplaceContainerCommand(maximizedWindow, window.Parent, window.Index));
}

if (!isMaximized && window is MaximizedWindow)
{
// C# isn't my mothertongue, I couldn't find a way to factorize the content of these two if blocks
// because of the type difference. Anyone's welcome to refactor this!
var tilingWindow = new TilingWindow(
window.Handle,
window.FloatingPlacement,
window.BorderDelta
)
{
Id = window.Id
};

_bus.Invoke(new ReplaceContainerCommand(tilingWindow, window.Parent, window.Index));
}
}
}
}

0 comments on commit c6cd4a1

Please sign in to comment.