@@ -15,9 +15,15 @@ final class MultitouchTargetResolver {
1515 /// Window most recently targeted by a repeatable gesture.
1616 /// Lets shrinking/growing continue after the cursor falls off the resized frame.
1717 private var lastRepeatableWindow : Window ?
18+ private var gestureWindowLookups : [ GestureBinding . ActivationZone : WindowLookup ] = [ : ]
1819
1920 func reset( ) {
2021 lastRepeatableWindow = nil
22+ resetGestureState ( )
23+ }
24+
25+ func resetGestureState( ) {
26+ gestureWindowLookups. removeAll ( )
2127 }
2228
2329 func targetWindow( for gesture: GestureBinding , allowsRapidRepeat: Bool ) -> Window ? {
@@ -35,13 +41,19 @@ final class MultitouchTargetResolver {
3541
3642 private func findTargetWindow( for gesture: GestureBinding ) -> Window ? {
3743 let cursorPosition = NSEvent . mouseLocation. flipY ( screen: NSScreen . screens [ 0 ] )
44+ let activationZone : GestureBinding . ActivationZone = gesture. fingerCount <= 2 ? . titlebar : gesture. activationZone
45+
46+ if let windowLookup = gestureWindowLookups [ activationZone] {
47+ return windowLookup. window
48+ }
3849
3950 guard let window = WindowUtility . windowAtPosition ( cursorPosition) else {
51+ gestureWindowLookups [ activationZone] = WindowLookup ( window: nil )
4052 return nil
4153 }
4254
4355 // 2-finger gestures are always titlebar-only to avoid system gesture conflicts.
44- switch gesture . fingerCount <= 2 ? . titlebar : gesture . activationZone {
56+ switch activationZone {
4557 case . titlebar:
4658 let minimumTitlebarHeight = Defaults [ . gestureTitlebarHeight]
4759 let titlebarHeight : CGFloat = if #available( macOS 26 , * ) {
@@ -60,10 +72,17 @@ final class MultitouchTargetResolver {
6072 let titlebarMinY = window. frame. minY
6173 let titlebarMaxY = window. frame. minY + titlebarHeight
6274 let isInTitlebar = cursorPosition. y >= titlebarMinY && cursorPosition. y <= titlebarMaxY
63- return isInTitlebar ? window : nil
75+ let targetWindow = isInTitlebar ? window : nil
76+ gestureWindowLookups [ activationZone] = WindowLookup ( window: targetWindow)
77+ return targetWindow
6478
6579 case . anywhere:
80+ gestureWindowLookups [ activationZone] = WindowLookup ( window: window)
6681 return window
6782 }
6883 }
6984}
85+
86+ private struct WindowLookup {
87+ let window : Window ?
88+ }
0 commit comments