SDL: events: Raise keyboard keys before sending the focus lost message (49955)

From 49955b37328d5836cb657bf3f2759e74b21f1f0b Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Thu, 15 Jan 2026 14:57:05 -0500
Subject: [PATCH] events: Raise keyboard keys before sending the focus lost
 message

Otherwise, the key raises may end up being ignored.

(cherry picked from commit e62d6a95b9fc193a8fd846c17844d2bd548a8c54)
---
 src/events/SDL_keyboard.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/events/SDL_keyboard.c b/src/events/SDL_keyboard.c
index 05e3f6edd3fb3..b57b0341d5660 100644
--- a/src/events/SDL_keyboard.c
+++ b/src/events/SDL_keyboard.c
@@ -333,6 +333,11 @@ bool SDL_SetKeyboardFocus(SDL_Window *window)
         }
     }
 
+    if (keyboard->focus && !window) {
+        // We won't get anymore keyboard messages, so reset keyboard state
+        SDL_ResetKeyboard();
+    }
+
     // See if the current window has lost focus
     if (keyboard->focus && keyboard->focus != window) {
         SDL_SendWindowEvent(keyboard->focus, SDL_EVENT_WINDOW_FOCUS_LOST, 0, 0);
@@ -346,9 +351,6 @@ bool SDL_SetKeyboardFocus(SDL_Window *window)
     }
 
     if (keyboard->focus && !window) {
-        // We won't get anymore keyboard messages, so reset keyboard state
-        SDL_ResetKeyboard();
-
         // Also leave mouse relative mode
         if (mouse->relative_mode) {
             SDL_SetRelativeMouseMode(false);