@@ -337,6 +337,20 @@ bool SDL_SetKeyboardFocus(SDL_Window *window)
337337 }
338338 }
339339
340+ // See if the current window has lost focus
341+ if (keyboard -> focus && keyboard -> focus != window ) {
342+ SDL_SendWindowEvent (keyboard -> focus , SDL_EVENT_WINDOW_FOCUS_LOST , 0 , 0 );
343+
344+ #if !defined(SDL_PLATFORM_IOS ) && !defined(SDL_PLATFORM_ANDROID )
345+ // Ensures IME compositions are committed
346+ if (SDL_TextInputActive (keyboard -> focus )) {
347+ if (video && video -> StopTextInput ) {
348+ video -> StopTextInput (video , keyboard -> focus );
349+ }
350+ }
351+ #endif // !SDL_PLATFORM_IOS && !SDL_PLATFORM_ANDROID
352+ }
353+
340354 if (keyboard -> focus && !window ) {
341355 // We won't get anymore keyboard messages, so reset keyboard state
342356 SDL_ResetKeyboard ();
@@ -355,20 +369,6 @@ bool SDL_SetKeyboardFocus(SDL_Window *window)
355369 }
356370 }
357371
358- // See if the current window has lost focus
359- if (keyboard -> focus && keyboard -> focus != window ) {
360- SDL_SendWindowEvent (keyboard -> focus , SDL_EVENT_WINDOW_FOCUS_LOST , 0 , 0 );
361-
362- #if !defined(SDL_PLATFORM_IOS ) && !defined(SDL_PLATFORM_ANDROID )
363- // Ensures IME compositions are committed
364- if (SDL_TextInputActive (keyboard -> focus )) {
365- if (video && video -> StopTextInput ) {
366- video -> StopTextInput (video , keyboard -> focus );
367- }
368- }
369- #endif // !SDL_PLATFORM_IOS && !SDL_PLATFORM_ANDROID
370- }
371-
372372 keyboard -> focus = window ;
373373
374374 if (keyboard -> focus ) {
0 commit comments