public enum ConfigCommand: Hashable, RawRepresentable, CaseIterable, Sendable { case focusLeft case focusRight case focusUp case focusDown case swapLeft case swapRight case swapUp case swapDown case moveLeft case moveRight case moveUp case moveDown case layoutGrid case layoutColumns case layoutRows case layoutSide case layoutTree case layoutBSP case layoutAccordion case splitHorizontal case splitVertical case joinLeft case joinRight case joinUp case joinDown case balance case rotate case mirrorHorizontal case mirrorVertical case ratioIncrease case ratioDecrease case ratioHalf case ratioThreeFifths case ratioTwoThirds case floatToggle case snapLeftHalf case snapRightHalf case snapTopHalf case snapBottomHalf case snapTopLeft case snapTopRight case snapBottomLeft case snapBottomRight case snapLeftThird case snapCenterThird case snapRightThird case snapLeftTwoThirds case snapRightTwoThirds case snapCenter case snapAlmostMaximize case snapMaximize case snapRestore case snapNextDisplay case snapPreviousDisplay case snapGrow case snapShrink case makePrimary case windowNext case windowPrevious case tabView case windowControls case resetSizes case retile case stack case stackNext case stackPrevious case unstack case setWindowCap(Int) case close case toggleFullscreen case alwaysFloat case undoLastRule case toggleFocus case toggleNoPeek case toggleCleanSpace case toggleBorders case toggleHoverFocus case undo case displayMoveLeft case displayMoveRight case displayMoveUp case displayMoveDown case openSettings case toggleAutomaticTiling case quit case spaceFocus(Int) case spaceNext case spacePrevious case spaceBackAndForth case windowToSpace(Int, follow: Bool) case windowToSpaceNext(follow: Bool) case windowToSpacePrevious(follow: Bool) public static let allCases: [ConfigCommand] = fixedCases + (0...5).map { .setWindowCap($0) } + [.spaceNext, .spacePrevious, .spaceBackAndForth] + [false, true].flatMap { follow in [.windowToSpaceNext(follow: follow), .windowToSpacePrevious(follow: follow)] + (1...16).map { .windowToSpace($0, follow: follow) } } + (1...16).map { .spaceFocus($0) } public static let bindableCases = allCases public var isBindable: Bool { true } public init?(rawValue: String) { guard let command = Self.allCases.first(where: { $0.rawValue == rawValue }) else { return nil } self = command } public var rawValue: String { switch self { case .spaceFocus(let number): return "space-focus \(number)" case .spaceNext: return "space-next" case .spacePrevious: return "space-previous" case .spaceBackAndForth: return "space-back-and-forth" case .windowToSpace(let number, let follow): return "window-to-space \(number)" + (follow ? " --follow" : "") case .windowToSpaceNext(let follow): return "window-to-space-next" + (follow ? " --follow" : "") case .windowToSpacePrevious(let follow): return "window-to-space-previous" + (follow ? " --follow" : "") case .focusLeft: return "focus-left" case .focusRight: return "focus-right" case .focusUp: return "focus-up" case .focusDown: return "focus-down" case .swapLeft: return "swap-left" case .swapRight: return "swap-right" case .swapUp: return "swap-up" case .swapDown: return "swap-down" case .moveLeft: return "move-left" case .moveRight: return "move-right" case .moveUp: return "move-up" case .moveDown: return "move-down" case .layoutGrid: return "layout-grid" case .layoutColumns: return "layout-columns" case .layoutRows: return "layout-rows" case .layoutSide: return "layout-side" case .layoutTree: return "layout-tree" case .layoutBSP: return "layout-bsp" case .layoutAccordion: return "layout-accordion" case .splitHorizontal: return "split-horizontal" case .splitVertical: return "split-vertical" case .joinLeft: return "join-left" case .joinRight: return "join-right" case .joinUp: return "join-up" case .joinDown: return "join-down" case .balance: return "balance" case .rotate: return "rotate" case .mirrorHorizontal: return "mirror-horizontal" case .mirrorVertical: return "mirror-vertical" case .ratioIncrease: return "ratio-increase" case .ratioDecrease: return "ratio-decrease" case .ratioHalf: return "ratio-half" case .ratioThreeFifths: return "ratio-three-fifths" case .ratioTwoThirds: return "ratio-two-thirds" case .floatToggle: return "float-toggle" case .snapLeftHalf: return "snap-left-half" case .snapRightHalf: return "snap-right-half" case .snapTopHalf: return "snap-top-half" case .snapBottomHalf: return "snap-bottom-half" case .snapTopLeft: return "snap-top-left" case .snapTopRight: return "snap-top-right" case .snapBottomLeft: return "snap-bottom-left" case .snapBottomRight: return "snap-bottom-right" case .snapLeftThird: return "snap-left-third" case .snapCenterThird: return "snap-center-third" case .snapRightThird: return "snap-right-third" case .snapLeftTwoThirds: return "snap-left-two-thirds" case .snapRightTwoThirds: return "snap-right-two-thirds" case .snapCenter: return "snap-center" case .snapAlmostMaximize: return "snap-almost-maximize" case .snapMaximize: return "snap-maximize" case .snapRestore: return "snap-restore" case .snapNextDisplay: return "snap-next-display" case .snapPreviousDisplay: return "snap-previous-display" case .snapGrow: return "snap-grow" case .snapShrink: return "snap-shrink" case .makePrimary: return "make-primary" case .windowNext: return "window-next" case .windowPrevious: return "window-previous" case .tabView: return "tab-view" case .windowControls: return "window-controls" case .resetSizes: return "reset-sizes" case .unstack: return "unstack" case .setWindowCap(let count): return "set-window-cap \(count)" case .close: return "close" case .toggleFullscreen: return "toggle-fullscreen" case .alwaysFloat: return "always-float" case .undoLastRule: return "undo-last-rule" case .toggleFocus: return "focus-toggle" case .toggleNoPeek: return "no-peek-toggle" case .toggleCleanSpace: return "clean-space-toggle" case .toggleBorders: return "borders-toggle" case .toggleHoverFocus: return "hover-focus-toggle" case .undo: return "undo" case .retile: return "retile" case .stack: return "stack" case .stackNext: return "stack-next" case .stackPrevious: return "stack-previous" case .displayMoveLeft: return "display-move-left" case .displayMoveRight: return "display-move-right" case .displayMoveUp: return "display-move-up" case .displayMoveDown: return "display-move-down" case .openSettings: return "open-settings" case .toggleAutomaticTiling: return "toggle-automatic-tiling" case .quit: return "quit" } } public var isSpaceCommand: Bool { switch self { case .spaceFocus, .spaceNext, .spacePrevious, .spaceBackAndForth, .windowToSpace, .windowToSpaceNext, .windowToSpacePrevious: true default: false } } var tomlKey: String { rawValue.contains(" ") ? "\"\(rawValue)\"" : rawValue } private static let fixedCases: [ConfigCommand] = [ .focusLeft, .focusRight, .focusUp, .focusDown, .swapLeft, .swapRight, .swapUp, .swapDown, .moveLeft, .moveRight, .moveUp, .moveDown, .layoutGrid, .layoutColumns, .layoutRows, .layoutSide, .layoutTree, .layoutBSP, .layoutAccordion, .splitHorizontal, .splitVertical, .joinLeft, .joinRight, .joinUp, .joinDown, .balance, .rotate, .mirrorHorizontal, .mirrorVertical, .ratioIncrease, .ratioDecrease, .ratioHalf, .ratioThreeFifths, .ratioTwoThirds, .floatToggle, .snapLeftHalf, .snapRightHalf, .snapTopHalf, .snapBottomHalf, .snapTopLeft, .snapTopRight, .snapBottomLeft, .snapBottomRight, .snapLeftThird, .snapCenterThird, .snapRightThird, .snapLeftTwoThirds, .snapRightTwoThirds, .snapCenter, .snapAlmostMaximize, .snapMaximize, .snapRestore, .snapNextDisplay, .snapPreviousDisplay, .snapGrow, .snapShrink, .makePrimary, .windowNext, .windowPrevious, .tabView, .windowControls, .resetSizes, .retile, .stack, .stackNext, .stackPrevious, .unstack, .close, .toggleFullscreen, .alwaysFloat, .undoLastRule, .toggleFocus, .toggleNoPeek, .toggleCleanSpace, .toggleBorders, .toggleHoverFocus, .undo, .displayMoveLeft, .displayMoveRight, .displayMoveUp, .displayMoveDown, .openSettings, .toggleAutomaticTiling, .quit, ] } public enum DefaultKeybindings { public static let modeExit = KeyChord(key: .escape) public static func bindings(prefix: KeyModifiers = [.ctrl, .alt]) -> [ConfigCommand: KeyChord] { let values = prefix.contains(.shift) ? defaults.merging(shiftPrefixDefaults) { _, alternate in alternate } : defaults var bindings = values.mapValues { KeyChord(modifiers: prefix.union($0.modifiers), key: $0.key) } .merging(applicationMenuDefaults) { _, local in local } bindings[.tabView] = KeyChord(modifiers: .alt, key: .tab) return bindings } public static func isApplicationMenuShortcut(for command: ConfigCommand, chord: KeyChord) -> Bool { applicationMenuDefaults[command] == chord } private static let applicationMenuDefaults: [ConfigCommand: KeyChord] = [ .openSettings: KeyChord(modifiers: .cmd, key: .comma), .quit: KeyChord(modifiers: .cmd, key: .q), ] private static let shiftPrefixDefaults: [ConfigCommand: KeyChord] = [ .layoutTree: KeyChord(key: .f18), .focusLeft: KeyChord(key: .h), .focusRight: KeyChord(key: .l), .focusUp: KeyChord(key: .k), .focusDown: KeyChord(key: .j), .moveRight: KeyChord(key: .f13), .alwaysFloat: KeyChord(key: .f16), .stackPrevious: KeyChord(key: .backslash), .windowControls: KeyChord(key: .f19), ] private static let defaults: [ConfigCommand: KeyChord] = [ .focusLeft: KeyChord(modifiers: .shift, key: .left), .focusRight: KeyChord(modifiers: .shift, key: .right), .focusUp: KeyChord(modifiers: .shift, key: .up), .focusDown: KeyChord(modifiers: .shift, key: .down), .swapLeft: KeyChord(key: .left), .swapRight: KeyChord(key: .right), .swapUp: KeyChord(key: .up), .swapDown: KeyChord(key: .down), .moveLeft: KeyChord(modifiers: .shift, key: .a), .moveRight: KeyChord(modifiers: .shift, key: .d), .moveUp: KeyChord(modifiers: .shift, key: .w), .moveDown: KeyChord(modifiers: .shift, key: .s), .layoutGrid: KeyChord(key: .g), .layoutColumns: KeyChord(key: .c), .layoutRows: KeyChord(key: .y), .layoutSide: KeyChord(key: .e), .layoutTree: KeyChord(modifiers: .shift, key: .t), .layoutBSP: KeyChord(key: .b), .layoutAccordion: KeyChord(key: .o), .splitHorizontal: KeyChord(key: .x), .splitVertical: KeyChord(key: .v), .joinLeft: KeyChord(key: .f5), .joinRight: KeyChord(key: .f6), .joinUp: KeyChord(key: .f7), .joinDown: KeyChord(key: .f8), .balance: KeyChord(key: .f9), .rotate: KeyChord(key: .f10), .mirrorHorizontal: KeyChord(key: .f11), .mirrorVertical: KeyChord(key: .f12), .ratioIncrease: KeyChord(key: .equal), .ratioDecrease: KeyChord(key: .minus), .floatToggle: KeyChord(key: .f), .alwaysFloat: KeyChord(modifiers: .shift, key: .f), .snapLeftHalf: KeyChord(key: .six), .snapRightHalf: KeyChord(key: .seven), .snapTopHalf: KeyChord(key: .eight), .snapBottomHalf: KeyChord(key: .nine), .makePrimary: KeyChord(key: .return), .windowControls: KeyChord(key: .backslash), .windowNext: KeyChord(key: .rightBracket), .windowPrevious: KeyChord(key: .leftBracket), .resetSizes: KeyChord(key: .zero), .retile: KeyChord(key: .r), .stack: KeyChord(key: .space), .stackNext: KeyChord(key: .grave), .stackPrevious: KeyChord(modifiers: .shift, key: .grave), .unstack: KeyChord(key: .semicolon), .undo: KeyChord(key: .u), .undoLastRule: KeyChord(key: .f17), .setWindowCap(1): KeyChord(modifiers: .cmd, key: .one), .setWindowCap(2): KeyChord(modifiers: .cmd, key: .two), .setWindowCap(3): KeyChord(modifiers: .cmd, key: .three), .setWindowCap(4): KeyChord(modifiers: .cmd, key: .four), .setWindowCap(5): KeyChord(modifiers: .cmd, key: .five), .close: KeyChord(key: .delete), .toggleFullscreen: KeyChord(key: .m), .toggleFocus: KeyChord(key: .z), .toggleHoverFocus: KeyChord(key: .i), .toggleNoPeek: KeyChord(key: .d), .toggleCleanSpace: KeyChord(key: .p), .displayMoveLeft: KeyChord(modifiers: .cmd, key: .f1), .displayMoveRight: KeyChord(modifiers: .cmd, key: .f2), .displayMoveUp: KeyChord(modifiers: .cmd, key: .f3), .displayMoveDown: KeyChord(modifiers: .cmd, key: .f4), .toggleAutomaticTiling: KeyChord(key: .t), ] }