Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions Sources/AppBundle/layout/layoutRecursive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,23 @@ extension Window {
@MainActor
fileprivate func layoutFloatingWindow(_ context: LayoutContext) async throws {
let workspace = context.workspace
let currentMonitor = try await getCenter()?.monitorApproximation // Probably not idempotent
if let currentMonitor, let windowTopLeftCorner = try await getAxTopLeftCorner(), workspace != currentMonitor.activeWorkspace {
let windowRect = try await getAxRect() // Probably not idempotent
let currentMonitor = windowRect?.center.monitorApproximation
if let currentMonitor, let windowRect, workspace != currentMonitor.activeWorkspace {
let windowTopLeftCorner = windowRect.topLeftCorner
let xProportion = (windowTopLeftCorner.x - currentMonitor.visibleRect.topLeftX) / currentMonitor.visibleRect.width
let yProportion = (windowTopLeftCorner.y - currentMonitor.visibleRect.topLeftY) / currentMonitor.visibleRect.height

let moveTo = workspace.workspaceMonitor
setAxFrame(CGPoint(
x: moveTo.visibleRect.topLeftX + xProportion * moveTo.visibleRect.width,
y: moveTo.visibleRect.topLeftY + yProportion * moveTo.visibleRect.height,
), nil)
let workspaceRect = workspace.workspaceMonitor.visibleRect
var newX = workspaceRect.topLeftX + xProportion * workspaceRect.width
var newY = workspaceRect.topLeftY + yProportion * workspaceRect.height

let windowWidth = windowRect.width
let windowHeight = windowRect.height
newX = newX.coerceIn(workspaceRect.minX ... max(workspaceRect.minX, workspaceRect.maxX - windowWidth))
newY = newY.coerceIn(workspaceRect.minY ... max(workspaceRect.minY, workspaceRect.maxY - windowHeight))

setAxFrame(CGPoint(x: newX, y: newY), nil)
}
if isFullscreen {
layoutFullscreen(context)
Expand Down
15 changes: 10 additions & 5 deletions Sources/AppBundle/tree/MacWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,16 @@ final class MacWindow: Window {
// Tiling windows should be unhidden with layoutRecursive anyway
case .floatingWindow:
let workspaceRect = nodeWorkspace.workspaceMonitor.rect
let pointInsideWorkspace = CGPoint(
x: workspaceRect.width * prevUnhiddenProportionalPositionInsideWorkspaceRect.x,
y: workspaceRect.height * prevUnhiddenProportionalPositionInsideWorkspaceRect.y,
)
setAxFrame(workspaceRect.topLeftCorner + pointInsideWorkspace, nil)
var newX = workspaceRect.topLeftX + workspaceRect.width * prevUnhiddenProportionalPositionInsideWorkspaceRect.x
var newY = workspaceRect.topLeftY + workspaceRect.height * prevUnhiddenProportionalPositionInsideWorkspaceRect.y
// todo we probably should replace lastFloatingSize with proper floating window sizing
// https://github.com/nikitabobko/AeroSpace/issues/1519
let windowWidth = lastFloatingSize?.width ?? 0
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let windowWidth = lastFloatingSize?.width ?? 0
// todo we probably should replace lastFloatingSize with proper floating window sizing
// https://github.com/nikitabobko/AeroSpace/issues/1519
let windowWidth = lastFloatingSize?.width ?? 0

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about the commit message, I added the full explanation in the commit message inside Sublime Merge, it displays the full message:
image

I will fix this commit to have a more descriptive first line and I will add your suggestions too.

let windowHeight = lastFloatingSize?.height ?? 0
newX = newX.coerceIn(workspaceRect.minX ... max(workspaceRect.minX, workspaceRect.maxX - windowWidth))
newY = newY.coerceIn(workspaceRect.minY ... max(workspaceRect.minY, workspaceRect.maxY - windowHeight))

setAxFrame(CGPoint(x: newX, y: newY), nil)
case .macosNativeFullscreenWindow, .macosNativeHiddenAppWindow, .macosNativeMinimizedWindow,
.macosPopupWindow, .tiling, .rootTilingContainer, .shimContainerRelation: break
}
Expand Down
Loading