@@ -20,12 +20,13 @@ final class MacWindow: Window {
2020 static func getOrRegister( windowId: UInt32 , macApp: MacApp ) async throws -> MacWindow {
2121 if let existing = allWindowsMap [ windowId] { return existing }
2222 let rect = try await macApp. getAxRect ( windowId)
23- let data = try await getBindingDataForNewWindow (
23+ let data = try await unbindAndGetBindingDataForNewWindow (
2424 windowId,
2525 macApp,
2626 isStartup
2727 ? ( rect? . center. monitorApproximation ?? mainMonitor) . activeWorkspace
28- : focus. workspace
28+ : focus. workspace,
29+ window: nil
2930 )
3031
3132 // atomic synchronous section
@@ -202,29 +203,31 @@ final class MacWindow: Window {
202203extension Window {
203204 @MainActor // todo swift is stupid
204205 func relayoutWindow( on workspace: Workspace , forceTile: Bool = false ) async throws {
205- unbindFromParent ( ) // It's important to unbind to get correct data from getBindingData*
206- let data = forceTile
207- ? getBindingDataForNewTilingWindow ( workspace)
208- : try await getBindingDataForNewWindow ( self . asMacWindow ( ) . windowId, self . asMacWindow ( ) . macApp, workspace)
206+ let data = if forceTile {
207+ unbindAndGetBindingDataForNewTilingWindow ( workspace, window: self )
208+ } else {
209+ try await unbindAndGetBindingDataForNewWindow ( self . asMacWindow ( ) . windowId, self . asMacWindow ( ) . macApp, workspace, window: self )
210+ }
209211 bind ( to: data. parent, adaptiveWeight: data. adaptiveWeight, index: data. index)
210212 }
211213}
212214
213- // The function is private because it's " unsafe" . It requires the window to be in unbound state
215+ // The function is private because it's unsafe. It leaves the window in unbound state
214216@MainActor // todo swift is stupid
215- private func getBindingDataForNewWindow ( _ windowId: UInt32 , _ macApp: MacApp , _ workspace: Workspace ) async throws -> BindingData {
217+ private func unbindAndGetBindingDataForNewWindow ( _ windowId: UInt32 , _ macApp: MacApp , _ workspace: Workspace , window : Window ? ) async throws -> BindingData {
216218 if try await !macApp. isWindowHeuristic ( windowId) {
217219 return BindingData ( parent: macosPopupWindowsContainer, adaptiveWeight: WEIGHT_AUTO, index: INDEX_BIND_LAST)
218220 }
219221 if try await macApp. isDialogHeuristic ( windowId) {
220222 return BindingData ( parent: workspace, adaptiveWeight: WEIGHT_AUTO, index: INDEX_BIND_LAST)
221223 }
222- return getBindingDataForNewTilingWindow ( workspace)
224+ return unbindAndGetBindingDataForNewTilingWindow ( workspace, window : window )
223225}
224226
225- // The function is private because it's unsafe. It requires the window to be in unbound state
227+ // The function is private because it's unsafe. It leaves the window in unbound state
226228@MainActor
227- private func getBindingDataForNewTilingWindow( _ workspace: Workspace ) -> BindingData {
229+ private func unbindAndGetBindingDataForNewTilingWindow( _ workspace: Workspace , window: Window ? ) -> BindingData {
230+ window? . unbindFromParent ( ) // It's important to unbind to get correct data from below
228231 let mruWindow = workspace. mostRecentWindowRecursive
229232 if let mruWindow, let tilingParent = mruWindow. parent as? TilingContainer {
230233 return BindingData (
0 commit comments