Просмотр исходного кода

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)
Qiu Qiang 1 месяц назад
Родитель
Сommit
3cd5a407b8
1 измененных файлов с 8 добавлено и 0 удалено
  1. 8 0
      src/video/cocoa/SDL_cocoaevents.m

+ 8 - 0
src/video/cocoa/SDL_cocoaevents.m

@@ -97,6 +97,14 @@ static void Cocoa_DispatchEvent(NSEvent *theEvent)
 {
 {
     if (s_bShouldHandleEventsInSDLApplication) {
     if (s_bShouldHandleEventsInSDLApplication) {
         Cocoa_DispatchEvent(theEvent);
         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];
     [super sendEvent:theEvent];