We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4215

Summary: Key events can be buffered when compiling without Ibus support on an Ibus supported system
Product: SDL Reporter: Marc Di Luzio <marcdi>
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: marcdi
Version: 2.0.8   
Hardware: x86_64   
OS: Linux   
Attachments: Simple reproduction file

Description Marc Di Luzio 2018-07-12 16:08:45 UTC
Created attachment 3271 [details]
Simple reproduction file

Tested on latest tip of default (1a1133e9c7d4).

On Linux, if SDL is compiled without ibus or fcitx support, but the system does support either - ie. XMODIFIERS="@im=ibus", then X key events for held keys will be buffered at low FPS.

See the example file to repro.

Compile and link with a SDL configured with --disable-ibus and --disable-fcitx, and run on a system with either supported (Ubuntu 18.04 will do).

This was originally introduced with https://hg.libsdl.org/SDL/rev/c3874aa1f2d1, which wrapped the setting of new_xmods behind the HAVE_IBUS_IBUS_H or HAVE_FCITX_FRONTEND_H defines.

https://hg.libsdl.org/SDL/rev/b48d8a98e261 Fixed a related issue, but the bug still remained.

A possible patch fix will be attached i a subsequent comment, though I'm unsure if it's exactly the correct fix.
Comment 1 Marc Di Luzio 2018-07-12 16:10:14 UTC
This patch fixes the issue locally. It simple ensures SDL still sets "@im=none" on systems that have ibus/fcitx support, regardless of whether SDL itself was configured with direct support.

# HG changeset patch
# User Marc Di Luzio <marcdi@unity3d.com>
# Date 1531410765 -3600
#      Thu Jul 12 16:52:45 2018 +0100
# Node ID 44ebedcfe8bf4b244d0cedb83019cc65985b6e83
# Parent  1a1133e9c7d40416af82e97711f91f5a857ffc54
Ensure we still clear the X locale modifiers even if not compiled with ibus or fcitx support

diff --git a/src/video/x11/SDL_x11keyboard.c b/src/video/x11/SDL_x11keyboard.c
--- a/src/video/x11/SDL_x11keyboard.c
+++ b/src/video/x11/SDL_x11keyboard.c
@@ -292,9 +292,7 @@
         char *prev_locale = setlocale(LC_ALL, NULL);
         char *prev_xmods  = X11_XSetLocaleModifiers(NULL);
         const char *new_xmods = "";
-#if defined(HAVE_IBUS_IBUS_H) || defined(HAVE_FCITX_FRONTEND_H)
         const char *env_xmods = SDL_getenv("XMODIFIERS");
-#endif
         SDL_bool has_dbus_ime_support = SDL_FALSE;
 
         if (prev_locale) {
@@ -309,16 +307,12 @@
            when it is used via XIM which causes issues. Prevent this by forcing
            @im=none if XMODIFIERS contains @im=ibus. IBus can still be used via 
            the DBus implementation, which also has support for pre-editing. */
-#ifdef HAVE_IBUS_IBUS_H
         if (env_xmods && SDL_strstr(env_xmods, "@im=ibus") != NULL) {
             has_dbus_ime_support = SDL_TRUE;
         }
-#endif
-#ifdef HAVE_FCITX_FRONTEND_H
         if (env_xmods && SDL_strstr(env_xmods, "@im=fcitx") != NULL) {
             has_dbus_ime_support = SDL_TRUE;
         }
-#endif
         if (has_dbus_ime_support || !xkb_repeat) {
             new_xmods = "@im=none";
         }
Comment 2 Marc Di Luzio 2018-07-13 10:51:02 UTC
Just to add a little more info for the repro file - when running, hold a keyboard key for more than a second and see the output. Release the key, and see that the events keep repeating for an extended period of time. SDL_PollEvent should be returning true if it has events queued, but it doesn't, they're still buffered in X.
Comment 3 Sam Lantinga 2018-07-17 15:56:20 UTC
Patch added, thanks!
https://hg.libsdl.org/SDL/rev/5b6f649b6488