Skip to content

Commit

Permalink
fix: center floating windows opened on empty workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-berger committed Dec 21, 2023
1 parent f0b6745 commit 15c35b5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
6 changes: 3 additions & 3 deletions GlazeWM.App/Resources/sample-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ general:
# Amount to move floating windows by (eg. when using `alt+<hjkl>` 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"
Expand Down
2 changes: 1 addition & 1 deletion GlazeWM.Domain/UserConfigs/GeneralConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class GeneralConfig
/// </summary>
public WindowAnimations WindowAnimations { get; set; } = WindowAnimations.Unchanged;
/// <summary>
/// Weather to center new floating windows
/// Whether to center new floating windows
/// </summary>
public bool CenterNewFloatingWindows { get; set; } = true;
}
Expand Down
13 changes: 9 additions & 4 deletions GlazeWM.Domain/Windows/CommandHandlers/ManageWindowHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 15c35b5

Please sign in to comment.