SDL: cocoa: Check for duplicate proximity events.

From 91a559828364f1da8d0c73ce02dda22d2995756a Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Mon, 20 Oct 2025 15:55:24 -0400
Subject: [PATCH] cocoa: Check for duplicate proximity events.

Fixes #12137.
---
 src/video/cocoa/SDL_cocoapen.m | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/video/cocoa/SDL_cocoapen.m b/src/video/cocoa/SDL_cocoapen.m
index 6c30bfb157d03..e8a15dac78eab 100644
--- a/src/video/cocoa/SDL_cocoapen.m
+++ b/src/video/cocoa/SDL_cocoapen.m
@@ -84,7 +84,12 @@ static void Cocoa_HandlePenProximityEvent(SDL_CocoaWindowData *_data, NSEvent *e
             return;  // we ignore other things, which hopefully is right.
         }
 
-        Cocoa_PenHandle *handle = (Cocoa_PenHandle *) SDL_calloc(1, sizeof (*handle));
+        Cocoa_PenHandle *handle = Cocoa_FindPenByDeviceID(devid, toolid);
+        if (handle) {
+            return;  // already have this one.
+        }
+
+        handle = (Cocoa_PenHandle *) SDL_calloc(1, sizeof (*handle));
         if (!handle) {
             return;  // oh well.
         }