Skip to content

Commit 2d14a23

Browse files
committed
Fixed trying to grab the mouse when losing keyboard focus
Fixes #14350
1 parent a57757a commit 2d14a23

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

src/events/SDL_keyboard.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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) {

src/events/SDL_windowevents.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,6 @@ bool SDL_SendWindowEvent(SDL_Window *window, SDL_EventType windowevent, int data
7777
}
7878
SDL_assert(SDL_ObjectValid(window, SDL_OBJECT_TYPE_WINDOW));
7979

80-
if (window->is_destroying && windowevent != SDL_EVENT_WINDOW_DESTROYED) {
81-
return false;
82-
}
8380
switch (windowevent) {
8481
case SDL_EVENT_WINDOW_SHOWN:
8582
if (!(window->flags & SDL_WINDOW_HIDDEN)) {
@@ -219,6 +216,10 @@ bool SDL_SendWindowEvent(SDL_Window *window, SDL_EventType windowevent, int data
219216
break;
220217
}
221218

219+
if (window->is_destroying && windowevent != SDL_EVENT_WINDOW_DESTROYED) {
220+
return false;
221+
}
222+
222223
// Post the event, if desired
223224
SDL_Event event;
224225
event.type = windowevent;

0 commit comments

Comments
 (0)