From 3cd5a407b8a6e884d5f1dfba42651639a8aab20e Mon Sep 17 00:00:00 2001
From: Qiu Qiang <[EMAIL REDACTED]>
Date: Sun, 11 Jan 2026 21:31:14 -0500
Subject: [PATCH] Fix duplicate event dispatch in Cocoa event pump
Prevent mouse and keyboard events from being processed twice by
skipping [super sendEvent:] for events SDL has already handled via
Cocoa_DispatchEvent. Other event types still go through AppKit's
normal handling.
(cherry picked from commit dd52dd8995dc1f0fb67e7ec8dcaa6c82416a7a4c)
---
src/video/cocoa/SDL_cocoaevents.m | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/src/video/cocoa/SDL_cocoaevents.m b/src/video/cocoa/SDL_cocoaevents.m
index 681c1a53a804f..f9e12cd11080d 100644
--- a/src/video/cocoa/SDL_cocoaevents.m
+++ b/src/video/cocoa/SDL_cocoaevents.m
@@ -97,6 +97,14 @@ - (void)sendEvent:(NSEvent *)theEvent
{
if (s_bShouldHandleEventsInSDLApplication) {
Cocoa_DispatchEvent(theEvent);
+
+ // Avoid double-dispatching mouse and keyboard events. They are already handled in Cocoa_DispatchEvent.
+ // Other event types should still go through AppKit's normal handling.
+ NSEventType type = [theEvent type];
+ if ((type >= NSEventTypeLeftMouseDown && type <= NSEventTypeMouseExited) ||
+ (type >= NSEventTypeKeyDown && type <= NSEventTypeFlagsChanged)) {
+ return;
+ }
}
[super sendEvent:theEvent];