Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899public import Foundationpublic import ParcelCore
public struct EngineFrameAcceptanceError: Error, Sendable, Equatable, LocalizedError { public let window: WindowID public let app: AppID public let requested: Rect public let accepted: Rect
public var errorDescription: String? { String( format: String( localized: "%@ refused its tile position. Parcel kept its accepted frame and arranged nearby windows around it. Reset the window's learned adjustment to try again.", table: "FrameAcceptance", bundle: .module), locale: .current, app.bundleID) }}
extension ParcelEngine { func prepareAcceptedFrames() { for (window, target) in exhaustedProtrusionTargets { let desired = manualCommandFrames[window] ?? manualRestorationFrames[window] ?? snapshot.state.frames[window] guard desired != target || !blockedWindows.contains(window) else { continue } exhaustedProtrusionTargets[window] = nil protrusionAttempts[window] = nil blockedWindows.remove(window) frameAdjustments[window] = nil } }
func targetAvoidingAcceptedFrames(_ target: Rect, for window: WindowID, in workspace: WorkspaceKey) -> Rect? { if snapshot.state.windows[window]?.isFloating == true { return target } let minimum = snapshot.state.windows[window]?.minimumSize ?? Size() let gap = snapshot.state.workspaces[workspace]?.gaps.inner ?? 0 var result = target for refused in exhaustedProtrusionTargets.keys.sorted() where refused != window { guard snapshot.state.workspace(containing: refused) == workspace, let accepted = actualFrames[refused] ?? snapshot.readbackFrames[refused] else { continue } guard let available = acceptedFrameRemainder(result, avoiding: accepted, gap: gap, minimum: minimum) else { return nil } result = available } return result }
func noteProtrusion(_ window: WindowID, requested: Rect, accepted: Rect) { guard let logicalTarget = manualCommandFrames[window] ?? manualRestorationFrames[window] ?? snapshot.state.frames[window], let workspace = snapshot.state.workspace(containing: window) else { preconditionFailure("A protruding managed window must have a logical layout target") } guard targetAvoidingAcceptedFrames(logicalTarget, for: window, in: workspace) == requested else { return } let previous = protrusionAttempts[window] let count = previous?.target == requested ? (previous?.count ?? 0) + 1 : 1 protrusionAttempts[window] = (requested, count) guard count >= 3 else { return } // Obstacle clipping changes the effective request, not the user's layout target. exhaustedProtrusionTargets[window] = logicalTarget blockedWindows.insert(window) cancelMotion(window, remove: false) log.record(.platform(.correctiveWriteLimit(window, limit: 3))) if let app = snapshot.state.windows[window]?.app { let failure = EngineFrameAcceptanceError(window: window, app: app, requested: requested, accepted: accepted) log.record(.internalFailure(failure)) onFailure?(failure) } needsRetile = true scheduleTurn() }}
func acceptedFrameRemainder(_ target: Rect, avoiding accepted: Rect, gap: Double, minimum: Size) -> Rect? { guard target.maxX > accepted.minX - gap, target.minX < accepted.maxX + gap, target.maxY > accepted.minY - gap, target.minY < accepted.maxY + gap else { return target } let candidates = [ Rect( x: target.minX, y: target.minY, width: min(target.maxX, accepted.minX - gap) - target.minX, height: target.size.height), Rect( x: max(target.minX, accepted.maxX + gap), y: target.minY, width: target.maxX - max(target.minX, accepted.maxX + gap), height: target.size.height), Rect( x: target.minX, y: target.minY, width: target.size.width, height: min(target.maxY, accepted.minY - gap) - target.minY), Rect( x: target.minX, y: max(target.minY, accepted.maxY + gap), width: target.size.width, height: target.maxY - max(target.minY, accepted.maxY + gap)), ] return candidates.filter { $0.isValid && $0.size.width > 0 && $0.size.height > 0 && $0.size.width >= minimum.width && $0.size.height >= minimum.height }.max { $0.size.width * $0.size.height < $1.size.width * $1.size.height }}