From d8a4e700868334bb04d8c67f9cff079f53ee579e Mon Sep 17 00:00:00 2001 From: Vincent Taverna Date: Mon, 2 Nov 2026 00:31:47 -0500 Subject: [PATCH] Make shortcut defaults safe to customize Signed-off-by: Vincent Taverna --- Sources/ParcelApp/AppComposition.swift | 4 +- Sources/ParcelApp/AppHotkeys.swift | 10 +- .../ParcelApp/AppShortcutEnvironment.swift | 3 +- Sources/ParcelApp/NativeAppRuntime.swift | 34 ++++++- Sources/ParcelConfig/ConfigCommand.swift | 5 +- Sources/ParcelConfig/ConfigDefaultFile.swift | 4 + Sources/ParcelConfig/ConfigJSONSchema.swift | 9 +- Sources/ParcelConfig/ConfigValidator.swift | 37 ++++++- Sources/ParcelConfig/Configuration.swift | 26 ++++- .../ParcelConfig/Resources/Schema.xcstrings | 1 + Sources/ParcelUI/Resources/Settings.xcstrings | 14 +++ .../Settings/SettingsDocumentEditor.swift | 21 ++-- Sources/ParcelUI/Settings/SettingsModel.swift | 47 +++++++++ .../Settings/SettingsShortcutConflicts.swift | 12 ++- Sources/ParcelUI/Settings/SettingsView.swift | 66 +++++++++++-- .../ParcelUI/Settings/ShortcutRecorder.swift | 1 + Sources/prcl/ConfigCheckCommand.swift | 72 ++++++++++++++ Sources/prcl/ParcelCLI.swift | 10 +- Sources/prcl/Resources/Localizable.xcstrings | 6 ++ .../ParcelAppTests/HotkeyRecoveryTests.swift | 96 ++++++++++++++++++ .../ParcelConfigTests/BindingModeTests.swift | 21 ++-- .../ConfigJSONSchemaTests.swift | 3 + .../ConfigValidationTests.swift | 61 ++++++++++-- .../FocusModeConfigurationTests.swift | 4 +- Tests/ParcelConfigTests/KeyChordTests.swift | 10 +- Tests/ParcelIPCTests/CLITests.swift | 2 +- .../ConfigCheckCommandTests.swift | 60 ++++++++++++ .../SettingsShortcutConflictTests.swift | 17 ++++ Tests/ParcelUITests/SettingsTests.swift | 97 +++++++++++++++++-- docs/parcel.schema.json | 23 ++++- 30 files changed, 711 insertions(+), 65 deletions(-) create mode 100644 Sources/prcl/ConfigCheckCommand.swift create mode 100644 Tests/ParcelIPCTests/ConfigCheckCommandTests.swift diff --git a/Sources/ParcelApp/AppComposition.swift b/Sources/ParcelApp/AppComposition.swift index 4c2f0316..c43b0384 100644 --- a/Sources/ParcelApp/AppComposition.swift +++ b/Sources/ParcelApp/AppComposition.swift @@ -262,7 +262,9 @@ final class AppComposition { engineConfiguration = updated } do { - if updated.keybindings != registeredBindings { + if updated.keybindings != registeredBindings + || previous?.general.shortcutsEnabled != updated.general.shortcutsEnabled + { registeredBindings = try runtime.registerHotkeys(updated) } } catch { diff --git a/Sources/ParcelApp/AppHotkeys.swift b/Sources/ParcelApp/AppHotkeys.swift index c046d39e..dba50dbe 100644 --- a/Sources/ParcelApp/AppHotkeys.swift +++ b/Sources/ParcelApp/AppHotkeys.swift @@ -50,26 +50,31 @@ final class AppHotkeys { private let unregister: @MainActor (HotKey) throws -> Void private let updateRepeats: @MainActor (HotKey, Bool) -> Void private let registrationIsPresent: @MainActor (HotKey) -> Bool + private let isReserved: @MainActor (KeyChord) -> Bool init( register: @escaping @MainActor (HotKey, Bool) throws -> Void, registerSwitcher: (@MainActor (HotKey, Bool) throws -> Void)? = nil, unregister: @escaping @MainActor (HotKey) throws -> Void, updateRepeats: @escaping @MainActor (HotKey, Bool) -> Void, - registrationIsPresent: @escaping @MainActor (HotKey) -> Bool = { _ in true } + registrationIsPresent: @escaping @MainActor (HotKey) -> Bool = { _ in true }, + isReserved: @escaping @MainActor (KeyChord) -> Bool = { _ in false } ) { self.register = register self.registerSwitcher = registerSwitcher ?? register self.unregister = unregister self.updateRepeats = updateRepeats self.registrationIsPresent = registrationIsPresent + self.isReserved = isReserved } func reload(_ configuration: ParcelConfiguration, mode nextMode: String? = nil) -> ( active: [ConfigCommand: KeyChord], conflicts: [Conflict] ) { let desired: [(BindingAction, KeyChord)] - if let nextMode { + if !configuration.general.shortcutsEnabled { + desired = [] + } else if let nextMode { desired = (configuration.modes[nextMode] ?? [:]).map { ($0.key, $0.value) } .sorted { $0.1.description < $1.1.description } } else { @@ -88,6 +93,7 @@ final class AppHotkeys { var conflicts: [Conflict] = [] var failed: Set = [] for (action, chord) in desired { + guard !isReserved(chord) else { continue } if case .command(let command) = action, DefaultKeybindings.isApplicationMenuShortcut(for: command, chord: chord) { diff --git a/Sources/ParcelApp/AppShortcutEnvironment.swift b/Sources/ParcelApp/AppShortcutEnvironment.swift index cff989bc..0e2e74ef 100644 --- a/Sources/ParcelApp/AppShortcutEnvironment.swift +++ b/Sources/ParcelApp/AppShortcutEnvironment.swift @@ -29,8 +29,9 @@ final class AppShortcutEnvironment: NSObject { } func read() async throws -> SettingsShortcutEnvironment { - var environment = SettingsShortcutEnvironment() + var environment = SettingsShortcutEnvironment(voiceOverEnabled: VoiceOverStatus.isRunning) do { environment.symbolicHotKeys = try await Task.detached { try SymbolicHotKeys.read() }.value } catch { + environment.symbolicHotKeysChecked = false environment.limitations.append( AppText.string("System shortcuts could not be checked: \(error.localizedDescription)")) } diff --git a/Sources/ParcelApp/NativeAppRuntime.swift b/Sources/ParcelApp/NativeAppRuntime.swift index 4d67606a..a52ed094 100644 --- a/Sources/ParcelApp/NativeAppRuntime.swift +++ b/Sources/ParcelApp/NativeAppRuntime.swift @@ -47,7 +47,9 @@ final class NativeAppRuntime: AppRuntime { shortcutChecker: SettingsShortcutChecker( read: { [weak self] in guard let self else { throw CancellationError() } - return try await self.shortcutEnvironment.read() + let environment = try await self.shortcutEnvironment.read() + self.refreshSystemShortcutReservations(environment) + return environment }), commands: services) private let log = AppEngineLog() private lazy var callbackRunner = AppCallbackRunner { [weak self] error in @@ -79,6 +81,7 @@ final class NativeAppRuntime: AppRuntime { private var hotkeyMode: String? private var voiceOverObservation: VoiceOverObservation? private var voiceOverNoticeShown = false + private var systemShortcutKeys: Set = [] private var hotkeyGate = HotkeyDispatchGate() private var effectiveShortcuts: [ConfigCommand: KeyChord]? private var registeredShortcutConfiguration: ParcelConfiguration? @@ -446,6 +449,10 @@ final class NativeAppRuntime: AppRuntime { } func registerHotkeys(_ configuration: ParcelConfiguration) throws -> [ConfigCommand: KeyChord] { + systemShortcutKeys = try Self.systemShortcutReservations( + shortcutsEnabled: configuration.general.shortcutsEnabled, current: systemShortcutKeys, + read: { try SymbolicHotKeys.read() }) + if !configuration.general.shortcutsEnabled { tabView?.cancel(immediately: true) } secureInput.start() if hotkeyBindings == nil { let center = HotKeyCenter( @@ -526,7 +533,8 @@ final class NativeAppRuntime: AppRuntime { registerSwitcher: { key, repeats in _ = try center.register(key, repeats: repeats, switcher: true) }, unregister: { try center.unregister($0) }, updateRepeats: { center.updateRepeats($0, enabled: $1) }, - registrationIsPresent: { center.isRegistered($0) }) + registrationIsPresent: { center.isRegistered($0) }, + isReserved: { [weak self] chord in self?.systemShortcutKeys.contains(Self.hotkey(chord)) == true }) } observeVoiceOver() return refreshHotkeys(configuration, mode: services.engine?.snapshot.state.activeMode) @@ -534,6 +542,7 @@ final class NativeAppRuntime: AppRuntime { var acceptsHotkeyInput: Bool { services.engine?.isRunning == true && !services.isTourUnresolved + && (services.engine?.configuration.general.shortcutsEnabled ?? false) } private func observeVoiceOver() { @@ -548,6 +557,7 @@ final class NativeAppRuntime: AppRuntime { do { try hotkeys?.refreshActivity() } catch { services.composition?.report(error, kind: .hotkeys) } if registeredShortcutConfiguration != nil { _ = refreshShortcutPresentation() } updateVoiceOverNotice() + settings.refreshShortcutWarnings() } private func updateVoiceOverNotice() { @@ -583,6 +593,23 @@ final class NativeAppRuntime: AppRuntime { return true } + static func systemShortcutReservations( + shortcutsEnabled: Bool, current: Set, read: () throws -> [SymbolicHotKey]? + ) rethrows -> Set { + guard shortcutsEnabled, let entries = try read() else { return current } + return Set(entries.filter(\.isEnabled).compactMap(\.hotKey)) + } + + private func refreshSystemShortcutReservations(_ environment: SettingsShortcutEnvironment) { + let updated = Self.systemShortcutReservations( + shortcutsEnabled: true, current: systemShortcutKeys, + read: { environment.symbolicHotKeysChecked ? environment.symbolicHotKeys : nil }) + guard updated != systemShortcutKeys else { return } + systemShortcutKeys = updated + guard hotkeyBindings != nil, let configuration = services.engine?.configuration else { return } + _ = refreshHotkeys(configuration, mode: services.engine?.snapshot.state.activeMode) + } + private func refreshHotkeys(_ configuration: ParcelConfiguration, mode: String?) -> [ConfigCommand: KeyChord] { guard let hotkeyBindings else { preconditionFailure("The hotkey registrar was not initialized") } let result = hotkeyBindings.reload(configuration, mode: mode) @@ -647,7 +674,8 @@ final class NativeAppRuntime: AppRuntime { ) -> ParcelConfiguration { func available(_ chord: KeyChord) -> Bool { let key = hotkey(chord) - return isActive && !(voiceOverEnabled && key.conflictsWithVoiceOver) + return configuration.general.shortcutsEnabled && isActive + && !(voiceOverEnabled && key.conflictsWithVoiceOver) && (!secureInput || (routes[key] ?? HotKeyRoute.preferred(for: key)) == .carbon) } var presented = configuration diff --git a/Sources/ParcelConfig/ConfigCommand.swift b/Sources/ParcelConfig/ConfigCommand.swift index a1cb4c23..4262a98f 100644 --- a/Sources/ParcelConfig/ConfigCommand.swift +++ b/Sources/ParcelConfig/ConfigCommand.swift @@ -327,6 +327,7 @@ public enum DefaultKeybindings { ] private static let shiftPrefixDefaults: [ConfigCommand: KeyChord] = [ + .layoutTree: KeyChord(key: .f18), .focusLeft: KeyChord(key: .h), .focusRight: KeyChord(key: .l), .focusUp: KeyChord(key: .k), @@ -353,7 +354,7 @@ public enum DefaultKeybindings { .layoutColumns: KeyChord(key: .c), .layoutRows: KeyChord(key: .y), .layoutSide: KeyChord(key: .e), - .layoutTree: KeyChord(key: .t), + .layoutTree: KeyChord(modifiers: .shift, key: .t), .layoutBSP: KeyChord(key: .b), .layoutAccordion: KeyChord(key: .o), .splitHorizontal: KeyChord(key: .x), @@ -400,6 +401,6 @@ public enum DefaultKeybindings { .displayMoveRight: KeyChord(modifiers: .cmd, key: .f2), .displayMoveUp: KeyChord(modifiers: .cmd, key: .f3), .displayMoveDown: KeyChord(modifiers: .cmd, key: .f4), - .toggleAutomaticTiling: KeyChord(key: .n), + .toggleAutomaticTiling: KeyChord(key: .t), ] } diff --git a/Sources/ParcelConfig/ConfigDefaultFile.swift b/Sources/ParcelConfig/ConfigDefaultFile.swift index 5a12df38..051f1225 100644 --- a/Sources/ParcelConfig/ConfigDefaultFile.swift +++ b/Sources/ParcelConfig/ConfigDefaultFile.swift @@ -5,6 +5,10 @@ extension ConfigStore { #:schema \(ConfigJSONSchema.publishedURL) version = 1 + [general] + shortcuts-enabled = true + when-display-full = "swap" + [motion] highlight = "active" highlight-width = 2.0 diff --git a/Sources/ParcelConfig/ConfigJSONSchema.swift b/Sources/ParcelConfig/ConfigJSONSchema.swift index 1dacb98c..d17449d4 100644 --- a/Sources/ParcelConfig/ConfigJSONSchema.swift +++ b/Sources/ParcelConfig/ConfigJSONSchema.swift @@ -114,6 +114,13 @@ public enum ConfigJSONSchema { "Modifiers used only to generate inherited shortcuts; explicit shortcuts are absolute."), ]), "launch-at-login": boolean(defaults.general.launchAtLogin), + "shortcuts-enabled": boolean(defaults.general.shortcutsEnabled), + "when-display-full": choice( + ConfigWhenDisplayFull.allCases.map(\.rawValue), + defaultValue: defaults.general.whenDisplayFull.rawValue, + description: + "When a directional swap arrow reaches a full display, swap windows or stack them. Explicit display moves and new windows are unchanged." + ), ]), "callbacks": object( Dictionary( @@ -188,7 +195,7 @@ public enum ConfigJSONSchema { keybindings, extra: [ "description": .string( - "Shortcuts inherit generated defaults. Set any command to false to remove it. " + "Shortcuts inherit generated defaults. Explicit chords take priority and leave conflicting inherited defaults unbound with a warning. Set any command to false to remove it. " + "Enter-mode targets must name declared modes, even when disabled; exit-mode is only valid in named modes." ), "propertyNames": .object([ diff --git a/Sources/ParcelConfig/ConfigValidator.swift b/Sources/ParcelConfig/ConfigValidator.swift index ade48819..b249f3d2 100644 --- a/Sources/ParcelConfig/ConfigValidator.swift +++ b/Sources/ParcelConfig/ConfigValidator.swift @@ -45,6 +45,7 @@ private struct Validation { ) configuration.keybindings = bindings.commands configuration.defaultModeEntries = bindings.entries + configuration.inheritedShortcutDisplacements = bindings.displacements diagnostics.sort { if $0.location.offset != $1.location.offset { return $0.location.offset < $1.location.offset @@ -101,7 +102,12 @@ private struct Validation { var result = GeneralConfiguration() guard let node else { return result } let values = table(node, path: "general", example: "[general]\nlaunch-at-login = false") - unknownKeys(values, allowed: ["prefix", "launch-at-login"], path: "general") + unknownKeys( + values, allowed: ["prefix", "launch-at-login", "shortcuts-enabled", "when-display-full"], path: "general") + result.shortcutsEnabled = boolean( + values["shortcuts-enabled"], path: "general.shortcuts-enabled", fallback: result.shortcutsEnabled) + result.whenDisplayFull = choice( + values["when-display-full"], path: "general.when-display-full", fallback: result.whenDisplayFull) result.launchAtLogin = boolean( values["launch-at-login"], path: "general.launch-at-login", fallback: result.launchAtLogin ) @@ -777,7 +783,9 @@ extension Validation { fileprivate mutating func keybindings( _ node: TOMLNode?, prefix: KeyModifiers, prefixLocation: SourceLocation, modeNames: Set - ) -> (commands: [ConfigCommand: KeyChord], entries: [String: KeyChord]) { + ) -> ( + commands: [ConfigCommand: KeyChord], entries: [String: KeyChord], displacements: [InheritedShortcutDisplacement] + ) { var result = DefaultKeybindings.bindings(prefix: prefix) var entries: [String: KeyChord] = [:] var entryLocations: [String: SourceLocation] = [:] @@ -845,6 +853,29 @@ extension Validation { } } } + var displacements: [InheritedShortcutDisplacement] = [] + let explicit = + explicitLocations.keys.compactMap { command in + result[command].map { (BindingAction.command(command), $0, explicitLocations[command]) } + } + + entries.keys.compactMap { target in + entries[target].map { (BindingAction.enterMode(target), $0, entryLocations[target]) } + } + for command in result.keys.sorted(by: { $0.rawValue < $1.rawValue }) where explicitLocations[command] == nil { + guard let chord = result[command], + let owner = explicit.first(where: { $0.1 == chord }) + else { continue } + result.removeValue(forKey: command) + displacements.append(InheritedShortcutDisplacement(command: command, chord: chord, binding: owner.0)) + let binding = "keybindings.\(BindingModeRules.actionName(owner.0))" + diagnostics.append( + ConfigDiagnostic( + severity: .warning, location: owner.2 ?? prefixLocation, + message: String( + localized: + "keybindings.\(command.rawValue): Unbound because \(binding) uses this key (\(chord.description)).", + table: "Schema", bundle: .module), relatedLocation: prefixLocation)) + } duplicateChords(result, explicitLocations: explicitLocations, prefixLocation: prefixLocation) var records = result.map { command, chord in ModeBindingRecord( @@ -857,7 +888,7 @@ extension Validation { fallbackLocation: prefixLocation, isCommand: false) } duplicateModeChords(records, path: "keybindings", skipCommandPairs: true) - return (result, entries) + return (result, entries, displacements) } fileprivate mutating func duplicateChords( diff --git a/Sources/ParcelConfig/Configuration.swift b/Sources/ParcelConfig/Configuration.swift index dc33b9c4..f795999e 100644 --- a/Sources/ParcelConfig/Configuration.swift +++ b/Sources/ParcelConfig/Configuration.swift @@ -17,6 +17,7 @@ public struct ParcelConfiguration: Equatable, Sendable { 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] @@ -68,13 +69,36 @@ public struct ParcelConfiguration: Equatable, Sendable { } } +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 whenDisplayFull: ConfigWhenDisplayFull - public init(prefix: KeyModifiers = [.ctrl, .alt], launchAtLogin: Bool = false) { + public init( + prefix: KeyModifiers = [.ctrl, .alt], launchAtLogin: Bool = false, + shortcutsEnabled: Bool = true, whenDisplayFull: ConfigWhenDisplayFull = .swap + ) { self.prefix = prefix self.launchAtLogin = launchAtLogin + self.shortcutsEnabled = shortcutsEnabled + self.whenDisplayFull = whenDisplayFull } } diff --git a/Sources/ParcelConfig/Resources/Schema.xcstrings b/Sources/ParcelConfig/Resources/Schema.xcstrings index 0ffd2224..6db83889 100644 --- a/Sources/ParcelConfig/Resources/Schema.xcstrings +++ b/Sources/ParcelConfig/Resources/Schema.xcstrings @@ -1,6 +1,7 @@ { "sourceLanguage" : "en", "strings" : { + "keybindings.%@: Unbound because %@ uses this key (%@)." : {"comment": "The first placeholder is the unbound inherited command, the second its winning explicit binding, and the third the physical key chord.", "extractionState": "manual", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "keybindings.%@: Unbound because %@ uses this key (%@)."}}}}, "“%@” is retired; this shortcut is unbound. Bind “%@” explicitly to restore it." : { "extractionState" : "manual", "localizations" : { "en" : { "stringUnit" : { "state" : "translated", "value" : "“%@” is retired; this shortcut is unbound. Bind “%@” explicitly to restore it." } } } diff --git a/Sources/ParcelUI/Resources/Settings.xcstrings b/Sources/ParcelUI/Resources/Settings.xcstrings index 5829cc35..6a218103 100644 --- a/Sources/ParcelUI/Resources/Settings.xcstrings +++ b/Sources/ParcelUI/Resources/Settings.xcstrings @@ -1,6 +1,20 @@ { "sourceLanguage": "en", "strings": { + "Left to macOS": {"extractionState": "manual", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Left to macOS"}}}}, + "Unbound because %@ uses this key": {"comment": "The placeholder names the command or mode entry that takes priority over this inherited shortcut.", "extractionState": "manual", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Unbound because %@ uses this key"}}}}, + "Revert": {"extractionState": "manual", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Revert"}}}}, + "Revert shortcut for %@": {"extractionState": "manual", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Revert shortcut for %@"}}}}, + "Reset All": {"extractionState": "manual", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Reset All"}}}}, + "Reset all command shortcuts": {"extractionState": "manual", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Reset all command shortcuts"}}}}, + "Reset all command shortcuts?": {"extractionState": "manual", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Reset all command shortcuts?"}}}}, + "Command shortcuts and the prefix return to defaults. Named modes and the Shortcuts switch are kept.": {"extractionState": "manual", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Command shortcuts and the prefix return to defaults. Named modes and the Shortcuts switch are kept."}}}}, + "When off, all shortcut keys are left to macOS. Menu and CLI commands still work.": {"extractionState": "manual", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "When off, all shortcut keys are left to macOS. Menu and CLI commands still work."}}}}, + "Automatic tiling only controls automatic arrangement. Explicit shortcuts still work when it is off.": {"extractionState": "manual", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Automatic tiling only controls automatic arrangement. Explicit shortcuts still work when it is off."}}}}, + "When an arrow shortcut reaches a full display": {"extractionState": "manual", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "When an arrow shortcut reaches a full display"}}}}, + "Swap windows": {"extractionState": "manual", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Swap windows"}}}}, + "Directional swap arrows use this policy at a display edge. Explicit display moves and new windows are unchanged.": {"extractionState": "manual", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Directional swap arrows use this policy at a display edge. Explicit display moves and new windows are unchanged."}}}}, + "This value cannot be safely reset. Edit it in the configuration file.": {"extractionState": "manual", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "This value cannot be safely reset. Edit it in the configuration file."}}}}, "Tab View": {"localizations": {"en": {"stringUnit": {"state": "translated", "value": "Tab View"}}}}, "Always float this app": {"localizations": {"en": {"stringUnit": {"state": "translated", "value": "Always float this app"}}}}, "Move anywhere modifiers": {"localizations": {"en": {"stringUnit": {"state": "translated", "value": "Move anywhere modifiers"}}}}, diff --git a/Sources/ParcelUI/Settings/SettingsDocumentEditor.swift b/Sources/ParcelUI/Settings/SettingsDocumentEditor.swift index f9dc2816..ef9a6f14 100644 --- a/Sources/ParcelUI/Settings/SettingsDocumentEditor.swift +++ b/Sources/ParcelUI/Settings/SettingsDocumentEditor.swift @@ -6,6 +6,7 @@ enum SettingsEdit: Sendable { case values([(SettingsField, TOMLValue)]) case removeAppearanceValues([String]) case shortcut(ConfigCommand, KeyChord?) + case revertShortcuts([ConfigCommand], resetPrefix: Bool) case hoverPreferences(HoverBarConfiguration, onlyMissing: Bool) case addRule(FloatRule) case replaceRule(index: Int, original: FloatRule, replacement: FloatRule) @@ -36,7 +37,13 @@ enum SettingsDocumentEditor { try document.setValue(value, forKey: field.path(in: document)) } case .removeAppearanceValues(let keys): - for key in keys { try removeAppearanceValue(key, from: &document) } + for key in keys { try removeValue(key, table: "appearance", from: &document) } + case .revertShortcuts(let commands, let resetPrefix): + for command in commands { try removeValue(command.rawValue, table: "keybindings", from: &document) } + if commands.contains(.toggleAutomaticTiling) { + try removeValue("pause-tiling", table: "keybindings", from: &document) + } + if resetPrefix { try removeValue("prefix", table: "general", from: &document) } case .shortcut(let command, let chord): try document.setValue( chord.map { .string($0.description) } ?? .bool(false), forKey: ["keybindings", command.rawValue]) @@ -210,20 +217,20 @@ enum SettingsDocumentEditor { return range } - private static func removeAppearanceValue(_ key: String, from document: inout TOMLDocument) throws { - guard let value = document.node(forKey: ["appearance", key]) else { return } + private static func removeValue(_ key: String, table: String, from document: inout TOMLDocument) throws { + guard let value = document.node(forKey: [table, key]) else { return } guard let keyRange = value.keyRange, - let appearance = document.node(forKey: ["appearance"]), case .table(let entries) = appearance.value + let container = document.node(forKey: [table]), case .table(let entries) = container.value else { throw SettingsFailure( - AppearanceText.string( - "This appearance value cannot be safely reset. Edit it in the configuration file.")) + SettingsText.string( + "This value cannot be safely reset. Edit it in the configuration file.")) } let scalars = Array(document.source.unicodeScalars) var assignmentStart = keyRange.start.offset while assignmentStart > 0, scalars[assignmentStart - 1] != "\n" { assignmentStart -= 1 } var edits = [(removalRange(assignmentStart.. = [] + private var hasExplicitShortcutPrefix = false private(set) var modeShortcutNoticeDetails: [ModeShortcutNotice] = [] public var modeShortcutNotices: [String] { modeShortcutNoticeDetails.map(\.display) } public private(set) var shortcutCheckLimitations: [String] = [] @@ -335,6 +341,38 @@ public final class SettingsModel { try await edit(.shortcut(command, chord)) } + public func revertShortcut(for command: ConfigCommand) async throws { + try await edit(.revertShortcuts([command], resetPrefix: false)) + } + + public func resetAllShortcuts() async throws { + try await edit(.revertShortcuts(ConfigCommand.allCases, resetPrefix: true)) + } + + public func canRevertShortcut(for command: ConfigCommand) -> Bool { + explicitShortcutOverrides.contains(command) + } + + public var canResetAllShortcuts: Bool { + !explicitShortcutOverrides.isEmpty || hasExplicitShortcutPrefix + } + + public func shortcutStatus(for command: ConfigCommand) -> String? { + guard configuration.general.shortcutsEnabled else { return SettingsText.string("Left to macOS") } + if let displacement = configuration.inheritedShortcutDisplacements.first(where: { $0.command == command }) { + let owner: String = + switch displacement.binding { + case .command(let command): command.settingsTitle + case .enterMode(let name): SettingsText.string("Enter mode \(name)") + case .exitMode: SettingsText.string("Exit mode") + } + return SettingsText.string("Unbound because \(owner) uses this key") + } + guard let chord = configuration.keybindings[command] else { return SettingsText.string("Left to macOS") } + return SettingsShortcutChecker.isLeftToMacOS(chord, environment: checkedShortcutEnvironment) + ? SettingsText.string("Left to macOS") : nil + } + public func setShortcut(text: String, for command: ConfigCommand) async throws { do { try await setShortcut(ShortcutRecorderParser.parse(text), for: command) @@ -412,7 +450,16 @@ public final class SettingsModel { pendingWindowRuleUndo = nil } latest = snapshot + explicitShortcutOverrides = Set( + ConfigCommand.allCases.filter { + snapshot.lastGoodDocument?.node(forKey: ["keybindings", $0.rawValue]) != nil + }) + if snapshot.lastGoodDocument?.node(forKey: ["keybindings", "pause-tiling"]) != nil { + explicitShortcutOverrides.insert(.toggleAutomaticTiling) + } + hasExplicitShortcutPrefix = snapshot.lastGoodDocument?.node(forKey: ["general", "prefix"]) != nil configuration = snapshot.activeConfiguration + if !configuration.general.shortcutsEnabled { onRecordedShortcut = nil } if changed { refreshShortcutWarnings() } diagnostics = snapshot.diagnostics let failures = snapshot.diagnostics.filter { $0.severity == .error } diff --git a/Sources/ParcelUI/Settings/SettingsShortcutConflicts.swift b/Sources/ParcelUI/Settings/SettingsShortcutConflicts.swift index 2c4881a4..27b8f990 100644 --- a/Sources/ParcelUI/Settings/SettingsShortcutConflicts.swift +++ b/Sources/ParcelUI/Settings/SettingsShortcutConflicts.swift @@ -5,14 +5,18 @@ public struct SettingsShortcutEnvironment: Equatable, Sendable { public var symbolicHotKeys: [SymbolicHotKey] public var menuShortcuts: [ParcelPlatform.MenuShortcut] public var limitations: [String] + public var voiceOverEnabled: Bool + public var symbolicHotKeysChecked: Bool public init( symbolicHotKeys: [SymbolicHotKey] = [], menuShortcuts: [ParcelPlatform.MenuShortcut] = [], - limitations: [String] = [] + limitations: [String] = [], voiceOverEnabled: Bool = false, symbolicHotKeysChecked: Bool = true ) { self.symbolicHotKeys = symbolicHotKeys self.menuShortcuts = menuShortcuts self.limitations = limitations + self.voiceOverEnabled = voiceOverEnabled + self.symbolicHotKeysChecked = symbolicHotKeysChecked } } @@ -36,6 +40,12 @@ public struct SettingsShortcutChecker { public func environment() async throws -> SettingsShortcutEnvironment { try await read() } + public static func isLeftToMacOS(_ chord: KeyChord, environment: SettingsShortcutEnvironment) -> Bool { + let key = hotkey(chord) + return (environment.voiceOverEnabled && key.conflictsWithVoiceOver) + || environment.symbolicHotKeys.contains { $0.isEnabled && $0.hotKey == key } + } + public static func warnings( bindings: [ConfigCommand: KeyChord], environment: SettingsShortcutEnvironment, additionalBindings: [KeyChord] = [] diff --git a/Sources/ParcelUI/Settings/SettingsView.swift b/Sources/ParcelUI/Settings/SettingsView.swift index 64e95dfa..b685cab0 100644 --- a/Sources/ParcelUI/Settings/SettingsView.swift +++ b/Sources/ParcelUI/Settings/SettingsView.swift @@ -106,6 +106,7 @@ public struct SettingsView: View { @State private var liveDisplays: [Display] = [] @State private var displayFailure: String? @State private var section = SettingsSection.general + @State private var resettingShortcuts = false public init(model: SettingsModel, permissions: AnyView) { self.init(model: model, permissions: permissions, initialSection: .general) @@ -159,6 +160,16 @@ public struct SettingsView: View { if let shortcut { ShortcutEditor(model: model, command: shortcut) } } .sheet(item: $ruleDraft) { draft in RuleEditor(model: model, draft: draft) } + .confirmationDialog(SettingsText.string("Reset all command shortcuts?"), isPresented: $resettingShortcuts) { + Button(SettingsText.string("Reset All"), role: .destructive) { + perform { try await model.resetAllShortcuts() } + } + } message: { + Text( + SettingsText.string( + "Command shortcuts and the prefix return to defaults. Named modes and the Shortcuts switch are kept." + )) + } } @ViewBuilder private var sectionContent: some View { @@ -250,6 +261,23 @@ public struct SettingsView: View { "The prefix applies to inherited shortcuts. Explicit shortcuts keep their own modifiers.") ) .font(.caption).foregroundStyle(.secondary) + Picker( + SettingsText.string("When an arrow shortcut reaches a full display"), + selection: Binding( + get: { model.configuration.general.whenDisplayFull }, + set: { value in perform { try await model.setValue(.string(value.rawValue), for: .whenDisplayFull) } + }) + ) { + Text(SettingsText.string("Swap windows")).tag(ConfigWhenDisplayFull.swap) + Text(SettingsText.string("Stack windows")).tag(ConfigWhenDisplayFull.stack) + } + .accessibilityIdentifier("settings.general.whenDisplayFull") + Text( + SettingsText.string( + "Directional swap arrows use this policy at a display edge. Explicit display moves and new windows are unchanged." + ) + ) + .font(.caption).foregroundStyle(.secondary) Toggle( SettingsText.string("Announce layout changes"), isOn: boolean(model.configuration.accessibility.announceLayoutChanges, field: .announceLayoutChanges)) @@ -520,6 +548,24 @@ public struct SettingsView: View { private var shortcuts: some View { Form { + Toggle( + SettingsText.string("Shortcuts"), + isOn: boolean(model.configuration.general.shortcutsEnabled, field: .shortcutsEnabled) + ) + .accessibilityIdentifier("settings.shortcuts.enabled") + Text( + SettingsText.string("When off, all shortcut keys are left to macOS. Menu and CLI commands still work.") + ) + .font(.caption).foregroundStyle(.secondary) + Text( + SettingsText.string( + "Automatic tiling only controls automatic arrangement. Explicit shortcuts still work when it is off." + ) + ) + .font(.caption).foregroundStyle(.secondary) + Button(SettingsText.string("Reset All")) { resettingShortcuts = true } + .disabled(!model.canResetAllShortcuts || model.isSaving) + .accessibilityLabel(SettingsText.string("Reset all command shortcuts")) if let notice = model.shortcutNotice { Text(notice).textSelection(.enabled) } ForEach(model.shortcutCheckLimitations, id: \.self) { Text($0).font(.caption) } ForEach(model.modeShortcutNoticeDetails, id: \.display) { notice in @@ -527,14 +573,20 @@ public struct SettingsView: View { } Button(SettingsText.string("Check shortcut conflicts")) { model.refreshShortcutWarnings() } ForEach(ConfigCommand.bindableCases, id: \.self) { command in - LabeledContent(command.settingsTitle) { - if let chord = model.configuration.keybindings[command] { - ShortcutLabel(chord: chord) - } else { - Text(SettingsText.string("Not assigned")) + VStack(alignment: .leading, spacing: 6) { + LabeledContent(command.settingsTitle) { + if let chord = model.configuration.keybindings[command] { ShortcutLabel(chord: chord) } + Button(SettingsText.string("Edit shortcut")) { shortcut = command } + .accessibilityLabel(SettingsText.string("Edit shortcut for \(command.settingsTitle)")) + Button(SettingsText.string("Revert")) { + perform { try await model.revertShortcut(for: command) } + } + .disabled(!model.canRevertShortcut(for: command) || model.isSaving) + .accessibilityLabel(SettingsText.string("Revert shortcut for \(command.settingsTitle)")) + } + if let status = model.shortcutStatus(for: command) { + Text(status).font(.caption).foregroundStyle(.secondary).textSelection(.enabled) } - Button(SettingsText.string("Edit shortcut")) { shortcut = command } - .accessibilityLabel(SettingsText.string("Edit shortcut for \(command.settingsTitle)")) } } } diff --git a/Sources/ParcelUI/Settings/ShortcutRecorder.swift b/Sources/ParcelUI/Settings/ShortcutRecorder.swift index e0196aa2..0b36da7d 100644 --- a/Sources/ParcelUI/Settings/ShortcutRecorder.swift +++ b/Sources/ParcelUI/Settings/ShortcutRecorder.swift @@ -133,6 +133,7 @@ struct ShortcutEditor: View { .onDisappear { model.onRecordedShortcut = nil } .onChange(of: text) { check() } .onChange(of: model.configuration.keybindings) { check() } + .onChange(of: model.configuration.general.shortcutsEnabled) { recording = false } .onChange(of: model.configuration.defaultModeEntries) { check() } .onChange(of: model.checkedShortcutEnvironment) { environment = model.checkedShortcutEnvironment diff --git a/Sources/prcl/ConfigCheckCommand.swift b/Sources/prcl/ConfigCheckCommand.swift new file mode 100644 index 00000000..1d7f6118 --- /dev/null +++ b/Sources/prcl/ConfigCheckCommand.swift @@ -0,0 +1,72 @@ +import ArgumentParser +import Foundation +import ParcelConfig + +struct ConfigurationCommand: AsyncParsableCommand { + static let configuration = CommandConfiguration( + commandName: "config", + abstract: String(localized: "Inspect local configuration without connecting to Parcel.", bundle: .module), + subcommands: [ConfigCheckCommand.self]) +} + +struct ConfigCheckCommand: CLICommand { + static let configuration = CommandConfiguration( + commandName: "check", + abstract: String(localized: "Validate the configuration and report unbound shortcuts.", bundle: .module)) + + @OptionGroup var output: CLIOptions + @Option(help: ArgumentHelp(String(localized: "Configuration file to check.", bundle: .module))) + var path: String = ConfigStore.defaultFileURL.path + + var invocation: CLIInvocation { .configCheck(path: path, json: output.json) } +} + +struct ConfigCheckReport: Encodable { + struct Diagnostic: Encodable { + let severity: String + let line: Int + let column: Int + let message: String + } + + let valid: Bool + let diagnostics: [Diagnostic] + + static func validate(_ source: String) -> Self { + let diagnostics: [ConfigDiagnostic] + let valid: Bool + do { + let result = ConfigValidator.validate(try TOMLDocument(parsing: source)) + valid = result.configuration != nil + diagnostics = result.diagnostics + } catch let diagnostic as ConfigDiagnostic { + valid = false + diagnostics = [diagnostic] + } catch { + preconditionFailure("TOML parsing must report a configuration diagnostic: \(error)") + } + return Self( + valid: valid, + diagnostics: diagnostics.map { + Diagnostic( + severity: $0.severity == .error ? "error" : "warning", line: $0.location.line, + column: $0.location.column, message: $0.message) + }) + } + + func format(json: Bool) throws -> String { + if json { + let encoder = JSONEncoder() + encoder.outputFormatting = [.sortedKeys, .withoutEscapingSlashes] + return String(decoding: try encoder.encode(self), as: UTF8.self) + "\n" + } + let heading = + valid + ? String(localized: "Configuration is valid.", bundle: .module) + : String(localized: "Configuration is invalid.", bundle: .module) + let details = diagnostics.map { + String(localized: "\($0.severity): line \($0.line), column \($0.column): \($0.message)", bundle: .module) + } + return ([heading] + details).joined(separator: "\n") + "\n" + } +} diff --git a/Sources/prcl/ParcelCLI.swift b/Sources/prcl/ParcelCLI.swift index 25cc3dbb..934845de 100644 --- a/Sources/prcl/ParcelCLI.swift +++ b/Sources/prcl/ParcelCLI.swift @@ -34,7 +34,7 @@ struct ParcelCLI: AsyncParsableCommand { SimpleCommand.self, SimpleCommand.self, SubscribeCommand.self, PingCommand.self, ReloadCommand.self, VersionCommand.self, RunCommand.self, WhyCommand.self, DiagnosticsCommand.self, SchemaCommand.self, MinimumsCommand.self, - MemoryCommand.self, + MemoryCommand.self, ConfigurationCommand.self, SpaceFocusCommand.self, WindowToSpaceCommand.self, SimpleCommand.self, SimpleCommand.self, SimpleCommand.self, @@ -54,6 +54,7 @@ enum CLIInvocation: Sendable, Equatable { case subscribe(topics: [IPCTopic], json: Bool) case version case schema + case configCheck(path: String, json: Bool) static func engine(_ command: String, args: [String], json: Bool) -> Self { .request(command: "run", args: [command] + args, query: nil, json: json) @@ -479,6 +480,11 @@ struct CLIRunner { case .schema: try write(ConfigJSONSchema.string + "\n") return + case .configCheck(let path, let json): + let report = ConfigCheckReport.validate(try String(contentsOfFile: path, encoding: .utf8)) + try write(report.format(json: json)) + if !report.valid { throw ExitCode.failure } + return case .request, .subscribe: break } @@ -504,7 +510,7 @@ struct CLIRunner { await subscription.cancel() throw error } - case .version, .schema: + case .version, .schema, .configCheck: break } await client.close() diff --git a/Sources/prcl/Resources/Localizable.xcstrings b/Sources/prcl/Resources/Localizable.xcstrings index b3943127..b2f5d65a 100644 --- a/Sources/prcl/Resources/Localizable.xcstrings +++ b/Sources/prcl/Resources/Localizable.xcstrings @@ -1,6 +1,12 @@ { "sourceLanguage" : "en", "strings" : { + "Inspect local configuration without connecting to Parcel.": {"extractionState": "manual", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Inspect local configuration without connecting to Parcel."}}}}, + "Validate the configuration and report unbound shortcuts.": {"extractionState": "manual", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Validate the configuration and report unbound shortcuts."}}}}, + "Configuration file to check.": {"extractionState": "manual", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Configuration file to check."}}}}, + "%@: line %lld, column %lld: %@": {"extractionState": "manual", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "%@: line %lld, column %lld: %@"}}}}, + "Configuration is valid.": {"extractionState": "manual", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Configuration is valid."}}}}, + "Configuration is invalid.": {"extractionState": "manual", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Configuration is invalid."}}}}, "Toggle automatic tiling; explicit commands still work when off.": {"localizations": {"en": {"stringUnit": {"state": "translated", "value": "Toggle automatic tiling; explicit commands still work when off."}}}}, "Inspect, save, or forget remembered layouts.": {"localizations": {"en": {"stringUnit": {"state": "translated", "value": "Inspect, save, or forget remembered layouts."}}}}, "Action: inspect, save, reset.": {"localizations": {"en": {"stringUnit": {"state": "translated", "value": "Action: inspect, save, reset."}}}}, diff --git a/Tests/ParcelAppTests/HotkeyRecoveryTests.swift b/Tests/ParcelAppTests/HotkeyRecoveryTests.swift index 9f537f00..96094341 100644 --- a/Tests/ParcelAppTests/HotkeyRecoveryTests.swift +++ b/Tests/ParcelAppTests/HotkeyRecoveryTests.swift @@ -7,6 +7,102 @@ import Testing @MainActor struct HotkeyRecoveryTests { + @Test func masterOffDoesNotReadSystemPreferencesAndEnabledReadErrorsSurface() throws { + enum ReadFailure: Error { case unavailable } + let key = NativeAppRuntime.hotkey(KeyChord(modifiers: [.ctrl, .alt], key: .t)) + let existing: Set = [key] + #expect( + try NativeAppRuntime.systemShortcutReservations( + shortcutsEnabled: false, current: existing, read: { throw ReadFailure.unavailable }) == existing) + #expect(throws: ReadFailure.self) { + try NativeAppRuntime.systemShortcutReservations( + shortcutsEnabled: true, current: existing, read: { throw ReadFailure.unavailable }) + } + #expect( + NativeAppRuntime.systemShortcutReservations(shortcutsEnabled: true, current: existing, read: { nil }) + == existing) + } + + @Test func freshSystemReservationSnapshotsUnregisterAndRestoreConfiguredChords() { + let chord = KeyChord(modifiers: [.ctrl, .alt], key: .t) + let key = NativeAppRuntime.hotkey(chord) + let configuration = ParcelConfiguration(keybindings: [.toggleAutomaticTiling: chord]) + let reserved = Mutex(Set()) + var installed: Set = [] + let hotkeys = AppHotkeys( + register: { key, _ in installed.insert(key) }, unregister: { installed.remove($0) }, + updateRepeats: { _, _ in }, + isReserved: { chord in reserved.withLock { $0.contains(NativeAppRuntime.hotkey(chord)) } }) + #expect(hotkeys.reload(configuration).active == configuration.keybindings) + reserved.withLock { keys in + keys = NativeAppRuntime.systemShortcutReservations( + shortcutsEnabled: true, current: keys, + read: { [SymbolicHotKey(id: 1, isEnabled: true, hotKey: key)] }) + } + #expect(hotkeys.reload(configuration).active.isEmpty) + #expect(installed.isEmpty) + reserved.withLock { keys in + keys = NativeAppRuntime.systemShortcutReservations(shortcutsEnabled: true, current: keys, read: { nil }) + } + #expect(hotkeys.reload(configuration).active.isEmpty) + reserved.withLock { keys in + keys = NativeAppRuntime.systemShortcutReservations( + shortcutsEnabled: true, current: keys, + read: { [SymbolicHotKey(id: 1, isEnabled: false, hotKey: key)] }) + } + #expect(hotkeys.reload(configuration).active == configuration.keybindings) + #expect(installed == [key]) + } + + @Test func masterSwitchUnregistersAllBindingsAndReenablesWithoutLosingConfiguration() throws { + let chord = KeyChord(modifiers: [.ctrl, .alt], key: .t) + let key = NativeAppRuntime.hotkey(chord) + var configuration = ParcelConfiguration(keybindings: [.toggleAutomaticTiling: chord]) + var installed: Set = [] + let hotkeys = AppHotkeys( + register: { key, _ in installed.insert(key) }, unregister: { installed.remove($0) }, + updateRepeats: { _, _ in }) + #expect(hotkeys.reload(configuration).active == configuration.keybindings) + configuration.general.shortcutsEnabled = false + #expect(hotkeys.reload(configuration).active.isEmpty) + #expect(installed.isEmpty) + #expect(hotkeys.action(for: HotKeyPress(hotKey: key, isRepeat: false)) == nil) + #expect(configuration.keybindings[.toggleAutomaticTiling] == chord) + configuration.general.shortcutsEnabled = true + #expect(hotkeys.reload(configuration).active == configuration.keybindings) + #expect(installed == [key]) + } + + @Test func masterSwitchAlsoDisablesNamedModeAndEntryBindings() { + let chord = KeyChord(modifiers: .cmd, key: .f20) + var configuration = ParcelConfiguration( + keybindings: [:], defaultModeEntries: ["resize": chord], modes: ["resize": [.command(.retile): chord]]) + var installed: Set = [] + let hotkeys = AppHotkeys( + register: { key, _ in installed.insert(key) }, unregister: { installed.remove($0) }, + updateRepeats: { _, _ in }) + #expect(hotkeys.reload(configuration).conflicts.isEmpty) + #expect(!installed.isEmpty) + configuration.general.shortcutsEnabled = false + #expect(hotkeys.reload(configuration, mode: "resize").active.isEmpty) + #expect(installed.isEmpty) + #expect(hotkeys.bindings.isEmpty) + } + + @Test func reservedSystemShortcutIsNotRegisteredOrAdvertised() { + let chord = KeyChord(modifiers: [.ctrl, .alt], key: .t) + let configuration = ParcelConfiguration(keybindings: [.toggleAutomaticTiling: chord]) + let hotkeys = AppHotkeys( + register: { _, _ in Issue.record("Reserved shortcut must remain with macOS") }, unregister: { _ in }, + updateRepeats: { _, _ in }, isReserved: { $0 == chord }) + #expect(hotkeys.reload(configuration).active.isEmpty) + #expect(hotkeys.bindings.isEmpty) + #expect( + NativeAppRuntime.shortcutPresentation( + ParcelConfiguration(general: GeneralConfiguration(shortcutsEnabled: false)), secureInput: false + ).keybindings.isEmpty) + } + @Test func nativeApplicationShortcutsStayLocalButCustomReplacementsRegisterGlobally() throws { var configuration = ParcelConfiguration.defaults configuration.defaultModeEntries = [:] diff --git a/Tests/ParcelConfigTests/BindingModeTests.swift b/Tests/ParcelConfigTests/BindingModeTests.swift index 85db9234..8cb3be84 100644 --- a/Tests/ParcelConfigTests/BindingModeTests.swift +++ b/Tests/ParcelConfigTests/BindingModeTests.swift @@ -154,15 +154,18 @@ struct BindingModeTests { #expect(result.diagnostics.contains { $0.message.contains("Expected a table") }) } - @Test func modeEntryConflictsWithInheritedDefault() throws { + @Test func explicitModeEntryDisplacesInheritedDefault() throws { let document = try TOMLDocument(parsing: "[keybindings]\n\"enter-mode resize\" = \"ctrl-alt-r\"\n[mode.resize]") let result = ConfigValidator.validate(document) - #expect(result.configuration == nil) - let error = try #require(result.diagnostics.first) - #expect(error.location == document.root["keybindings"]?["enter-mode resize"]?.range.start) - #expect(error.relatedLocation == document.root.range.start) - #expect(error.message.contains("retile")) - #expect(error.message.contains("inherited default")) + let value = try #require(result.configuration) + #expect(value.keybindings[.retile] == nil) + #expect(value.defaultModeEntries["resize"] == KeyChord(modifiers: [.ctrl, .alt], key: .r)) + let warning = try #require(result.diagnostics.first) + #expect(warning.severity == .warning) + #expect(warning.location == document.root["keybindings"]?["enter-mode resize"]?.range.start) + #expect(warning.relatedLocation == document.root.range.start) + #expect(warning.message.contains("retile")) + #expect(warning.message.contains("Unbound because keybindings.enter-mode resize uses this key")) #expect( try configuration( "[keybindings]\nretile = false\n\"enter-mode resize\" = \"ctrl-alt-r\"\n[mode.resize]" @@ -181,8 +184,10 @@ struct BindingModeTests { parsing: "[general]\nprefix = \"fn\"\n[keybindings]\n\"enter-mode first\" = \"fn-r\"\n[mode.first]" ) let prefixed = ConfigValidator.validate(document) - #expect(prefixed.configuration == nil) + #expect(prefixed.configuration?.keybindings[.retile] == nil) + #expect(prefixed.configuration?.defaultModeEntries["first"] == KeyChord(modifiers: .fn, key: .r)) let conflict = try #require(prefixed.diagnostics.first) + #expect(conflict.severity == .warning) #expect(conflict.location.line == 4) #expect(conflict.relatedLocation == document.root["general"]?["prefix"]?.range.start) } diff --git a/Tests/ParcelConfigTests/ConfigJSONSchemaTests.swift b/Tests/ParcelConfigTests/ConfigJSONSchemaTests.swift index d9cff945..fbf1600f 100644 --- a/Tests/ParcelConfigTests/ConfigJSONSchemaTests.swift +++ b/Tests/ParcelConfigTests/ConfigJSONSchemaTests.swift @@ -39,6 +39,9 @@ struct ConfigJSONSchemaTests { let general = try schema()["properties"]?["general"]?["properties"] #expect(general?["prefix"]?["default"] == .string(ParcelConfiguration.defaults.general.prefix.description)) #expect(general?["launch-at-login"]?["default"] == .bool(false)) + #expect(general?["shortcuts-enabled"]?["default"] == .bool(true)) + #expect(general?["when-display-full"]?["default"] == .string("swap")) + #expect(general?["when-display-full"]?["enum"] == .array([.string("swap"), .string("stack")])) } @Test func schemaLayoutEnumMatchesModel() throws { diff --git a/Tests/ParcelConfigTests/ConfigValidationTests.swift b/Tests/ParcelConfigTests/ConfigValidationTests.swift index a93ee5d7..ef2e2b8a 100644 --- a/Tests/ParcelConfigTests/ConfigValidationTests.swift +++ b/Tests/ParcelConfigTests/ConfigValidationTests.swift @@ -17,6 +17,42 @@ struct ConfigValidationTests { #expect(try configuration("version = 1") == .defaults) } + @Test(arguments: ConfigWhenDisplayFull.allCases) + func fullDisplayPolicyAndMasterShortcutsParseIndependently(_ policy: ConfigWhenDisplayFull) throws { + #expect(ParcelConfiguration.defaults.general.whenDisplayFull == .swap) + #expect(ParcelConfiguration.defaults.general.shortcutsEnabled) + let value = try configuration( + "[general]\nwhen-display-full = '\(policy.rawValue)'\nshortcuts-enabled = false\n") + #expect(value.general.whenDisplayFull == policy) + #expect(!value.general.shortcutsEnabled) + #expect(value.keybindings == DefaultKeybindings.bindings()) + } + + @Test(arguments: ["when-display-full = 'float'", "when-display-full = false", "shortcuts-enabled = 'false'"]) + func invalidGeneralShortcutAndDisplayPoliciesAreRejected(_ assignment: String) throws { + #expect(try validate("[general]\n\(assignment)").configuration == nil) + } + + @Test func explicitOldTreeChordWinsNewAutomaticTilingDefault() throws { + let result = try validate("[keybindings]\nlayout-tree = 'ctrl-alt-t'\n") + let value = try #require(result.configuration) + #expect(value.keybindings[.layoutTree] == KeyChord(modifiers: [.ctrl, .alt], key: .t)) + #expect(value.keybindings[.toggleAutomaticTiling] == nil) + #expect(result.diagnostics.count == 1) + #expect(result.diagnostics.first?.severity == .warning) + #expect( + result.diagnostics.first?.message.contains("Unbound because keybindings.layout-tree uses this key") == true) + } + + @Test func explicitModeEntryWinsInheritedDefault() throws { + let result = try validate("[keybindings]\n\"enter-mode resize\" = 'ctrl-alt-t'\n[mode.resize]\n") + let value = try #require(result.configuration) + #expect(value.keybindings[.toggleAutomaticTiling] == nil) + #expect(value.defaultModeEntries["resize"] == KeyChord(modifiers: [.ctrl, .alt], key: .t)) + #expect(value.inheritedShortcutDisplacements.first?.binding == .enterMode("resize")) + #expect(result.diagnostics.first?.severity == .warning) + } + @Test func defaultPrefix() { #expect(ParcelConfiguration.defaults.general.prefix == [.ctrl, .alt]) } @@ -1017,16 +1053,23 @@ extension ConfigValidationTests { #expect(result.diagnostics.count == 1) } - @Test func inheritedDefaultConflictIsExplicitlyIdentified() throws { + @Test func explicitShortcutDisplacesInheritedDefaultWithWarning() throws { let chord = try #require(DefaultKeybindings.bindings()[.focusRight]) let document = try TOMLDocument(parsing: "[keybindings]\nfocus-left = \"\(chord.description)\"") let result = ConfigValidator.validate(document) - #expect(result.configuration == nil) - let error = try #require(result.diagnostics.first) - #expect(error.message.contains("inherited default")) - #expect(error.message.contains("focus-right")) - #expect(error.location == document.root["keybindings"]?["focus-left"]?.range.start) - #expect(error.relatedLocation == document.root.range.start) + let configuration = try #require(result.configuration) + #expect(configuration.keybindings[.focusLeft] == chord) + #expect(configuration.keybindings[.focusRight] == nil) + #expect( + configuration.inheritedShortcutDisplacements == [ + InheritedShortcutDisplacement(command: .focusRight, chord: chord, binding: .command(.focusLeft)) + ]) + let warning = try #require(result.diagnostics.first) + #expect(warning.severity == .warning) + #expect(warning.message.contains("Unbound because keybindings.focus-left uses this key")) + #expect(warning.message.contains("focus-right")) + #expect(warning.location == document.root["keybindings"]?["focus-left"]?.range.start) + #expect(warning.relatedLocation == document.root.range.start) } @Test func inheritedConflictPointsToChangedPrefix() throws { @@ -1036,7 +1079,9 @@ extension ConfigValidationTests { let result = ConfigValidator.validate(document) let error = try #require(result.diagnostics.first) #expect(error.relatedLocation == document.root["general"]?["prefix"]?.range.start) - #expect(error.message.contains("inherited default")) + #expect(result.configuration != nil) + #expect(error.severity == .warning) + #expect(error.message.contains("Unbound because")) } @Test func disablingInheritedBindingResolvesConflict() throws { diff --git a/Tests/ParcelConfigTests/FocusModeConfigurationTests.swift b/Tests/ParcelConfigTests/FocusModeConfigurationTests.swift index 3ae931a2..9a6f1d38 100644 --- a/Tests/ParcelConfigTests/FocusModeConfigurationTests.swift +++ b/Tests/ParcelConfigTests/FocusModeConfigurationTests.swift @@ -80,7 +80,9 @@ import Testing for (command, key) in modeKeys { #expect(bindings[command] == KeyChord(modifiers: prefix, key: key)) } - #expect(bindings[.toggleAutomaticTiling] == KeyChord(modifiers: prefix, key: .n)) + #expect(bindings[.toggleAutomaticTiling] == KeyChord(modifiers: prefix, key: .t)) + let treeKey = prefix.contains(.shift) ? ANSIKey.f18 : .t + #expect(bindings[.layoutTree] == KeyChord(modifiers: prefix.union(.shift), key: treeKey)) let moveRight = prefix.contains(.shift) ? ANSIKey.f13 : .d #expect(bindings[.moveRight] == KeyChord(modifiers: prefix.union(.shift), key: moveRight)) } diff --git a/Tests/ParcelConfigTests/KeyChordTests.swift b/Tests/ParcelConfigTests/KeyChordTests.swift index 4c7e9b9a..062c7da7 100644 --- a/Tests/ParcelConfigTests/KeyChordTests.swift +++ b/Tests/ParcelConfigTests/KeyChordTests.swift @@ -227,9 +227,11 @@ struct DefaultKeybindingsTests { #expect(Set(bindings.values).count == bindings.count) let shiftAlternates: [ConfigCommand: ANSIKey] = [ .focusLeft: .h, .focusRight: .l, .focusUp: .k, .focusDown: .j, - .moveRight: .f13, .alwaysFloat: .f16, .stackPrevious: .backslash, + .moveRight: .f13, .alwaysFloat: .f16, .stackPrevious: .backslash, .layoutTree: .f18, ] - #expect(Set(bindings.values.map(\.keyCode)).count == bindings.count - (prefix.contains(.shift) ? 0 : 7)) + #expect( + Set(bindings.values.map(\.keyCode)).count + == bindings.count - (prefix.contains(.shift) ? 0 : shiftAlternates.count)) for command in bindings.keys { let chord = try #require(bindings[command]) let base = try #require(withoutPrefix[command]) @@ -449,7 +451,7 @@ private enum KeyChordSamples { (.moveUp, "ctrl-alt-shift-w"), (.moveDown, "ctrl-alt-shift-s"), (.layoutGrid, "ctrl-alt-g"), (.layoutColumns, "ctrl-alt-c"), (.layoutRows, "ctrl-alt-y"), (.layoutSide, "ctrl-alt-e"), - (.layoutTree, "ctrl-alt-t"), (.layoutBSP, "ctrl-alt-b"), (.layoutAccordion, "ctrl-alt-o"), + (.layoutTree, "ctrl-alt-shift-t"), (.layoutBSP, "ctrl-alt-b"), (.layoutAccordion, "ctrl-alt-o"), (.splitHorizontal, "ctrl-alt-x"), (.splitVertical, "ctrl-alt-v"), (.joinLeft, "ctrl-alt-f5"), (.joinRight, "ctrl-alt-f6"), (.joinUp, "ctrl-alt-f7"), (.joinDown, "ctrl-alt-f8"), (.balance, "ctrl-alt-f9"), (.rotate, "ctrl-alt-f10"), @@ -470,7 +472,7 @@ private enum KeyChordSamples { (.toggleHoverFocus, "ctrl-alt-i"), (.displayMoveLeft, "ctrl-alt-cmd-f1"), (.displayMoveRight, "ctrl-alt-cmd-f2"), (.displayMoveUp, "ctrl-alt-cmd-f3"), (.displayMoveDown, "ctrl-alt-cmd-f4"), - (.openSettings, "cmd-,"), (.toggleAutomaticTiling, "ctrl-alt-n"), (.quit, "cmd-q"), + (.openSettings, "cmd-,"), (.toggleAutomaticTiling, "ctrl-alt-t"), (.quit, "cmd-q"), ] static let commands: [(ConfigCommand, String)] = [ diff --git a/Tests/ParcelIPCTests/CLITests.swift b/Tests/ParcelIPCTests/CLITests.swift index 846dd796..d21a4409 100644 --- a/Tests/ParcelIPCTests/CLITests.swift +++ b/Tests/ParcelIPCTests/CLITests.swift @@ -565,7 +565,7 @@ struct CLIEngineReachabilityTests { #expect(Set(CLIEngineScenario.all.map { $0.arguments[0] }).count == 33) let other: Set = [ "query", "subscribe", "ping", "reload", "version", "run", "why", "diagnostics", "schema", "minimums", - "memory", "toggle-automatic-tiling", + "memory", "config", "toggle-automatic-tiling", "space-focus", "space-next", "space-previous", "space-back-and-forth", "window-to-space", "window-to-space-next", "window-to-space-previous", ] diff --git a/Tests/ParcelIPCTests/ConfigCheckCommandTests.swift b/Tests/ParcelIPCTests/ConfigCheckCommandTests.swift new file mode 100644 index 00000000..5494b61b --- /dev/null +++ b/Tests/ParcelIPCTests/ConfigCheckCommandTests.swift @@ -0,0 +1,60 @@ +import ArgumentParser +import Foundation +import ParcelConfig +import Synchronization +import Testing + +@testable import prcl + +struct ConfigCheckCommandTests { + @Test func parsesLocalValidationCommand() throws { + #expect( + try CLIParsing.parse(["config", "check"]) + == .configCheck(path: ConfigStore.defaultFileURL.path, json: false)) + #expect( + try CLIParsing.parse(["config", "check", "--path", "custom.toml", "--json"]) + == .configCheck(path: "custom.toml", json: true)) + } + + @Test func inheritedDisplacementIsAValidWarningAndExplicitDuplicatesAreErrors() throws { + let warning = ConfigCheckReport.validate("[keybindings]\nlayout-tree = 'ctrl-alt-t'\n") + #expect(warning.valid) + #expect(warning.diagnostics.first?.severity == "warning") + #expect(try warning.format(json: false).contains("Unbound because keybindings.layout-tree uses this key")) + let error = ConfigCheckReport.validate( + "[keybindings]\nlayout-tree = 'ctrl-alt-t'\ntoggle-automatic-tiling = 'ctrl-alt-t'\n") + #expect(!error.valid) + #expect(error.diagnostics.first?.severity == "error") + #expect(!ConfigCheckReport.validate("[broken").valid) + } + + @Test func validatesWithoutConnectingAndKeepsWarningsSuccessful() async throws { + let directory = FileManager.default.temporaryDirectory.appendingPathComponent( + "parcel-config-check-\(UUID().uuidString)") + try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: false) + defer { + do { try FileManager.default.removeItem(at: directory) } catch { Issue.record(error) } + } + let file = directory.appendingPathComponent("parcel.toml") + try "[keybindings]\nlayout-tree = 'ctrl-alt-t'\n".write(to: file, atomically: true, encoding: .utf8) + let output = Mutex("") + try await CLIRunner.execute(.configCheck(path: file.path, json: true), socketPath: "not-an-absolute-path") { + text in + output.withLock { $0 += text } + } + let report = try JSONDecoder().decode(Report.self, from: Data(output.withLock { $0 }.utf8)) + #expect(report.valid) + #expect(report.diagnostics.first?.message.contains("Unbound because") == true) + try "[general]\nshortcuts-enabled = 'no'\n".write(to: file, atomically: true, encoding: .utf8) + await #expect(throws: ExitCode.self) { + try await CLIRunner.execute(.configCheck(path: file.path, json: false), socketPath: "not-an-absolute-path") + { _ in } + } + } + + private struct Report: Decodable { + struct Diagnostic: Decodable { let message: String } + let valid: Bool + let diagnostics: [Diagnostic] + } +} diff --git a/Tests/ParcelUITests/SettingsShortcutConflictTests.swift b/Tests/ParcelUITests/SettingsShortcutConflictTests.swift index 56f069f5..8e54b49b 100644 --- a/Tests/ParcelUITests/SettingsShortcutConflictTests.swift +++ b/Tests/ParcelUITests/SettingsShortcutConflictTests.swift @@ -6,6 +6,23 @@ import Testing @testable import ParcelUI @MainActor @Suite struct SettingsShortcutConflictTests { + @Test func leftToMacOSDistinguishesSystemVoiceOverAndApplicationOwners() throws { + let chord = try KeyChord(parsing: "ctrl-alt-t") + let key = SettingsShortcutChecker.hotkey(chord) + let system = SymbolicHotKey(id: 1, isEnabled: true, hotKey: key) + #expect(SettingsShortcutChecker.isLeftToMacOS(chord, environment: .init(symbolicHotKeys: [system]))) + #expect( + !SettingsShortcutChecker.isLeftToMacOS( + chord, environment: .init(symbolicHotKeys: [SymbolicHotKey(id: 1, isEnabled: false, hotKey: key)]))) + #expect(SettingsShortcutChecker.isLeftToMacOS(chord, environment: .init(voiceOverEnabled: true))) + #expect( + !SettingsShortcutChecker.isLeftToMacOS( + chord, + environment: .init(menuShortcuts: [ + MenuShortcut(pid: 1, path: ["File", "Action"], character: "t", hotKey: key) + ]))) + } + @Test func nativeApplicationShortcutsIgnoreOtherAppsButStillDetectParcelDuplicates() throws { let chord = try #require(DefaultKeybindings.bindings()[.quit]) let environment = SettingsShortcutEnvironment(symbolicHotKeys: [ diff --git a/Tests/ParcelUITests/SettingsTests.swift b/Tests/ParcelUITests/SettingsTests.swift index ee9940d1..57ee7b2a 100644 --- a/Tests/ParcelUITests/SettingsTests.swift +++ b/Tests/ParcelUITests/SettingsTests.swift @@ -14,6 +14,88 @@ import Testing @Suite(.serialized, .timeLimit(.minutes(1))) @MainActor struct SettingsTests { + @Test func masterShortcutsAndDisplayFullPolicyRoundTripWithoutChangingBindings() async throws { + try await withSettings(source: "# preferences\n") { model, file in + let bindings = model.configuration.keybindings + model.onRecordedShortcut = { _ in Issue.record("Disabled shortcut capture must be canceled") } + try await model.setValue(.bool(false), for: .shortcutsEnabled) + #expect(model.configuration.keybindings == bindings) + #expect(model.shortcutStatus(for: .toggleAutomaticTiling) == "Left to macOS") + #expect(model.onRecordedShortcut == nil) + try await model.setValue(.string("stack"), for: .whenDisplayFull) + #expect(model.configuration.general.whenDisplayFull == .stack) + try await model.setValue(.bool(true), for: .shortcutsEnabled) + #expect(model.shortcutStatus(for: .toggleAutomaticTiling) == nil) + #expect( + try TOMLDocument(parsing: file.read()).node(forKey: ["general", "when-display-full"])?.value + == .string("stack")) + } + } + + @Test(arguments: [ + "[keybindings]\nfocus-left = 'cmd-f20' # key\nfocus-right = false\n", + "keybindings = { focus-left = 'cmd-f20', focus-right = false } # key\n", + "keybindings.focus-left = 'cmd-f20' # key\nkeybindings.focus-right = false\n", + ]) + func perShortcutRevertRestoresInheritanceAndPreservesOtherOverrides(_ source: String) async throws { + try await withSettings(source: source) { model, file in + #expect(model.canRevertShortcut(for: .focusLeft)) + try await model.revertShortcut(for: .focusLeft) + #expect(model.configuration.keybindings[.focusLeft] == DefaultKeybindings.bindings()[.focusLeft]) + #expect(model.configuration.keybindings[.focusRight] == nil) + #expect(!model.canRevertShortcut(for: .focusLeft)) + #expect(try file.read().contains("# key")) + } + } + + @Test(arguments: [false, true]) + func retiredAutomaticTilingOverrideCanBeRevertedOrReset(resetAll: Bool) async throws { + try await withSettings(source: "[keybindings]\npause-tiling = 'ctrl-alt-n' # retired\n") { model, file in + #expect(model.configuration.keybindings[.toggleAutomaticTiling] == nil) + #expect(model.canRevertShortcut(for: .toggleAutomaticTiling)) + #expect(model.canResetAllShortcuts) + if resetAll { + try await model.resetAllShortcuts() + } else { + try await model.revertShortcut(for: .toggleAutomaticTiling) + } + #expect(model.configuration.keybindings == DefaultKeybindings.bindings()) + #expect(!model.canRevertShortcut(for: .toggleAutomaticTiling)) + #expect(!model.canResetAllShortcuts) + #expect(try file.read().contains("# retired")) + #expect(try TOMLDocument(parsing: file.read()).node(forKey: ["keybindings", "pause-tiling"]) == nil) + } + } + + @Test func resetAllPreservesModesSwitchAndOtherPreferences() async throws { + let source = + "[general]\nprefix = 'fn'\nshortcuts-enabled = false\nwhen-display-full = 'stack'\n[keybindings]\nfocus-left = 'cmd-f20'\nfocus-right = false\n\"enter-mode resize\" = 'cmd-f19'\n[mode.resize]\nfocus-left = 'h'\n[layout]\nratio = 0.6 # layout\n" + try await withSettings(source: source) { model, file in + #expect(model.canResetAllShortcuts) + try await model.resetAllShortcuts() + #expect(model.configuration.keybindings == DefaultKeybindings.bindings()) + #expect(model.configuration.general.prefix == [.ctrl, .alt]) + #expect(!model.configuration.general.shortcutsEnabled) + #expect(model.configuration.general.whenDisplayFull == .stack) + #expect(model.configuration.defaultModeEntries["resize"] == KeyChord(modifiers: .cmd, key: .f19)) + #expect(model.configuration.modes["resize"]?[.command(.focusLeft)] == KeyChord(key: .h)) + #expect(!model.canResetAllShortcuts) + #expect(try file.read().contains("ratio = 0.6 # layout")) + } + } + + @Test func revertingOccupiedDefaultStaysSafelyUnboundUntilOwnerIsReverted() async throws { + try await withSettings(source: "[keybindings]\nlayout-tree = 'ctrl-alt-t'\ntoggle-automatic-tiling = false\n") { + model, _ in + try await model.revertShortcut(for: .toggleAutomaticTiling) + #expect(model.configuration.keybindings[.toggleAutomaticTiling] == nil) + #expect(model.shortcutStatus(for: .toggleAutomaticTiling) == "Unbound because Tree layout uses this key") + try await model.revertShortcut(for: .layoutTree) + #expect(model.configuration.keybindings == DefaultKeybindings.bindings()) + #expect(model.configuration.inheritedShortcutDisplacements.isEmpty) + } + } + @Test func settingsRoundTripPreservesCommentsAndOtherSections() async throws { let source = "# 改善 café\r\n[general]\r\nlaunch-at-login = false # startup\r\n[layout]\r\nratio = 0.5 # balance\r\n[motion]\r\nlevel = 'playful' # keep\r\n" @@ -465,13 +547,14 @@ struct SettingsTests { } } - @Test func inheritedShortcutConflictIsRejectedAndClearDisablesRatherThanResets() async throws { + @Test func explicitShortcutWinsAndClearDisablesRatherThanResets() async throws { let source = "# bindings\n" try await withSettings(source: source) { model, file in let conflict = try #require(model.configuration.keybindings[.focusRight]) - await #expect(throws: SettingsFailure.self) { try await model.setShortcut(conflict, for: .focusLeft) } - #expect(try file.read() == source) - #expect(model.error?.message.contains(ConfigCommand.focusRight.rawValue) == true) + try await model.setShortcut(conflict, for: .focusLeft) + #expect(model.configuration.keybindings[.focusRight] == nil) + #expect(model.shortcutStatus(for: .focusRight) == "Unbound because Focus left uses this key") + #expect(model.error == nil) try await model.setShortcut(nil, for: .focusRight) try await model.setShortcut(conflict, for: .focusLeft) #expect(model.configuration.keybindings[.focusLeft] == conflict) @@ -511,9 +594,9 @@ struct SettingsTests { @Test func prefixEditsRespectAbsoluteOverridesAndValidateConflicts() async throws { try await withSettings(source: "") { model, file in try await model.setShortcut(KeyChord(modifiers: .cmd, key: .right), for: .focusLeft) - let original = try file.read() - await #expect(throws: SettingsFailure.self) { try await model.setValue(.string("cmd"), for: .prefix) } - #expect(try file.read() == original) + try await model.setValue(.string("cmd"), for: .prefix) + #expect(model.configuration.keybindings[.swapRight] == nil) + #expect(model.shortcutStatus(for: .swapRight) == "Unbound because Focus left uses this key") try await model.setValue(.string("fn"), for: .prefix) #expect(model.configuration.keybindings[.focusLeft] == KeyChord(modifiers: .cmd, key: .right)) #expect(model.configuration.keybindings[.focusRight] == KeyChord(modifiers: [.fn, .shift], key: .right)) diff --git a/docs/parcel.schema.json b/docs/parcel.schema.json index f92b7cf0..2f5b574f 100644 --- a/docs/parcel.schema.json +++ b/docs/parcel.schema.json @@ -306,6 +306,19 @@ "description" : "Modifiers used only to generate inherited shortcuts; explicit shortcuts are absolute.", "format" : "parcel-modifiers", "type" : "string" + }, + "shortcuts-enabled" : { + "default" : true, + "type" : "boolean" + }, + "when-display-full" : { + "default" : "swap", + "description" : "When a directional swap arrow reaches a full display, swap windows or stack them. Explicit display moves and new windows are unchanged.", + "enum" : [ + "swap", + "stack" + ], + "type" : "string" } }, "type" : "object" @@ -354,7 +367,7 @@ "layout-grid" : "ctrl-alt-g", "layout-rows" : "ctrl-alt-y", "layout-side" : "ctrl-alt-e", - "layout-tree" : "ctrl-alt-t", + "layout-tree" : "ctrl-alt-shift-t", "make-primary" : "ctrl-alt-return", "mirror-horizontal" : "ctrl-alt-f11", "mirror-vertical" : "ctrl-alt-f12", @@ -389,7 +402,7 @@ "swap-right" : "ctrl-alt-right", "swap-up" : "ctrl-alt-up", "tab-view" : "alt-tab", - "toggle-automatic-tiling" : "ctrl-alt-n", + "toggle-automatic-tiling" : "ctrl-alt-t", "toggle-fullscreen" : "ctrl-alt-m", "undo" : "ctrl-alt-u", "undo-last-rule" : "ctrl-alt-f17", @@ -397,7 +410,7 @@ "window-next" : "ctrl-alt-]", "window-previous" : "ctrl-alt-[" }, - "description" : "Shortcuts inherit generated defaults. Set any command to false to remove it. Enter-mode targets must name declared modes, even when disabled; exit-mode is only valid in named modes.", + "description" : "Shortcuts inherit generated defaults. Explicit chords take priority and leave conflicting inherited defaults unbound with a warning. Set any command to false to remove it. Enter-mode targets must name declared modes, even when disabled; exit-mode is only valid in named modes.", "patternProperties" : { "^enter-mode (?![dD][eE][fF][aA][uU][lL][tT]$)[A-Za-z0-9_-]+$(?![\\s\\S])" : { "oneOf" : [ @@ -764,7 +777,7 @@ ] }, "layout-tree" : { - "default" : "ctrl-alt-t", + "default" : "ctrl-alt-shift-t", "description" : "Select the editable tree layout.", "oneOf" : [ { @@ -1737,7 +1750,7 @@ ] }, "toggle-automatic-tiling" : { - "default" : "ctrl-alt-n", + "default" : "ctrl-alt-t", "description" : "Toggle automatic window arrangement. Explicit shortcuts and menu commands remain available when off.", "oneOf" : [ { -- knotmirror 0.0.1