[SDL] Fix processing keyboard events if SDL_EnableUNICODE() is enabled
Petr Pisar
ppisar at fedoraproject.org
Mon Aug 4 07:49:48 UTC 2014
commit b2b2095f5e7f7fa9fa3d0f205673e0cb1eb2b3c4
Author: Petr Písař <ppisar at redhat.com>
Date: Mon Aug 4 09:42:19 2014 +0200
Fix processing keyboard events if SDL_EnableUNICODE() is enabled
...5-SDL_EnableUNICODE_drops_keyboard_events.patch | 73 ++++++++++++++++++++
SDL.spec | 10 +++-
2 files changed, 82 insertions(+), 1 deletions(-)
---
diff --git a/SDL-1.2.15-SDL_EnableUNICODE_drops_keyboard_events.patch b/SDL-1.2.15-SDL_EnableUNICODE_drops_keyboard_events.patch
new file mode 100644
index 0000000..fdf910e
--- /dev/null
+++ b/SDL-1.2.15-SDL_EnableUNICODE_drops_keyboard_events.patch
@@ -0,0 +1,73 @@
+# HG changeset patch
+# User Sam Lantinga <slouken at libsdl.org>
+# Date 1397799374 25200
+# Thu Apr 17 22:36:14 2014 -0700
+# Branch SDL-1.2
+# Node ID 0aade9c0203f717fe4b823a176c3c040f1a709f8
+# Parent 22a7f096bb9d4d596f35a93e33608825693462b0
+Fixed bug 2325 - SDL_EnableUNICODE sometimes drops keyboard events completely
+
+Rafał Mużyło
+
+The most annoying part of this bug is that though I've found it in two separate apps, I don't have a trivial testcase for it.
+
+The problem seems to be a condition race, as it's triggered quite randomly (therefore it will be hard to tell whether it really gets fixed, if a probable fix is found).
+
+While it's specific to SDL 1.2, it seems quite similar to the problem described and fixed in http://forums.libsdl.org/viewtopic.php?p=40503.
+
+Now, I should start describing the problem.
+
+A game uses Escape to open menu (the exact key might not be important). Upon opening, it calls SDL_EnableUNICODE(1). Upon closing it calls SDL_EnableUNICODE(0).
+
+I have an IME running.
+
+Game uses SDL_PollEvent to get the events.
+
+If Escape is pressed repeatedly, menu is opened and closed, till it eventually freezes in open state.
+"freezes" in this context means "app itself still runs, but no keyboard events are getting delivered (though - for example - mouse events still are)". "getting delivered" should mean "SDL_PollEvent is not receiving any".
+If it matters, the last delivered keyboard event is a keypress, the release never arrives.
+
+It seems (no guarantees, due to random nature of the freeze) that unsetting XMODIFIERS (which - AFAIU - will disable IME as far as SDL is concerned) prevents the freeze, therefore the reference to that SDL2 thread.
+
+diff -r 22a7f096bb9d -r 0aade9c0203f src/video/x11/SDL_x11events.c
+--- a/src/video/x11/SDL_x11events.c Sun Dec 01 00:00:17 2013 -0500
++++ b/src/video/x11/SDL_x11events.c Thu Apr 17 22:36:14 2014 -0700
+@@ -395,6 +395,8 @@
+ {
+ int posted;
+ XEvent xevent;
++ int orig_event_type;
++ KeyCode orig_keycode;
+
+ SDL_memset(&xevent, '\0', sizeof (XEvent)); /* valgrind fix. --ryan. */
+ XNextEvent(SDL_Display, &xevent);
+@@ -410,9 +412,29 @@
+ #ifdef X_HAVE_UTF8_STRING
+ /* If we are translating with IM, we need to pass all events
+ to XFilterEvent, and discard those filtered events immediately. */
++ orig_event_type = xevent.type;
++ if (orig_event_type == KeyPress || orig_event_type == KeyRelease) {
++ orig_keycode = xevent.xkey.keycode;
++ } else {
++ orig_keycode = 0;
++ }
+ if ( SDL_TranslateUNICODE
+ && SDL_IM != NULL
+ && XFilterEvent(&xevent, None) ) {
++ if (orig_keycode) {
++ SDL_keysym keysym;
++ static XComposeStatus state;
++ char keybuf[32];
++
++ keysym.scancode = xevent.xkey.keycode;
++ keysym.sym = X11_TranslateKeycode(SDL_Display, xevent.xkey.keycode);
++ keysym.mod = KMOD_NONE;
++ keysym.unicode = 0;
++ if (orig_event_type == KeyPress && XLookupString(&xevent.xkey, keybuf, sizeof(keybuf), NULL, &state))
++ keysym.unicode = (Uint8)keybuf[0];
++
++ SDL_PrivateKeyboard(orig_event_type == KeyPress ? SDL_PRESSED : SDL_RELEASED, &keysym);
++ }
+ return 0;
+ }
+ #endif
diff --git a/SDL.spec b/SDL.spec
index 8a7f9e8..27d6957 100644
--- a/SDL.spec
+++ b/SDL.spec
@@ -10,7 +10,7 @@
Name: SDL
Version: 1.2.15
-Release: 15%{?dist}
+Release: 16%{?dist}
Summary: A cross-platform multimedia library
Group: System Environment/Libraries
URL: http://www.libsdl.org/
@@ -37,6 +37,9 @@ Patch5: SDL-1.2.15-ignore_insane_joystick_axis.patch
# Do not use backing store by default, sdl2383, rh1073057, rejected by
# upstream
Patch6: SDL-1.2.15-no-default-backing-store.patch
+# Fix processing keyboard events if SDL_EnableUNICODE() is enabled, sdl2325,
+# rh1126136, in upstream after 1.2.15
+Patch7: SDL-1.2.15-SDL_EnableUNICODE_drops_keyboard_events.patch
BuildRequires: alsa-lib-devel
%if %{with arts}
@@ -106,6 +109,7 @@ applications.
%patch4 -p1 -b .sdl_config_man
%patch5 -p1 -b .insane_axis
%patch6 -p1 -b .backing_store
+%patch7 -p1 -b .sdl_enableunicode
for F in CREDITS; do
iconv -f iso8859-1 -t utf-8 < "$F" > "${F}.utf"
touch --reference "$F" "${F}.utf"
@@ -181,6 +185,10 @@ rm -f %{buildroot}%{_libdir}/*.la
%{_libdir}/lib*.a
%changelog
+* Mon Aug 04 2014 Petr Pisar <ppisar at redhat.com> - 1.2.15-16
+- Fix processing keyboard events if SDL_EnableUNICODE() is enabled
+ (bug #1126136)
+
* Fri Jun 06 2014 Fedora Release Engineering <rel-eng at lists.fedoraproject.org> - 1.2.15-15
- Rebuilt for https://fedoraproject.org/wiki/Fedora_21_Mass_Rebuild
More information about the scm-commits
mailing list