Skip to content

Commit

Permalink
Make "Shake To Snap" sensivitiy adjustable
Browse files Browse the repository at this point in the history
  • Loading branch information
rohanrhu committed Oct 12, 2024
1 parent 1bec11e commit b532606
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 1 addition & 2 deletions MacsyZones/Macsy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ func onObserverNotification(observer: AXObserver, element: AXUIElement, notifica
}
}

let shakeAccelerationThreshold: CGFloat = 50000.0
let shakeCoolDown: TimeInterval = 0.75

var previousPosition: CGPoint?
Expand Down Expand Up @@ -243,7 +242,7 @@ func onWindowMoved(observer: AXObserver, element: AXUIElement, notification: CFS
let acceleration = CGPoint(x: deltaVelocity.x / CGFloat(deltaTime), y: deltaVelocity.y / CGFloat(deltaTime))
let accelerationMagnitude = sqrt(pow(acceleration.x, 2) + pow(acceleration.y, 2))

if (oppositeDirectionOnX || oppositeDirectionOnY) && accelerationMagnitude > shakeAccelerationThreshold && currentTime - lastShakeTime > shakeCoolDown {
if (oppositeDirectionOnX || oppositeDirectionOnY) && accelerationMagnitude > appSettings.shakeAccelerationThreshold && currentTime - lastShakeTime > shakeCoolDown {
lastShakeTime = currentTime

isFitting = !isFitting
Expand Down
12 changes: 12 additions & 0 deletions MacsyZones/TrayPopupView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class AppSettings: ObservableObject {
@Published var selectPerDesktopLayout: Bool = true
@Published var prioritizeCenterToSnap: Bool = true
@Published var shakeToSnap: Bool = true
@Published var shakeAccelerationThreshold: CGFloat = 50000.0
}

let appSettings = AppSettings()
Expand Down Expand Up @@ -220,6 +221,17 @@ struct Main: View {
Spacer()
}.padding(.bottom, 5)

if settings.shakeToSnap {
VStack {
Text("Shake Sensitivity")
Slider(value: Binding(
get: { Double(settings.shakeAccelerationThreshold) },
set: { settings.shakeAccelerationThreshold = CGFloat($0) }
), in: 10000...100000, step: 1000)
}
.padding(.bottom, 10)
}

if #available(macOS 13.0, *) {
HStack {
Toggle("Start at login", isOn: $startAtLogin)
Expand Down

0 comments on commit b532606

Please sign in to comment.