enum FloatingWindowPlacement { static func frame(in usableArea: Rect, minimum: Size) -> Rect? { let area = usableArea.roundedToWholePoints() guard area.isValid, area.size.width > 0, area.size.height > 0, minimum.isValid else { return nil } let width = max(minimum.width.rounded(.up), (area.size.width * 0.7).rounded(.down)) let height = max(minimum.height.rounded(.up), (area.size.height * 0.7).rounded(.down)) guard width > 0, height > 0 else { return nil } // An oversized minimum may overflow, but its title controls must stay reachable. return Rect( x: max(area.minX, area.center.xCoordinate - width / 2), y: max(area.minY, area.center.yCoordinate - height / 2), width: width, height: height ).roundedToWholePoints() } } extension Workspace { mutating func rebalanceFloatTransition( from previousTileCount: Int, in frame: Rect, windows: [WindowID: ManagedWindow] ) { guard !layout.preservesTree, (tree?.tileCount ?? 0) != previousTileCount else { return } var balanced = self balanced.tree = balancedWorkspaceTree(tree?.stacks ?? []) balanced.adaptiveTileMemory = nil balanced.alternateSideTree = nil if let focus { balanced.select(focus) } if LayoutEngine.arrange(balanced, in: frame, windows: windows).cannotFit.isEmpty { self = balanced } } }