Skip to content

GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.

feat: respect initial minimized state (#67)

lars-bergerbfbdfd3db85f
diff --git a/GlazeWM.Domain/Windows/CommandHandlers/AddWindowHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/AddWindowHandler.cs
index 76445a91..77e830fa 100644
--- a/GlazeWM.Domain/Windows/CommandHandlers/AddWindowHandler.cs
+++ b/GlazeWM.Domain/Windows/CommandHandlers/AddWindowHandler.cs
@@ -1,4 +1,5 @@
-using System.Linq;
+using System;
+using System.Linq;
using GlazeWM.Domain.Containers;
using GlazeWM.Domain.Containers.Commands;
using GlazeWM.Domain.Monitors;
@@ -54,16 +55,9 @@ namespace GlazeWM.Domain.Windows.CommandHandlers
? (command.TargetParent, 0)
: GetInsertionTarget();
- var targetWorkspace = _workspaceService.GetWorkspaceFromChildContainer(targetParent);
-
- // Calculate where window should be placed when floating is enabled. Use the original
- // width/height of the window, but position it in the center of the workspace.
- var originalPlacement = _windowService.GetPlacementOfHandle(windowHandle).NormalPosition;
- var floatingPlacement = originalPlacement.TranslateToCenter(targetWorkspace.ToRectangle());
-
// Create the window instance.
- var defaultBorderDelta = new RectDelta(7, 0, 7, 7);
- var window = new TilingWindow(command.WindowHandle, floatingPlacement, defaultBorderDelta);
+ var targetWorkspace = _workspaceService.GetWorkspaceFromChildContainer(targetParent);
+ var window = CreateWindow(windowHandle, targetWorkspace);
var matchingWindowRules = _userConfigService.GetMatchingWindowRules(window);
@@ -75,7 +69,10 @@ namespace GlazeWM.Domain.Windows.CommandHandlers
if (commandStrings.Contains("ignore"))
return CommandResponse.Ok;
- _bus.Invoke(new AttachAndResizeContainerCommand(window, targetParent, targetIndex));
+ if (window is IResizable)
+ _bus.Invoke(new AttachAndResizeContainerCommand(window, targetParent, targetIndex));
+ else
+ _bus.Invoke(new AttachContainerCommand(window, targetParent, targetIndex));
// The OS might spawn the window on a different monitor to the target parent, so adjustments
// might need to be made because of DPI.
@@ -96,10 +93,6 @@ namespace GlazeWM.Domain.Windows.CommandHandlers
.Select(commandString => _commandParsingService.ParseCommand(commandString))
.ToList();
- // Initialize windows that can't be resized as floating.
- if (!window.HasWindowStyle(WS.WS_THICKFRAME))
- parsedCommands.Insert(0, new ToggleFloatingCommand(window));
-
// Invoke commands in the matching window rules. Use `dynamic` to resolve the command type
// at runtime and allow multiple dispatch.
foreach (var parsedCommand in parsedCommands)
@@ -111,6 +104,53 @@ namespace GlazeWM.Domain.Windows.CommandHandlers
return CommandResponse.Ok;
}
+ private Window CreateWindow(IntPtr windowHandle, Workspace targetWorkspace)
+ {
+ // Calculate where window should be placed when floating is enabled. Use the original
+ // width/height of the window, but position it in the center of the workspace.
+ var originalPlacement = _windowService.GetPlacementOfHandle(windowHandle).NormalPosition;
+ var floatingPlacement = originalPlacement.TranslateToCenter(targetWorkspace.ToRectangle());
+
+ var defaultBorderDelta = new RectDelta(7, 0, 7, 7);
+
+ var windowType = GetWindowTypeToCreate(windowHandle);
+ var isResizable = _windowService.HandleHasWindowStyle(windowHandle, WS.WS_THICKFRAME);
+
+ // TODO: Handle initialization of maximized and fullscreen windows.
+ return windowType switch
+ {
+ WindowType.MINIMIZED => new MinimizedWindow(
+ windowHandle,
+ floatingPlacement,
+ defaultBorderDelta,
+ isResizable ? WindowType.TILING : WindowType.FLOATING
+ ),
+ WindowType.FLOATING => new FloatingWindow(
+ windowHandle,
+ floatingPlacement,
+ defaultBorderDelta
+ ),
+ WindowType.TILING => new TilingWindow(
+ windowHandle,
+ floatingPlacement,
+ defaultBorderDelta
+ ),
+ _ => throw new ArgumentException(),
+ };
+ }
+
+ private WindowType GetWindowTypeToCreate(IntPtr windowHandle)
+ {
+ if (_windowService.HandleHasWindowStyle(windowHandle, WS.WS_MINIMIZE))
+ return WindowType.MINIMIZED;
+
+ // Initialize windows that can't be resized as floating.
+ if (!_windowService.HandleHasWindowStyle(windowHandle, WS.WS_THICKFRAME))
+ return WindowType.FLOATING;
+
+ return WindowType.TILING;
+ }
+
private (SplitContainer targetParent, int targetIndex) GetInsertionTarget()
{
var focusedContainer = _containerService.FocusedContainer;
diff --git a/GlazeWM.Domain/Windows/CommandHandlers/ToggleFloatingHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/ToggleFloatingHandler.cs
index 3f478cea..2ff75687 100644
--- a/GlazeWM.Domain/Windows/CommandHandlers/ToggleFloatingHandler.cs
+++ b/GlazeWM.Domain/Windows/CommandHandlers/ToggleFloatingHandler.cs
@@ -39,7 +39,10 @@ namespace GlazeWM.Domain.Windows.CommandHandlers
// Keep reference to the window's ancestor workspace prior to detaching.
var workspace = _workspaceService.GetWorkspaceFromChildContainer(window);
- _bus.Invoke(new MoveContainerWithinTreeCommand(window, workspace, true));
+ if (window is IResizable)
+ _bus.Invoke(new MoveContainerWithinTreeCommand(window, workspace, true));
+ else
+ _bus.Invoke(new MoveContainerWithinTreeCommand(window, workspace, false));
// Create a floating window and place it in the center of the workspace.
var floatingWindow = new FloatingWindow(
diff --git a/GlazeWM.Domain/Workspaces/CommandHandlers/MoveFocusedWindowToWorkspaceHandler.cs b/GlazeWM.Domain/Workspaces/CommandHandlers/MoveFocusedWindowToWorkspaceHandler.cs
index 557a9072..76715bb5 100644
--- a/GlazeWM.Domain/Workspaces/CommandHandlers/MoveFocusedWindowToWorkspaceHandler.cs
+++ b/GlazeWM.Domain/Workspaces/CommandHandlers/MoveFocusedWindowToWorkspaceHandler.cs
@@ -50,11 +50,10 @@ namespace GlazeWM.Domain.Workspaces.CommandHandlers
focusedWindow.FloatingPlacement =
focusedWindow.FloatingPlacement.TranslateToCenter(targetWorkspace.ToRectangle());
- if (focusedWindow is FloatingWindow)
- _bus.Invoke(new MoveContainerWithinTreeCommand(focusedWindow, targetWorkspace, false));
-
- else
+ if (focusedWindow is TilingWindow)
MoveTilingWindowToWorkspace(focusedWindow as TilingWindow, targetWorkspace);
+ else
+ _bus.Invoke(new MoveContainerWithinTreeCommand(focusedWindow, targetWorkspace, false));
// Reassign focus to descendant within the current workspace.
_bus.Invoke(new FocusWorkspaceCommand(currentWorkspace.Name));