Skip to content

Commit cc1d22d

Browse files
committed
2/2 MacWindow.hideInCorner: fix incorrect monitor that we calculate relative position against
#1492 Calculate position relative to the monitor the window is currently on, instead of the one it logically belongs to
1 parent c36fd4c commit cc1d22d

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

Sources/AppBundle/layout/layoutRecursive.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ extension Window {
6969
@MainActor // todo can be dropped in future Swift versions?
7070
fileprivate func layoutFloatingWindow(_ context: LayoutContext) async throws {
7171
let workspace = context.workspace
72-
let currentMonitor = try await getCenter()?.monitorApproximation
72+
let currentMonitor = try await getCenter()?.monitorApproximation // Probably not idempotent
7373
if let currentMonitor, let windowTopLeftCorner = try await getAxTopLeftCorner(), workspace != currentMonitor.activeWorkspace {
7474
let xProportion = (windowTopLeftCorner.x - currentMonitor.visibleRect.topLeftX) / currentMonitor.visibleRect.width
7575
let yProportion = (windowTopLeftCorner.y - currentMonitor.visibleRect.topLeftY) / currentMonitor.visibleRect.height

Sources/AppBundle/tree/MacWindow.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,19 @@ final class MacWindow: Window {
124124
macApp.closeAndUnregisterAxWindow(windowId)
125125
}
126126

127+
// todo it's part of the window layout and should be move to layoutRecursive.swift
127128
@MainActor
128129
func hideInCorner(_ corner: OptimalHideCorner) async throws {
129130
guard let nodeMonitor else { return }
130131
// Don't accidentally override prevUnhiddenEmulationPosition in case of subsequent
131132
// `hideEmulation` calls
132133
if !isHiddenInCorner {
133-
guard let topLeftCorner = try await getAxTopLeftCorner() else { return }
134-
guard let nodeWorkspace else { return } // hiding only makes sense for workspace windows
135-
let workspaceRect = nodeWorkspace.workspaceMonitor.rect
136-
let absolutePoint = topLeftCorner - workspaceRect.topLeftCorner
134+
guard let windowRect = try await getAxRect() else { return }
135+
let topLeftCorner = windowRect.topLeftCorner
136+
let monitorRect = windowRect.center.monitorApproximation.rect // Similar to layoutFloatingWindow. Non idempotent
137+
let absolutePoint = topLeftCorner - monitorRect.topLeftCorner
137138
prevUnhiddenProportionalPositionInsideWorkspaceRect =
138-
CGPoint(x: absolutePoint.x / workspaceRect.width, y: absolutePoint.y / workspaceRect.height)
139+
CGPoint(x: absolutePoint.x / monitorRect.width, y: absolutePoint.y / monitorRect.height)
139140
}
140141
let p: CGPoint
141142
switch corner {

0 commit comments

Comments
 (0)