Skip to content

Commit

Permalink
SDL: Make TEXTINPUT handling more reliable for SDL2.
Browse files Browse the repository at this point in the history
This reduces the likelihood of entering two characters per keypress in our guy
on Windows. In fact, during my brief testing with the filter widget in the
launcher I was not able to trigger the former behavior at all anymore.
  • Loading branch information
Johannes Schickel committed May 22, 2016
1 parent 6581bca commit c925e5b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions backends/events/sdl/sdl-events.cpp
Expand Up @@ -872,6 +872,21 @@ uint32 SdlEventSource::obtainUnicode(const SDL_keysym keySym) {
#if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_Event events[2];

// Update the event queue here to give SDL a chance to insert TEXTINPUT
// events for KEYDOWN events. Otherwise we have a high chance that on
// Windows the TEXTINPUT event is not in the event queue at this point.
// In this case we will get two events with ascii values due to mapKey
// and dispatchSDLEvent. This results in nasty double input of characters
// in the GUI.
//
// FIXME: This is all a bit fragile because in mapKey we derive the ascii
// value from the key code if no unicode value is given. This is legacy
// behavior and should be removed anyway. If that is removed, we might not
// even need to do this peeking here but instead can rely on the
// SDL_TEXTINPUT case in dispatchSDLEvent to introduce keydown/keyup with
// proper ASCII values (but with KEYCODE_INVALID as keycode).
SDL_PumpEvents();

// In SDL2, the unicode field has been removed from the keysym struct.
// Instead a SDL_TEXTINPUT event is generated on key combinations that
// generates unicode.
Expand Down

0 comments on commit c925e5b

Please sign in to comment.