mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-06-02 15:47:31 +08:00
Make sure the window is valid in SDL_SetKeyboardFocus()
This commit is contained in:
@@ -746,10 +746,17 @@ SDL_GetKeyboardFocus(void)
|
|||||||
return keyboard->focus;
|
return keyboard->focus;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDL_SetKeyboardFocus(SDL_Window *window)
|
int SDL_SetKeyboardFocus(SDL_Window *window)
|
||||||
{
|
{
|
||||||
|
SDL_VideoDevice *video = SDL_GetVideoDevice();
|
||||||
SDL_Keyboard *keyboard = &SDL_keyboard;
|
SDL_Keyboard *keyboard = &SDL_keyboard;
|
||||||
|
|
||||||
|
if (window) {
|
||||||
|
if (!video || window->magic != &video->window_magic || window->is_destroying) {
|
||||||
|
return SDL_SetError("Invalid window");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (keyboard->focus && window == NULL) {
|
if (keyboard->focus && window == NULL) {
|
||||||
/* We won't get anymore keyboard messages, so reset keyboard state */
|
/* We won't get anymore keyboard messages, so reset keyboard state */
|
||||||
SDL_ResetKeyboard();
|
SDL_ResetKeyboard();
|
||||||
@@ -773,7 +780,6 @@ void SDL_SetKeyboardFocus(SDL_Window *window)
|
|||||||
|
|
||||||
/* Ensures IME compositions are committed */
|
/* Ensures IME compositions are committed */
|
||||||
if (SDL_EventEnabled(SDL_EVENT_TEXT_INPUT)) {
|
if (SDL_EventEnabled(SDL_EVENT_TEXT_INPUT)) {
|
||||||
SDL_VideoDevice *video = SDL_GetVideoDevice();
|
|
||||||
if (video && video->StopTextInput) {
|
if (video && video->StopTextInput) {
|
||||||
video->StopTextInput(video);
|
video->StopTextInput(video);
|
||||||
}
|
}
|
||||||
@@ -793,6 +799,7 @@ void SDL_SetKeyboardFocus(SDL_Window *window)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int SDL_SendKeyboardKeyInternal(Uint64 timestamp, SDL_KeyboardFlags flags, Uint8 state, SDL_Scancode scancode, SDL_Keycode keycode)
|
static int SDL_SendKeyboardKeyInternal(Uint64 timestamp, SDL_KeyboardFlags flags, Uint8 state, SDL_Scancode scancode, SDL_Keycode keycode)
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ extern void SDL_SetKeymap(int start, const SDL_Keycode *keys, int length, SDL_bo
|
|||||||
extern void SDL_SetScancodeName(SDL_Scancode scancode, const char *name);
|
extern void SDL_SetScancodeName(SDL_Scancode scancode, const char *name);
|
||||||
|
|
||||||
/* Set the keyboard focus window */
|
/* Set the keyboard focus window */
|
||||||
extern void SDL_SetKeyboardFocus(SDL_Window *window);
|
extern int SDL_SetKeyboardFocus(SDL_Window *window);
|
||||||
|
|
||||||
/* Send a character from an on-screen keyboard as scancode and modifier key events,
|
/* Send a character from an on-screen keyboard as scancode and modifier key events,
|
||||||
currently assuming ASCII characters on a US keyboard layout
|
currently assuming ASCII characters on a US keyboard layout
|
||||||
|
|||||||
Reference in New Issue
Block a user