@@ -300,6 +300,26 @@ extension AppKitWindow {
300300final class UGNSWindow : AppKit . NSWindow {
301301 weak var window : Window !
302302 private var touchesIDs : [ ObjectIdentifier : UUID ] = [ : ]
303+ private var surfaceIDs : [ ObjectIdentifier : UUID ] = [ : ]
304+
305+ func id( forTouch touch: NSTouch ) -> UUID {
306+ let objectID = ObjectIdentifier ( touch. identity)
307+ if let id = touchesIDs [ objectID] {
308+ return id
309+ }
310+ let id = UUID ( )
311+ touchesIDs [ objectID] = id
312+ return id
313+ }
314+ func id( forSurface device: AnyObject ) -> UUID {
315+ let objectID = ObjectIdentifier ( device)
316+ if let id = surfaceIDs [ objectID] {
317+ return id
318+ }
319+ let id = UUID ( )
320+ surfaceIDs [ objectID] = id
321+ return id
322+ }
303323
304324 init ( window: Window ,
305325 contentRect: NSRect ,
@@ -544,8 +564,7 @@ extension UGNSWindow {
544564 let touches = event. touches ( matching: . began, in: nil )
545565
546566 for touch in touches {
547- let id = UUID ( )
548- touchesIDs [ ObjectIdentifier ( touch. identity) ] = id
567+ let id = self . id ( forTouch: touch)
549568 let type = type ( for: touch)
550569 if let position = locationOfTouch ( touch, from: event) {
551570 switch touch. type {
@@ -564,7 +583,7 @@ extension UGNSWindow {
564583 Game . shared. hid. surfaceTouchChange (
565584 id: id,
566585 event: . began,
567- surfaceID: ObjectIdentifier ( device) ,
586+ surfaceID: self . id ( forSurface : device) ,
568587 normalizedPosition: position,
569588 pressure: 0 ,
570589 window: window
@@ -581,7 +600,7 @@ extension UGNSWindow {
581600 let touches = event. touches ( matching: . moved, in: nil )
582601
583602 for touch in touches {
584- guard let id = touchesIDs [ ObjectIdentifier ( touch. identity ) ] else { continue }
603+ let id = self . id ( forTouch : touch)
585604 let type = type ( for: touch)
586605 if let position = locationOfTouch ( touch, from: event) {
587606 switch touch. type {
@@ -600,7 +619,7 @@ extension UGNSWindow {
600619 Game . shared. hid. surfaceTouchChange (
601620 id: id,
602621 event: . moved,
603- surfaceID: ObjectIdentifier ( device) ,
622+ surfaceID: self . id ( forSurface : device) ,
604623 normalizedPosition: position,
605624 pressure: 0 ,
606625 window: window
@@ -617,7 +636,7 @@ extension UGNSWindow {
617636 let touches = event. touches ( matching: . ended, in: nil )
618637
619638 for touch in touches {
620- guard let id = touchesIDs [ ObjectIdentifier ( touch. identity ) ] else { continue }
639+ let id = self . id ( forTouch : touch)
621640 let type = type ( for: touch)
622641 if let position = locationOfTouch ( touch, from: event) {
623642 switch touch. type {
@@ -636,7 +655,7 @@ extension UGNSWindow {
636655 Game . shared. hid. surfaceTouchChange (
637656 id: id,
638657 event: . ended,
639- surfaceID: ObjectIdentifier ( device) ,
658+ surfaceID: self . id ( forSurface : device) ,
640659 normalizedPosition: position,
641660 pressure: 0 ,
642661 window: window
@@ -654,7 +673,7 @@ extension UGNSWindow {
654673 let touches = event. touches ( matching: . cancelled, in: nil )
655674
656675 for touch in touches {
657- guard let id = touchesIDs [ ObjectIdentifier ( touch. identity ) ] else { continue }
676+ let id = self . id ( forTouch : touch)
658677 let type = type ( for: touch)
659678 if let position = locationOfTouch ( touch, from: event) {
660679 switch touch. type {
@@ -673,7 +692,7 @@ extension UGNSWindow {
673692 Game . shared. hid. surfaceTouchChange (
674693 id: id,
675694 event: . canceled,
676- surfaceID: ObjectIdentifier ( device) ,
695+ surfaceID: self . id ( forSurface : device) ,
677696 normalizedPosition: position,
678697 pressure: 0 ,
679698 window: window
0 commit comments