@@ -53,7 +53,7 @@ private func touchEventHandler(_ cgEvent: CGEvent) -> Bool {
5353 if touches. count == 0 { return false } // sometimes the os sends events with no touches
5454 let activeTouches = touches. filter { !$0. isResting && ( $0. phase == . began || $0. phase == . moved || $0. phase == . stationary) }
5555 let requiredFingers = Preferences . nextWindowGesture. isThreeFinger ( ) ? 3 : 4
56- if touches. count != requiredFingers {
56+ if ( !App . app . appIsBeingUsed && touches. count != requiredFingers) || ( App . app . appIsBeingUsed && touches . count < 2 ) {
5757 TriggerSwipeDetector . reset ( )
5858 NavigationSwipeDetector . reset ( )
5959 return GestureDetector . checkForFingersUp ( activeTouches, requiredFingers)
@@ -111,6 +111,14 @@ class GestureDetector {
111111 }
112112 return totalDelta / activeTouches. count
113113 }
114+
115+ static func computeDistance( _ activeTouches: Set < NSTouch > , _ startPositions: [ String : NSPoint ] ) -> Array < NSPoint > {
116+ var deltas : Array < NSPoint > = [ ]
117+ for touch in activeTouches {
118+ deltas. append ( touch. normalizedPosition - startPositions[ " \( touch. identity) " ] !)
119+ }
120+ return deltas
121+ }
114122
115123 static func blockOngoingScrolling( ) {
116124 if #available( macOS 10 . 13 , * ) {
@@ -135,15 +143,17 @@ class TriggerSwipeDetector {
135143
136144 static func check( _ activeTouches: Set < NSTouch > ) -> Bool ? {
137145 if !App. app. appIsBeingUsed && swipeStillPossible {
138- let averageDistance = GestureDetector . computeAverageDistance ( activeTouches, startPositions)
139- let ( absX , absY ) = ( abs ( averageDistance . x ) , abs ( averageDistance . y ) )
140- let horizontal = Preferences . nextWindowGesture . isHorizontal ( )
141- if ( updateSwipeStillPossible ( horizontal ? absY : absX ) && ( horizontal ? absX : absY ) >= MIN_SWIPE_DISTANCE ) {
142- reset ( )
143- DispatchQueue . main . async { App . app . showUiOrCycleSelection ( Preferences . gestureIndex , false ) }
144- return true
146+ let distances = GestureDetector . computeDistance ( activeTouches, startPositions)
147+ for distance in distances {
148+ let ( absX , absY ) = ( abs ( distance . x ) , abs ( distance . y ) )
149+ let horizontal = Preferences . nextWindowGesture . isHorizontal ( )
150+ if ( ! ( updateSwipeStillPossible ( horizontal ? absY : absX ) && ( horizontal ? absX : absY ) >= MIN_SWIPE_DISTANCE ) ) {
151+ return false
152+ }
145153 }
146- return false
154+ reset ( )
155+ DispatchQueue . main. async { App . app. showUiOrCycleSelection ( Preferences . gestureIndex, false ) }
156+ return true
147157 }
148158 return nil
149159 }
@@ -160,9 +170,7 @@ class TriggerSwipeDetector {
160170}
161171
162172class NavigationSwipeDetector {
163- // TODO: replace this approach with a "virtual cursor" approach
164- // Instead of detecting swipes, we would track coordinate, and check which thumbnail is under that cursor
165- static let MIN_SWIPE_DISTANCE : Double = 0.045 // % of trackpad surface traveled
173+ static let MIN_SWIPE_DISTANCE : Double = 0.03 // % of trackpad surface traveled
166174
167175 static var startPositions : [ String : NSPoint ] = [ : ]
168176
0 commit comments