Skip to content

Commit ebafed6

Browse files
committed
feat: swipes can now be horizontal or vertical (closes #4020)
swipe recognition has also been improved in many ways
1 parent db5500f commit ebafed6

File tree

4 files changed

+200
-140
lines changed

4 files changed

+200
-140
lines changed

src/api-wrappers/HelperExtensions.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,17 @@ class ModifierFlags {
247247
return NSEvent.modifierFlags
248248
}
249249
}
250+
251+
extension NSPoint {
252+
static func + (lhs: NSPoint, rhs: NSPoint) -> NSPoint {
253+
return NSPoint(x: lhs.x + rhs.x, y: lhs.y + rhs.y)
254+
}
255+
256+
static func - (lhs: NSPoint, rhs: NSPoint) -> NSPoint {
257+
return NSPoint(x: lhs.x - rhs.x, y: lhs.y - rhs.y)
258+
}
259+
260+
static func / (lhs: NSPoint, rhs: Int) -> NSPoint {
261+
return NSPoint(x: lhs.x / Double(rhs), y: lhs.y / Double(rhs))
262+
}
263+
}

src/logic/Preferences.swift

Lines changed: 57 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -203,31 +203,34 @@ class Preferences {
203203

204204
private static func updateToNewPreferences(_ versionInPlist: String) {
205205
// x.compare(y) is .orderedDescending if x > y
206-
if versionInPlist.compare("7.8.0", options: .numeric) != .orderedDescending {
207-
migrateMenubarIconWithNewShownToggle()
208-
if versionInPlist.compare("7.0.0", options: .numeric) != .orderedDescending {
209-
migratePreferencesIndexes()
210-
if versionInPlist.compare("6.43.0", options: .numeric) != .orderedDescending {
211-
migrateBlacklists()
212-
if versionInPlist.compare("6.28.1", options: .numeric) != .orderedDescending {
213-
migrateMinMaxWindowsWidthInRow()
214-
if versionInPlist.compare("6.27.1", options: .numeric) != .orderedDescending {
215-
// "Start at login" new implem doesn't use Login Items; we remove the entry from previous versions
216-
(Preferences.self as AvoidDeprecationWarnings.Type).migrateLoginItem()
217-
if versionInPlist.compare("6.23.0", options: .numeric) != .orderedDescending {
218-
// "Show windows from:" got the "Active Space" option removed
219-
migrateShowWindowsFrom()
220-
if versionInPlist.compare("6.18.1", options: .numeric) != .orderedDescending {
221-
// nextWindowShortcut used to be able to have modifiers already present in holdShortcut; we remove these
222-
migrateNextWindowShortcuts()
223-
// dropdowns preferences used to store English text; now they store indexes
224-
migrateDropdownsFromTextToIndexes()
225-
// the "Hide menubar icon" checkbox was replaced with a dropdown of: icon1, icon2, hidden
226-
migrateMenubarIconFromCheckboxToDropdown()
227-
// "Show minimized/hidden/fullscreen windows" checkboxes were replaced with dropdowns
228-
migrateShowWindowsCheckboxToDropdown()
229-
// "Max size on screen" was split into max width and max height
230-
migrateMaxSizeOnScreenToWidthAndHeight()
206+
if versionInPlist.compare("7.13.1", options: .numeric) != .orderedDescending {
207+
migrateGestures()
208+
if versionInPlist.compare("7.8.0", options: .numeric) != .orderedDescending {
209+
migrateMenubarIconWithNewShownToggle()
210+
if versionInPlist.compare("7.0.0", options: .numeric) != .orderedDescending {
211+
migratePreferencesIndexes()
212+
if versionInPlist.compare("6.43.0", options: .numeric) != .orderedDescending {
213+
migrateBlacklists()
214+
if versionInPlist.compare("6.28.1", options: .numeric) != .orderedDescending {
215+
migrateMinMaxWindowsWidthInRow()
216+
if versionInPlist.compare("6.27.1", options: .numeric) != .orderedDescending {
217+
// "Start at login" new implem doesn't use Login Items; we remove the entry from previous versions
218+
(Preferences.self as AvoidDeprecationWarnings.Type).migrateLoginItem()
219+
if versionInPlist.compare("6.23.0", options: .numeric) != .orderedDescending {
220+
// "Show windows from:" got the "Active Space" option removed
221+
migrateShowWindowsFrom()
222+
if versionInPlist.compare("6.18.1", options: .numeric) != .orderedDescending {
223+
// nextWindowShortcut used to be able to have modifiers already present in holdShortcut; we remove these
224+
migrateNextWindowShortcuts()
225+
// dropdowns preferences used to store English text; now they store indexes
226+
migrateDropdownsFromTextToIndexes()
227+
// the "Hide menubar icon" checkbox was replaced with a dropdown of: icon1, icon2, hidden
228+
migrateMenubarIconFromCheckboxToDropdown()
229+
// "Show minimized/hidden/fullscreen windows" checkboxes were replaced with dropdowns
230+
migrateShowWindowsCheckboxToDropdown()
231+
// "Max size on screen" was split into max width and max height
232+
migrateMaxSizeOnScreenToWidthAndHeight()
233+
}
231234
}
232235
}
233236
}
@@ -237,6 +240,19 @@ class Preferences {
237240
}
238241
}
239242

243+
// we split gestures from disabled, 3-finger, 4-finger to: disabled, 3-finger-horizontal, 3-finger-vertical, 4-finger-horizontal, 4-finger-vertical
244+
// no need to map 0 -> 0 (disabled -> disabled)
245+
// no need to map 1 -> 1 (3-finger -> 3-finger-horizontal)
246+
// we need to map 2 -> 3 (4-finger -> 4-finger-horizontal)
247+
private static func migrateGestures() {
248+
if let old = UserDefaults.standard.string(forKey: "nextWindowGesture") {
249+
if old == "2" { // 2 (4-finger) -> 3 (4-finger-horizontal)
250+
UserDefaults.standard.set("3", forKey: "nextWindowGesture")
251+
}
252+
}
253+
}
254+
255+
240256
// we added the new menubarIconShown toggle. It replaces menubarIcon having value "3" which would hide the icon
241257
// there are now 2 preferences : menubarIconShown is a boolean, and menubarIcon has values 0, 1, 2
242258
private static func migrateMenubarIconWithNewShownToggle() {
@@ -506,16 +522,28 @@ enum MenubarIconPreference: CaseIterable, MacroPreference {
506522

507523
enum GesturePreference: CaseIterable, MacroPreference {
508524
case disabled
509-
case threeFingerSwipe
510-
case fourFingerSwipe
525+
case threeFingerHorizontalSwipe
526+
case threeFingerVerticalSwipe
527+
case fourFingerHorizontalSwipe
528+
case fourFingerVerticalSwipe
511529

512530
var localizedString: LocalizedString {
513531
switch self {
514532
case .disabled: return NSLocalizedString("Disabled", comment: "")
515-
case .threeFingerSwipe: return NSLocalizedString("Swipe with Three Fingers", comment: "")
516-
case .fourFingerSwipe: return NSLocalizedString("Swipe with Four Fingers", comment: "")
533+
case .threeFingerHorizontalSwipe: return NSLocalizedString("Horizontal Swipe with Three Fingers", comment: "")
534+
case .threeFingerVerticalSwipe: return NSLocalizedString("Vertical Swipe with Three Fingers", comment: "")
535+
case .fourFingerHorizontalSwipe: return NSLocalizedString("Horizontal Swipe with Four Fingers", comment: "")
536+
case .fourFingerVerticalSwipe: return NSLocalizedString("Vertical Swipe with Four Fingers", comment: "")
517537
}
518538
}
539+
540+
func isHorizontal() -> Bool {
541+
return self == .threeFingerHorizontalSwipe || self == .fourFingerHorizontalSwipe
542+
}
543+
544+
func isThreeFinger() -> Bool {
545+
return self == .threeFingerHorizontalSwipe || self == .threeFingerVerticalSwipe
546+
}
519547
}
520548

521549
enum LanguagePreference: CaseIterable, MacroPreference {

src/logic/Windows.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class Windows {
183183
let nextIndex = windowIndexAfterCycling(step)
184184
// don't wrap-around at the end, if key-repeat
185185
if (((step > 0 && nextIndex < focusedWindowIndex) || (step < 0 && nextIndex > focusedWindowIndex)) &&
186-
(ATShortcut.lastEventIsARepeat || KeyRepeatTimer.timer?.isValid ?? false))
186+
(!allowWrap || ATShortcut.lastEventIsARepeat || KeyRepeatTimer.timer?.isValid ?? false))
187187
// don't cycle to another row, if !allowWrap
188188
|| (!allowWrap && list[nextIndex].rowIndex != list[focusedWindowIndex].rowIndex) {
189189
return

0 commit comments

Comments
 (0)