[Scummvm-cvs-logs] scummvm master -> c4317a8da14180d60822b9e5c762c8807cec49de

lordhoto lordhoto at gmail.com
Thu Mar 5 20:15:25 CET 2015


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
26fb7b2c8f SDL: Remove TEXTINPUT events we associate with KEYDOWN.
c4317a8da1 SDL: Fake key events for unassociated TEXTINPUT events.


Commit: 26fb7b2c8fa184d02bf9bfc97ec7281dd8fa7cfd
    https://github.com/scummvm/scummvm/commit/26fb7b2c8fa184d02bf9bfc97ec7281dd8fa7cfd
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2015-03-05T20:08:34+01:00

Commit Message:
SDL: Remove TEXTINPUT events we associate with KEYDOWN.

Changed paths:
    backends/events/sdl/sdl-events.cpp



diff --git a/backends/events/sdl/sdl-events.cpp b/backends/events/sdl/sdl-events.cpp
index 18fe545..a9f94d9 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;
 	}


Commit: c4317a8da14180d60822b9e5c762c8807cec49de
    https://github.com/scummvm/scummvm/commit/c4317a8da14180d60822b9e5c762c8807cec49de
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2015-03-05T20:08:35+01:00

Commit Message:
SDL: Fake key events for unassociated TEXTINPUT events.

Changed paths:
    backends/events/sdl/sdl-events.cpp
    backends/events/sdl/sdl-events.h



diff --git a/backends/events/sdl/sdl-events.cpp b/backends/events/sdl/sdl-events.cpp
index a9f94d9..1e5119d 100644
--- a/backends/events/sdl/sdl-events.cpp
+++ b/backends/events/sdl/sdl-events.cpp
@@ -49,8 +49,33 @@
 #define JOY_BUT_SPACE 4
 #define JOY_BUT_F5 5
 
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+static uint32 convUTF8ToUTF32(const char *src) {
+	uint32 utf32 = 0;
+
+	char *dst = SDL_iconv_string(
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+	                             "UTF-32BE",
+#else
+	                             "UTF-32LE",
+#endif
+                                 "UTF-8", src, SDL_strlen(src) + 1);
+
+	if (dst) {
+		utf32 = *((uint32 *)dst);
+		SDL_free(dst);
+	}
+
+	return utf32;
+}
+#endif
+
 SdlEventSource::SdlEventSource()
-    : EventSource(), _scrollLock(false), _joystick(0), _lastScreenID(0), _graphicsManager(0) {
+    : EventSource(), _scrollLock(false), _joystick(0), _lastScreenID(0), _graphicsManager(0)
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+      , _queuedFakeKeyUp(false), _fakeKeyUp()
+#endif
+      {
 	// Reset mouse state
 	memset(&_km, 0, sizeof(_km));
 
@@ -364,6 +389,16 @@ Common::KeyCode SdlEventSource::SDLToOSystemKeycode(const SDLKey key) {
 bool SdlEventSource::pollEvent(Common::Event &event) {
 	handleKbdMouse();
 
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+	// In case we still need to send a key up event for a key down from a
+	// TEXTINPUT event we do this immediately.
+	if (_queuedFakeKeyUp) {
+		event = _fakeKeyUp;
+		_queuedFakeKeyUp = false;
+		return true;
+	}
+#endif
+
 	// If the screen changed, send an Common::EVENT_SCREEN_CHANGED
 	int screenID = ((OSystem_SDL *)g_system)->getGraphicsManager()->getScreenChangeID();
 	if (screenID != _lastScreenID) {
@@ -424,6 +459,27 @@ bool SdlEventSource::dispatchSDLEvent(SDL_Event &ev, Common::Event &event) {
 		}
 		}
 
+	case SDL_TEXTINPUT: {
+		// When we get a TEXTINPUT event it means we got some user input for
+		// which no KEYDOWN exists. SDL 1.2 introduces a "fake" key down+up
+		// in such cases. We will do the same to mimic it's behavior.
+		event.type = Common::EVENT_KEYDOWN;
+
+		event.kbd = Common::KeyState(Common::KEYCODE_INVALID, convUTF8ToUTF32(ev.text.text), 0);
+
+		SDLModToOSystemKeyFlags(SDL_GetModState(), event);
+		// Set the scroll lock sticky flag
+		if (_scrollLock)
+			event.kbd.flags |= Common::KBD_SCRL;
+
+		// Fake a key up when we have a proper ascii value.
+		_queuedFakeKeyUp = (event.kbd.ascii != 0);
+		_fakeKeyUp = event;
+		_fakeKeyUp.type = Common::EVENT_KEYUP;
+
+		return _queuedFakeKeyUp;
+		}
+
 	case SDL_WINDOWEVENT:
 		switch (ev.window.event) {
 		case SDL_WINDOWEVENT_EXPOSED:
@@ -818,27 +874,6 @@ bool SdlEventSource::handleResizeEvent(Common::Event &event, int w, int h) {
 	return false;
 }
 
-#if SDL_VERSION_ATLEAST(2, 0, 0)
-static uint32 convUTF8ToUTF32(const char *src) {
-	uint32 utf32 = 0;
-
-	char *dst = SDL_iconv_string(
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
-	                             "UTF-32BE",
-#else
-	                             "UTF-32LE",
-#endif
-                                 "UTF-8", src, SDL_strlen(src) + 1);
-
-	if (dst) {
-		utf32 = *((uint32 *)dst);
-		SDL_free(dst);
-	}
-
-	return utf32;
-}
-#endif
-
 uint32 SdlEventSource::obtainUnicode(const SDL_keysym keySym) {
 #if SDL_VERSION_ATLEAST(2, 0, 0)
 	SDL_Event events[2];
diff --git a/backends/events/sdl/sdl-events.h b/backends/events/sdl/sdl-events.h
index 7fc52a0..caa60c1 100644
--- a/backends/events/sdl/sdl-events.h
+++ b/backends/events/sdl/sdl-events.h
@@ -147,6 +147,19 @@ protected:
 	 * May only be used for key down events.
 	 */
 	uint32 obtainUnicode(const SDL_keysym keySym);
+
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+	/**
+	 * Whether _fakeKeyUp contains an event we need to send.
+	 */
+	bool _queuedFakeKeyUp;
+
+	/**
+	 * A fake key up event when we receive a TEXTINPUT without any previous
+	 * KEYDOWN event.
+	 */
+	Common::Event _fakeKeyUp;
+#endif
 };
 
 #endif






More information about the Scummvm-git-logs mailing list