SDL: Improve handling of SDL2 keyboard repeat events

- Flag them as repeat events
- Disable ScummVM's own repeat event generation

This fixes keyboard repeat events not being flagged as such with SDL2,
and complies with the user's operating system preferences regarding key
repeat timings.
This commit is contained in:
Bastien Bouclet 2017-09-09 15:45:28 +02:00
parent 7d811d356e
commit 8fc70ce37f
2 changed files with 15 additions and 0 deletions

View File

@ -696,6 +696,10 @@ bool SdlEventSource::handleKeyDown(SDL_Event &ev, Common::Event &event) {
event.kbd.keycode = SDLToOSystemKeycode(sdlKeycode);
event.kbd.ascii = mapKey(sdlKeycode, (SDLMod)ev.key.keysym.mod, obtainUnicode(ev.key.keysym));
#if SDL_VERSION_ATLEAST(2, 0, 0)
event.kbdRepeat = ev.key.repeat;
#endif
return true;
}

View File

@ -43,6 +43,7 @@
#include "backends/audiocd/sdl/sdl-audiocd.h"
#endif
#include "backends/events/default/default-events.h"
#include "backends/events/sdl/sdl-events.h"
#include "backends/mutex/sdl/sdl-mutex.h"
#include "backends/timer/sdl/sdl-timer.h"
@ -207,6 +208,16 @@ void OSystem_SDL::initBackend() {
if (_eventSource == 0)
_eventSource = new SdlEventSource();
if (_eventManager == nullptr) {
DefaultEventManager *eventManager = new DefaultEventManager(_eventSource);
#if SDL_VERSION_ATLEAST(2, 0, 0)
// SDL 2 generates its own keyboard repeat events.
eventManager->setGenerateKeyRepeatEvents(false);
#endif
_eventManager = eventManager;
}
#ifdef USE_OPENGL
#if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_DisplayMode displayMode;