diff options
Diffstat (limited to 'backends/events')
-rw-r--r-- | backends/events/sdl/sdl-events.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/backends/events/sdl/sdl-events.cpp b/backends/events/sdl/sdl-events.cpp index 18fe5453f8..a9f94d9fa9 100644 --- a/backends/events/sdl/sdl-events.cpp +++ b/backends/events/sdl/sdl-events.cpp @@ -850,10 +850,19 @@ uint32 SdlEventSource::obtainUnicode(const SDL_keysym keySym) { int n = SDL_PeepEvents(events, 2, SDL_PEEKEVENT, SDL_KEYDOWN, SDL_TEXTINPUT); // Make sure that the TEXTINPUT event belongs to this KEYDOWN // event and not another pending one. - if (n > 0 && events[0].type == SDL_TEXTINPUT) { - return convUTF8ToUTF32(events[0].text.text); - } else if (n > 1 && events[0].type != SDL_KEYDOWN && events[1].type == SDL_TEXTINPUT) { - return convUTF8ToUTF32(events[1].text.text); + if ((n > 0 && events[0].type == SDL_TEXTINPUT) + || (n > 1 && events[0].type != SDL_KEYDOWN && events[1].type == SDL_TEXTINPUT)) { + // Remove the text input event we associate with the key press. This + // makes sure we never get any SDL_TEXTINPUT events which do "belong" + // to SDL_KEYDOWN events. + n = SDL_PeepEvents(events, 1, SDL_GETEVENT, SDL_TEXTINPUT, SDL_TEXTINPUT); + // This is basically a paranoia safety check because we know there + // must be a text input event in the queue. + if (n > 0) { + return convUTF8ToUTF32(events[0].text.text); + } else { + return 0; + } } else { return 0; } |