From e2b41ed2998423b8cbcb5e7471ca44acd04e00ba Mon Sep 17 00:00:00 2001 From: Kai Azim <68963405+MrKai77@users.noreply.github.com> Date: Sat, 24 Jun 2023 21:50:09 -0600 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20keybinds=20to=20Defaults,=20a?= =?UTF-8?q?dd=20new=20function=20to=20change=20them?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Loop/Extensions/Defaults+Extensions.swift | 67 +++++++++++++++++++++++ Loop/Helpers/WindowDirection.swift | 54 +++++++++++++----- 2 files changed, 106 insertions(+), 15 deletions(-) diff --git a/Loop/Extensions/Defaults+Extensions.swift b/Loop/Extensions/Defaults+Extensions.swift index 8c5c9643..6027eb34 100644 --- a/Loop/Extensions/Defaults+Extensions.swift +++ b/Loop/Extensions/Defaults+Extensions.swift @@ -28,4 +28,71 @@ extension Defaults.Keys { static let previewCornerRadius = Key("previewCornerRadius", default: 15) static let previewPadding = Key("previewPadding", default: 10) static let previewBorderThickness = Key("previewBorderThickness", default: 0) + + static let maximizeKeybind = Key<[Set]>( + "maximizeKeybind", + default: [[KeyCode.space], [KeyCode.return]] + ) + + // Halves + static let topHalfKeybind = Key<[Set]>( + "topHalfKeybind", + default: [[KeyCode.w], [KeyCode.upArrow]] + ) + static let bottomHalfKeybind = Key<[Set]>( + "bottomHalfKeybind", + default: [[KeyCode.s], [KeyCode.downArrow]] + ) + static let rightHalfKeybind = Key<[Set]>( + "rightHalfKeybind", + default: [[KeyCode.d], [KeyCode.rightArrow]] + ) + static let leftHalfKeybind = Key<[Set]>( + "leftHalfKeybind", + default: [[KeyCode.a], [KeyCode.leftArrow]] + ) + + // Quarters + static let topLeftQuarter = Key<[Set]>( + "topLeftQuarter", + default: [[KeyCode.w, KeyCode.a], + [KeyCode.upArrow, KeyCode.leftArrow]] + ) + static let topRightQuarter = Key<[Set]>( + "topRightQuarter", + default: [[KeyCode.w, KeyCode.d], + [KeyCode.upArrow, KeyCode.rightArrow]] + ) + static let bottomRightQuarter = Key<[Set]>( + "bottomRightQuarter", + default: [[KeyCode.s, KeyCode.d], + [KeyCode.downArrow, KeyCode.rightArrow]] + ) + static let bottomLeftQuarter = Key<[Set]>( + "bottomLeftQuarter", + default: [[KeyCode.s, KeyCode.a], + [KeyCode.downArrow, KeyCode.leftArrow]] + ) + + // Thirds + static let leftThird = Key<[Set]>( + "leftThird", + default: [[KeyCode.j]] + ) + static let leftTwoThirds = Key<[Set]>( + "leftTwoThirds", + default: [[KeyCode.u]] + ) + static let horizontalCenterThird = Key<[Set]>( + "horizontalCenterThird", + default: [[KeyCode.k]] + ) + static let rightTwoThirds = Key<[Set]>( + "rightTwoThirds", + default: [[KeyCode.o]] + ) + static let rightThird = Key<[Set]>( + "rightThird", + default: [[KeyCode.l]] + ) } diff --git a/Loop/Helpers/WindowDirection.swift b/Loop/Helpers/WindowDirection.swift index 4f6ce186..0e032d5a 100644 --- a/Loop/Helpers/WindowDirection.swift +++ b/Loop/Helpers/WindowDirection.swift @@ -6,6 +6,7 @@ // import SwiftUI +import Defaults // Enum that stores all possible resizing options enum WindowDirection: CaseIterable { @@ -54,28 +55,51 @@ enum WindowDirection: CaseIterable { } } - var keybindings: [Set] { + var keybind: [Set] { switch self { case .noAction: [[]] - case .maximize: [[KeyCode.space]] + case .maximize: Defaults[.maximizeKeybind] - case .topHalf: [[KeyCode.w], [KeyCode.upArrow]] - case .rightHalf: [[KeyCode.d], [KeyCode.rightArrow]] - case .bottomHalf: [[KeyCode.s], [KeyCode.downArrow]] - case .leftHalf: [[KeyCode.a], [KeyCode.leftArrow]] + case .topHalf: Defaults[.topHalfKeybind] + case .rightHalf: Defaults[.rightHalfKeybind] + case .bottomHalf: Defaults[.bottomHalfKeybind] + case .leftHalf: Defaults[.leftHalfKeybind] - case .topRightQuarter: [[KeyCode.w, KeyCode.d], [KeyCode.upArrow, KeyCode.rightArrow]] - case .bottomRightQuarter: [[KeyCode.s, KeyCode.d], [KeyCode.downArrow, KeyCode.rightArrow]] - case .bottomLeftQuarter: [[KeyCode.s, KeyCode.a], [KeyCode.downArrow, KeyCode.leftArrow]] - case .topLeftQuarter: [[KeyCode.w, KeyCode.a], [KeyCode.upArrow, KeyCode.leftArrow]] + case .topRightQuarter: Defaults[.topRightQuarter] + case .bottomRightQuarter: Defaults[.bottomRightQuarter] + case .bottomLeftQuarter: Defaults[.bottomLeftQuarter] + case .topLeftQuarter: Defaults[.topLeftQuarter] - case .leftThird: [[KeyCode.j]] - case .leftTwoThirds: [[KeyCode.u]] - case .horizontalCenterThird: [[KeyCode.k]] - case .rightTwoThirds: [[KeyCode.o]] - case .rightThird: [[KeyCode.l]] + case .leftThird: Defaults[.leftThird] + case .leftTwoThirds: Defaults[.leftTwoThirds] + case .horizontalCenterThird: Defaults[.horizontalCenterThird] + case .rightTwoThirds: Defaults[.rightTwoThirds] + case .rightThird: Defaults[.rightThird] default: [[]] } } + + func setKeybind(_ keybind: [Set]) { + switch self { + case .maximize: Defaults[.maximizeKeybind] = keybind + + case .topHalf: Defaults[.topHalfKeybind] = keybind + case .rightHalf: Defaults[.rightHalfKeybind] = keybind + case .bottomHalf: Defaults[.bottomHalfKeybind] = keybind + case .leftHalf: Defaults[.leftHalfKeybind] = keybind + + case .topRightQuarter: Defaults[.topRightQuarter] = keybind + case .bottomRightQuarter: Defaults[.bottomRightQuarter] = keybind + case .bottomLeftQuarter: Defaults[.bottomLeftQuarter] = keybind + case .topLeftQuarter: Defaults[.topLeftQuarter] = keybind + + case .leftThird: Defaults[.leftThird] = keybind + case .leftTwoThirds: Defaults[.leftTwoThirds] = keybind + case .horizontalCenterThird: Defaults[.horizontalCenterThird] = keybind + case .rightTwoThirds: Defaults[.rightTwoThirds] = keybind + case .rightThird: Defaults[.rightThird] = keybind + default: return + } + } }