SDL: Fix #13057 - fixes bug with NSEventTypeMouseMoved having a NULL window causing us to suppress future mouse move events... (b55cf)

From b55cfaf90bfa4a16f6100ec80718911294e03769 Mon Sep 17 00:00:00 2001
From: danginsburg <[EMAIL REDACTED]>
Date: Fri, 16 May 2025 12:03:46 -0400
Subject: [PATCH] Fix #13057 - fixes bug with NSEventTypeMouseMoved having a
 NULL window causing us to suppress future mouse move events because the
 window was considered out of focus.

(cherry picked from commit 968222e74fded22f06e2af78a4616140b1db6683)
---
 src/video/cocoa/SDL_cocoamouse.m | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/video/cocoa/SDL_cocoamouse.m b/src/video/cocoa/SDL_cocoamouse.m
index 530ca0c874eea..f8f582972fba6 100644
--- a/src/video/cocoa/SDL_cocoamouse.m
+++ b/src/video/cocoa/SDL_cocoamouse.m
@@ -450,12 +450,18 @@ void Cocoa_HandleMouseEvent(SDL_VideoDevice *_this, NSEvent *event)
     // All events except NSEventTypeMouseExited can only happen if the window
     // has mouse focus, so we'll always set the focus even if we happen to miss
     // NSEventTypeMouseEntered, which apparently happens if the window is
-    // created under the mouse on macOS 12.7
+    // created under the mouse on macOS 12.7.  But, only set the focus if
+    // the event acutally has a non-NULL window, otherwise what would happen
+    // is that after an NSEventTypeMouseEntered there would sometimes be
+    // NSEventTypeMouseMoved without a window causing us to suppress subsequent
+    // mouse move events.
     NSEventType event_type = [event type];
     if (event_type == NSEventTypeMouseExited) {
         Cocoa_MouseFocus = NULL;
     } else {
-        Cocoa_MouseFocus = [event window];
+        if ([event window] != NULL) {
+            Cocoa_MouseFocus = [event window];
+        }
     }
 
     switch (event_type) {