Skip to content

Commit

Permalink
✨ Add keybinds to Defaults, add new function to change them
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKai77 committed Jun 25, 2023
1 parent a7f6bfd commit e2b41ed
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 15 deletions.
67 changes: 67 additions & 0 deletions Loop/Extensions/Defaults+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,71 @@ extension Defaults.Keys {
static let previewCornerRadius = Key<CGFloat>("previewCornerRadius", default: 15)
static let previewPadding = Key<CGFloat>("previewPadding", default: 10)
static let previewBorderThickness = Key<CGFloat>("previewBorderThickness", default: 0)

static let maximizeKeybind = Key<[Set<UInt16>]>(
"maximizeKeybind",
default: [[KeyCode.space], [KeyCode.return]]
)

// Halves
static let topHalfKeybind = Key<[Set<UInt16>]>(
"topHalfKeybind",
default: [[KeyCode.w], [KeyCode.upArrow]]
)
static let bottomHalfKeybind = Key<[Set<UInt16>]>(
"bottomHalfKeybind",
default: [[KeyCode.s], [KeyCode.downArrow]]
)
static let rightHalfKeybind = Key<[Set<UInt16>]>(
"rightHalfKeybind",
default: [[KeyCode.d], [KeyCode.rightArrow]]
)
static let leftHalfKeybind = Key<[Set<UInt16>]>(
"leftHalfKeybind",
default: [[KeyCode.a], [KeyCode.leftArrow]]
)

// Quarters
static let topLeftQuarter = Key<[Set<UInt16>]>(
"topLeftQuarter",
default: [[KeyCode.w, KeyCode.a],
[KeyCode.upArrow, KeyCode.leftArrow]]
)
static let topRightQuarter = Key<[Set<UInt16>]>(
"topRightQuarter",
default: [[KeyCode.w, KeyCode.d],
[KeyCode.upArrow, KeyCode.rightArrow]]
)
static let bottomRightQuarter = Key<[Set<UInt16>]>(
"bottomRightQuarter",
default: [[KeyCode.s, KeyCode.d],
[KeyCode.downArrow, KeyCode.rightArrow]]
)
static let bottomLeftQuarter = Key<[Set<UInt16>]>(
"bottomLeftQuarter",
default: [[KeyCode.s, KeyCode.a],
[KeyCode.downArrow, KeyCode.leftArrow]]
)

// Thirds
static let leftThird = Key<[Set<UInt16>]>(
"leftThird",
default: [[KeyCode.j]]
)
static let leftTwoThirds = Key<[Set<UInt16>]>(
"leftTwoThirds",
default: [[KeyCode.u]]
)
static let horizontalCenterThird = Key<[Set<UInt16>]>(
"horizontalCenterThird",
default: [[KeyCode.k]]
)
static let rightTwoThirds = Key<[Set<UInt16>]>(
"rightTwoThirds",
default: [[KeyCode.o]]
)
static let rightThird = Key<[Set<UInt16>]>(
"rightThird",
default: [[KeyCode.l]]
)
}
54 changes: 39 additions & 15 deletions Loop/Helpers/WindowDirection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import SwiftUI
import Defaults

// Enum that stores all possible resizing options
enum WindowDirection: CaseIterable {
Expand Down Expand Up @@ -54,28 +55,51 @@ enum WindowDirection: CaseIterable {
}
}

var keybindings: [Set<UInt16>] {
var keybind: [Set<UInt16>] {
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<UInt16>]) {
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
}
}
}

0 comments on commit e2b41ed

Please sign in to comment.