Skip to content

Commit

Permalink
feat: option to disable floating windows initial centering (#476)
Browse files Browse the repository at this point in the history
  • Loading branch information
Video-Nomad authored Dec 21, 2023
1 parent 537edda commit 18eb8c8
Showing 4 changed files with 21 additions and 4 deletions.
3 changes: 3 additions & 0 deletions GlazeWM.App/Resources/sample-config.yaml
Original file line number Diff line number Diff line change
@@ -15,6 +15,9 @@ 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.
4 changes: 4 additions & 0 deletions GlazeWM.Domain/UserConfigs/GeneralConfig.cs
Original file line number Diff line number Diff line change
@@ -26,5 +26,9 @@ public class GeneralConfig
/// Whether to enable window transition animations (on minimize, close, etc).
/// </summary>
public WindowAnimations WindowAnimations { get; set; } = WindowAnimations.Unchanged;
/// <summary>
/// Whether to center new floating windows
/// </summary>
public bool CenterNewFloatingWindows { get; set; } = true;
}
}
15 changes: 11 additions & 4 deletions GlazeWM.Domain/Windows/CommandHandlers/ManageWindowHandler.cs
Original file line number Diff line number Diff line change
@@ -87,14 +87,21 @@ public CommandResponse Handle(ManageWindowCommand command)
return CommandResponse.Ok;
}

private static Window CreateWindow(IntPtr windowHandle, Container targetParent)
private Window CreateWindow(IntPtr windowHandle, Container targetParent)
{
var originalPlacement = WindowService.GetPlacementOfHandle(windowHandle).NormalPosition;

// 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 targetWorkspace = WorkspaceService.GetWorkspaceFromChildContainer(targetParent);
var floatingPlacement = originalPlacement.TranslateToCenter(targetWorkspace.ToRect());
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 centerNewFloatingWindows = _userConfigService.GeneralConfig.CenterNewFloatingWindows;
var floatingPlacement = handleWorkspace == targetWorkspace && !centerNewFloatingWindows
? originalPlacement
: originalPlacement.TranslateToCenter(targetWorkspace.ToRect());

var defaultBorderDelta = new RectDelta(7, 0, 7, 7);

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -91,6 +91,9 @@ general:
# 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
```
## Keybindings

0 comments on commit 18eb8c8

Please sign in to comment.