aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schickel2016-05-22 13:04:46 +0200
committerJohannes Schickel2016-05-22 13:09:24 +0200
commitc925e5b35cf87b7e0adb88767fa282ad0d36cf12 (patch)
tree6ec3dd1f95f1d0282daf7fe80804f13483aa214a
parent6581bcad6dfb409924af55dc67e050f3a7504da1 (diff)
downloadscummvm-rg350-c925e5b35cf87b7e0adb88767fa282ad0d36cf12.tar.gz
scummvm-rg350-c925e5b35cf87b7e0adb88767fa282ad0d36cf12.tar.bz2
scummvm-rg350-c925e5b35cf87b7e0adb88767fa282ad0d36cf12.zip
SDL: Make TEXTINPUT handling more reliable for SDL2.
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.
-rw-r--r--backends/events/sdl/sdl-events.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/backends/events/sdl/sdl-events.cpp b/backends/events/sdl/sdl-events.cpp
index 7b56a0a955..00e2f25cbc 100644
--- a/backends/events/sdl/sdl-events.cpp
+++ b/backends/events/sdl/sdl-events.cpp
@@ -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.