From 15c35b580510d3d0a1451d6be631312fd3fedfe8 Mon Sep 17 00:00:00 2001 From: Lars Berger Date: Thu, 21 Dec 2023 18:14:09 +0800 Subject: [PATCH] fix: center floating windows opened on empty workspaces --- GlazeWM.App/Resources/sample-config.yaml | 6 +++--- GlazeWM.Domain/UserConfigs/GeneralConfig.cs | 2 +- .../Windows/CommandHandlers/ManageWindowHandler.cs | 13 +++++++++---- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/GlazeWM.App/Resources/sample-config.yaml b/GlazeWM.App/Resources/sample-config.yaml index 46cd610ce..d32b4ae7c 100644 --- a/GlazeWM.App/Resources/sample-config.yaml +++ b/GlazeWM.App/Resources/sample-config.yaml @@ -15,14 +15,14 @@ general: # Amount to move floating windows by (eg. when using `alt+` on a floating window) floating_window_move_amount: "5%" + # Whether to center new floating windows. + center_new_floating_windows: true + # *Strongly* recommended to set to 'false'. Whether to globally enable/disable # window transition animations (on minimize, close, etc). Set to 'unchanged' # to make no setting changes. window_animations: "unchanged" - # Whether to center new floating windows (default is true) - center_new_floating_windows: true - gaps: # Gap between adjacent windows. inner_gap: "20px" diff --git a/GlazeWM.Domain/UserConfigs/GeneralConfig.cs b/GlazeWM.Domain/UserConfigs/GeneralConfig.cs index 1154f881c..8d8924694 100644 --- a/GlazeWM.Domain/UserConfigs/GeneralConfig.cs +++ b/GlazeWM.Domain/UserConfigs/GeneralConfig.cs @@ -27,7 +27,7 @@ public class GeneralConfig /// public WindowAnimations WindowAnimations { get; set; } = WindowAnimations.Unchanged; /// - /// Weather to center new floating windows + /// Whether to center new floating windows /// public bool CenterNewFloatingWindows { get; set; } = true; } diff --git a/GlazeWM.Domain/Windows/CommandHandlers/ManageWindowHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/ManageWindowHandler.cs index 71679f987..217a7bcd2 100644 --- a/GlazeWM.Domain/Windows/CommandHandlers/ManageWindowHandler.cs +++ b/GlazeWM.Domain/Windows/CommandHandlers/ManageWindowHandler.cs @@ -91,12 +91,17 @@ private Window CreateWindow(IntPtr windowHandle, Container targetParent) { var originalPlacement = WindowService.GetPlacementOfHandle(windowHandle).NormalPosition; + var targetWorkspace = WorkspaceService.GetWorkspaceFromChildContainer(targetParent); + var handleWorkspace = _monitorService + .GetMonitorFromHandleLocation(windowHandle) + .DisplayedWorkspace; + // Calculate where window should be placed when floating is enabled. Use the original // width/height of the window and optionally position it in the center of the workspace. - var targetWorkspace = WorkspaceService.GetWorkspaceFromChildContainer(targetParent); - var floatingPlacement = _userConfigService.GeneralConfig.CenterNewFloatingWindows - ? originalPlacement.TranslateToCenter(targetWorkspace.ToRect()) - : originalPlacement; + var centerNewFloatingWindows = _userConfigService.GeneralConfig.CenterNewFloatingWindows; + var floatingPlacement = handleWorkspace == targetWorkspace && !centerNewFloatingWindows + ? originalPlacement + : originalPlacement.TranslateToCenter(targetWorkspace.ToRect()); var defaultBorderDelta = new RectDelta(7, 0, 7, 7);