public import Foundation import ParcelCore public enum BindingAction: Hashable, Sendable { case command(ConfigCommand) case enterMode(String) case exitMode } public struct ParcelConfiguration: Equatable, Sendable { public var version: Int public var general: GeneralConfiguration public var layout: LayoutConfiguration public var motion: MotionConfiguration public var focusModes: FocusModeConfiguration public var mouse: MouseConfiguration public var hoverBar: HoverBarConfiguration public var memory: MemoryConfiguration public var keybindings: [ConfigCommand: KeyChord] public var inheritedShortcutDisplacements: [InheritedShortcutDisplacement] = [] public var defaultModeEntries: [String: KeyChord] public var modes: [String: [BindingAction: KeyChord]] public var floatRules: [FloatRule] /// Rules are ordered; all supplied matchers must match and the last matching rule wins. public var rules: [RuleConfiguration] public var classification: ClassificationConfiguration public var accessibility: AccessibilityConfiguration public var callbacks: CallbackConfiguration public var appearance: AppearanceConfiguration public static let defaults = ParcelConfiguration() public init( version: Int = 1, general: GeneralConfiguration = GeneralConfiguration(), layout: LayoutConfiguration = LayoutConfiguration(), motion: MotionConfiguration = MotionConfiguration(), keybindings: [ConfigCommand: KeyChord]? = nil, floatRules: [FloatRule] = [], accessibility: AccessibilityConfiguration = AccessibilityConfiguration(), rules: [RuleConfiguration] = [], classification: ClassificationConfiguration = ClassificationConfiguration(), mouse: MouseConfiguration = MouseConfiguration(), hoverBar: HoverBarConfiguration = HoverBarConfiguration(), memory: MemoryConfiguration = MemoryConfiguration(), defaultModeEntries: [String: KeyChord] = [:], modes: [String: [BindingAction: KeyChord]] = [:], callbacks: CallbackConfiguration = CallbackConfiguration(), focusModes: FocusModeConfiguration = FocusModeConfiguration(), appearance: AppearanceConfiguration = AppearanceConfiguration() ) { self.version = version self.general = general self.layout = layout self.motion = motion self.focusModes = focusModes self.mouse = mouse self.hoverBar = hoverBar self.memory = memory self.keybindings = keybindings ?? DefaultKeybindings.bindings(prefix: general.prefix) self.defaultModeEntries = defaultModeEntries self.modes = modes self.floatRules = floatRules self.rules = rules self.classification = classification self.accessibility = accessibility self.callbacks = callbacks self.appearance = appearance } } public struct InheritedShortcutDisplacement: Equatable, Sendable { public let command: ConfigCommand public let chord: KeyChord public let binding: BindingAction public init(command: ConfigCommand, chord: KeyChord, binding: BindingAction) { self.command = command self.chord = chord self.binding = binding } } public enum ConfigWhenDisplayFull: String, Codable, CaseIterable, Sendable { case swap, stack } public struct GeneralConfiguration: Equatable, Sendable { public var prefix: KeyModifiers public var launchAtLogin: Bool public var shortcutsEnabled: Bool public var collectActivity: Bool public var whenDisplayFull: ConfigWhenDisplayFull public init( prefix: KeyModifiers = [.ctrl, .alt], launchAtLogin: Bool = false, shortcutsEnabled: Bool = true, whenDisplayFull: ConfigWhenDisplayFull = .swap, collectActivity: Bool = true ) { self.prefix = prefix self.launchAtLogin = launchAtLogin self.shortcutsEnabled = shortcutsEnabled self.collectActivity = collectActivity self.whenDisplayFull = whenDisplayFull } } public enum ConfigLayout: String, Codable, CaseIterable, Sendable { case grid, columns, rows, side, tree, bsp, accordion } public enum ConfigWhenFull: String, Codable, CaseIterable, Sendable { case stack, float } public struct LayoutConfiguration: Equatable, Sendable { public var global: LayoutValues public var displays: [UUID: LayoutValues] public init(global: LayoutValues = LayoutValues(), displays: [UUID: LayoutValues] = [:]) { self.global = global self.displays = displays } public func values(for displayID: UUID) -> LayoutValues { displays[displayID] ?? global } } public struct LayoutValues: Equatable, Sendable { public var defaultLayout: ConfigLayout public var portraitLayout: ConfigLayout public var ratio: Double public var gaps: LayoutGaps public var reserved: ReservedEdges /// Defaults to three tiles; zero explicitly disables both user and layout capability limits. public var windowCap: Int public var whenFull: ConfigWhenFull public init( defaultLayout: ConfigLayout = .grid, portraitLayout: ConfigLayout = .rows, ratio: Double = 0.5, gaps: LayoutGaps = LayoutGaps(), reserved: ReservedEdges = ReservedEdges(), windowCap: Int = 3, whenFull: ConfigWhenFull = .stack ) { self.defaultLayout = defaultLayout self.portraitLayout = portraitLayout self.ratio = ratio self.gaps = gaps self.reserved = reserved self.windowCap = windowCap self.whenFull = whenFull } } public struct LayoutGaps: Equatable, Sendable { public var inner: Double public var outer: Double public init(inner: Double = 8, outer: Double = 8) { self.inner = inner self.outer = outer } } public struct ReservedEdges: Equatable, Sendable { public var top: Double public var right: Double public var bottom: Double public var left: Double public init(top: Double = 0, right: Double = 0, bottom: Double = 0, left: Double = 0) { self.top = top self.right = right self.bottom = bottom self.left = left } } public enum ConfigMotionLevel: String, CaseIterable, Sendable { case calm, playful, extra } public enum ConfigMotionTransition: String, CaseIterable, Sendable { case glide, ghost, snap } public enum ConfigMenuBarIcon: String, CaseIterable, Sendable { case minimap, logo } public enum ConfigHighlight: String, CaseIterable, Sendable { case none, active, all, glow } public struct MotionConfiguration: Equatable, Sendable { public static let highlightWidths = 2.0...6.0 public var enabled: Bool public var level: ConfigMotionLevel public var speed: Double public var transitions: ConfigMotionTransition public var highlight: ConfigHighlight public var highlightWidth: Double public var focusBorder: Bool { get { highlight != .none } set { if !newValue { highlight = .none } else if highlight == .none { highlight = .active } } } public var dropHints: Bool public var experimentalDimming: Bool public var sound: Bool public var menuBarIcon: ConfigMenuBarIcon public init( enabled: Bool = true, level: ConfigMotionLevel = .playful, speed: Double = 1, transitions: ConfigMotionTransition = .glide, dropHints: Bool = true, experimentalDimming: Bool = false, sound: Bool = false, menuBarIcon: ConfigMenuBarIcon = .minimap, highlight: ConfigHighlight = .active, highlightWidth: Double = 2 ) { self.enabled = enabled self.level = level self.speed = speed self.transitions = transitions self.highlight = highlight self.highlightWidth = highlightWidth self.dropHints = dropHints self.experimentalDimming = experimentalDimming self.sound = sound self.menuBarIcon = menuBarIcon } public init( enabled: Bool = true, level: ConfigMotionLevel = .playful, speed: Double = 1, transitions: ConfigMotionTransition = .glide, focusBorder: Bool, dropHints: Bool = true, experimentalDimming: Bool = false, sound: Bool = false, menuBarIcon: ConfigMenuBarIcon = .minimap ) { self.init( enabled: enabled, level: level, speed: speed, transitions: transitions, dropHints: dropHints, experimentalDimming: experimentalDimming, sound: sound, menuBarIcon: menuBarIcon, highlight: focusBorder ? .active : .none) } } public struct MouseConfiguration: Equatable, Sendable { public var enabled: Bool public var swapModifiers: MouseModifiers public var stackModifiers: MouseModifiers public var moveModifiers: MouseModifiers public var resizeModifiers: MouseModifiers public var edgeSnapping: Bool public var dropToRatio: Bool public var focusFollowsMouse: Bool public var focusDelay: Double public var typingCooldown: Double public static let focusDelays = 0.1...3.0 public static let typingCooldowns = 0.0...10.0 public var isValid: Bool { let modifiers = [swapModifiers, stackModifiers, moveModifiers, resizeModifiers] return modifiers.allSatisfy { !$0.isEmpty } && Set(modifiers).count == modifiers.count && focusDelay.isFinite && Self.focusDelays.contains(focusDelay) && typingCooldown.isFinite && Self.typingCooldowns.contains(typingCooldown) } public init( enabled: Bool = true, swapModifiers: MouseModifiers = .command, stackModifiers: MouseModifiers = [.option, .command], moveModifiers: MouseModifiers = [.control, .option, .command], resizeModifiers: MouseModifiers = [.control, .option, .command, .shift], edgeSnapping: Bool = true, dropToRatio: Bool = true, focusFollowsMouse: Bool = false, focusDelay: Double = 0.35, typingCooldown: Double = 1 ) { self.enabled = enabled self.swapModifiers = swapModifiers self.stackModifiers = stackModifiers self.moveModifiers = moveModifiers self.resizeModifiers = resizeModifiers self.edgeSnapping = edgeSnapping self.dropToRatio = dropToRatio self.focusFollowsMouse = focusFollowsMouse self.focusDelay = focusDelay self.typingCooldown = typingCooldown } } public struct FloatRule: Equatable, Sendable { public var bundleID: String? public var titleRegex: String? public var role: String? public init(bundleID: String? = nil, titleRegex: String? = nil, role: String? = nil) { self.bundleID = bundleID self.titleRegex = titleRegex self.role = role } } public enum RuleAction: String, CaseIterable, Codable, Equatable, Sendable { case float, tile, ignore } public struct RuleConfiguration: Codable, Equatable, Sendable { public var bundleID: String? public var appName: String? public var titleContains: String? public var titleRegex: String? public var role: String? public var subrole: String? public var action: RuleAction? public var display: String? public var position: Int? public var layout: ConfigLayout? public var space: Int? public var moveToSpace: Bool public init( bundleID: String? = nil, appName: String? = nil, titleContains: String? = nil, titleRegex: String? = nil, role: String? = nil, subrole: String? = nil, action: RuleAction? = nil, display: String? = nil, position: Int? = nil, layout: ConfigLayout? = nil, space: Int? = nil, moveToSpace: Bool = false ) { self.bundleID = bundleID self.appName = appName self.titleContains = titleContains self.titleRegex = titleRegex self.role = role self.subrole = subrole self.action = action self.display = display self.position = position self.layout = layout self.space = space self.moveToSpace = moveToSpace } public init(from decoder: any Decoder) throws { let values = try decoder.container(keyedBy: CodingKeys.self) self.init( bundleID: try values.decodeIfPresent(String.self, forKey: .bundleID), appName: try values.decodeIfPresent(String.self, forKey: .appName), titleContains: try values.decodeIfPresent(String.self, forKey: .titleContains), titleRegex: try values.decodeIfPresent(String.self, forKey: .titleRegex), role: try values.decodeIfPresent(String.self, forKey: .role), subrole: try values.decodeIfPresent(String.self, forKey: .subrole), action: try values.decodeIfPresent(RuleAction.self, forKey: .action), display: try values.decodeIfPresent(String.self, forKey: .display), position: try values.decodeIfPresent(Int.self, forKey: .position), layout: try values.decodeIfPresent(ConfigLayout.self, forKey: .layout), space: try values.decodeIfPresent(Int.self, forKey: .space), moveToSpace: try values.decodeIfPresent(Bool.self, forKey: .moveToSpace) ?? false) } private enum CodingKeys: String, CodingKey { case bundleID = "bundle-id" case appName = "app-name" case titleContains = "title-contains" case titleRegex = "title-regex" case role, subrole, action, display, position, layout, space case moveToSpace = "move-to-space" } } public struct AccessibilityConfiguration: Equatable, Sendable { public var announceLayoutChanges: Bool public init(announceLayoutChanges: Bool = false) { self.announceLayoutChanges = announceLayoutChanges } } public struct ConfigValidationResult: Equatable, Sendable { public let configuration: ParcelConfiguration? public let diagnostics: [ConfigDiagnostic] public init(configuration: ParcelConfiguration?, diagnostics: [ConfigDiagnostic]) { self.configuration = configuration self.diagnostics = diagnostics } } enum ConfigLimits { static let ratio = 0.1...0.9 static let gap = 0.0...256.0 static let reserved = 0.0...4096.0 static let windowCap = Workspace.windowCapBounds static let speed = 0.1...4.0 }