Skip to content

Commit 4fc5405

Browse files
committed
Fixed trying to grab the mouse when losing keyboard focus
Fixes libsdl-org#14350 (cherry picked from commit 2d14a23)
1 parent 16d9f73 commit 4fc5405

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

src/events/SDL_keyboard.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,18 @@ bool SDL_SetKeyboardFocus(SDL_Window *window)
333333
}
334334
}
335335

336+
// See if the current window has lost focus
337+
if (keyboard->focus && keyboard->focus != window) {
338+
SDL_SendWindowEvent(keyboard->focus, SDL_EVENT_WINDOW_FOCUS_LOST, 0, 0);
339+
340+
// Ensures IME compositions are committed
341+
if (SDL_TextInputActive(keyboard->focus)) {
342+
if (video && video->StopTextInput) {
343+
video->StopTextInput(video, keyboard->focus);
344+
}
345+
}
346+
}
347+
336348
if (keyboard->focus && !window) {
337349
// We won't get anymore keyboard messages, so reset keyboard state
338350
SDL_ResetKeyboard();
@@ -351,18 +363,6 @@ bool SDL_SetKeyboardFocus(SDL_Window *window)
351363
}
352364
}
353365

354-
// See if the current window has lost focus
355-
if (keyboard->focus && keyboard->focus != window) {
356-
SDL_SendWindowEvent(keyboard->focus, SDL_EVENT_WINDOW_FOCUS_LOST, 0, 0);
357-
358-
// Ensures IME compositions are committed
359-
if (SDL_TextInputActive(keyboard->focus)) {
360-
if (video && video->StopTextInput) {
361-
video->StopTextInput(video, keyboard->focus);
362-
}
363-
}
364-
}
365-
366366
keyboard->focus = window;
367367

368368
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)) {
@@ -212,6 +209,10 @@ bool SDL_SendWindowEvent(SDL_Window *window, SDL_EventType windowevent, int data
212209
break;
213210
}
214211

212+
if (window->is_destroying && windowevent != SDL_EVENT_WINDOW_DESTROYED) {
213+
return false;
214+
}
215+
215216
// Post the event, if desired
216217
SDL_Event event;
217218
event.type = windowevent;

0 commit comments

Comments
 (0)