From 5af67f49f461179beca78f26cef49415ef4c9e19 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 17 Oct 2016 21:37:26 -0700 Subject: [PATCH] Fixed bug 3458 - x11: reset deadkeys in StartTextInput/StopTextInput Eric Wasylishen The patch makes StartTextInput/StopTextInput call Xutf8ResetIC ( https://www.x.org/releases/X11R7.5/doc/man/man3/XmbResetIC.3.html ) on the XIC of all SDL windows. This fixes my use case in Quakespasm (Ubuntu 16.04, system keyboard layout set to German. Type the '^' dead key, which opens Quakespasm's developer console and calls SDL_StartTextInput, then press 'e'. I expect the dead key to be ignored.) Also, here is a patch for sdl2's "checkkeys" for testing this: https://bugzilla-attachments.libsdl.org/attachment.cgi?id=2451 --- src/video/x11/SDL_x11keyboard.c | 25 ++++++++++++++++++++++++- src/video/x11/SDL_x11sym.h | 1 + 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/video/x11/SDL_x11keyboard.c b/src/video/x11/SDL_x11keyboard.c index e7e1a56a9..b888bff35 100644 --- a/src/video/x11/SDL_x11keyboard.c +++ b/src/video/x11/SDL_x11keyboard.c @@ -427,15 +427,38 @@ X11_QuitKeyboard(_THIS) #endif } +static void +X11_ResetXIM(_THIS) +{ +#ifdef X_HAVE_UTF8_STRING + SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata; + int i; + + if (videodata && videodata->windowlist) { + for (i = 0; i < videodata->numwindows; ++i) { + SDL_WindowData *data = videodata->windowlist[i]; + if (data && data->ic) { + /* Clear any partially entered dead keys */ + char *contents = X11_Xutf8ResetIC(data->ic); + if (contents) { + X11_XFree(contents); + } + } + } + } +#endif +} + void X11_StartTextInput(_THIS) { - + X11_ResetXIM(_this); } void X11_StopTextInput(_THIS) { + X11_ResetXIM(_this); #ifdef SDL_USE_IME SDL_IME_Reset(); #endif diff --git a/src/video/x11/SDL_x11sym.h b/src/video/x11/SDL_x11sym.h index c9840d845..7290412b7 100644 --- a/src/video/x11/SDL_x11sym.h +++ b/src/video/x11/SDL_x11sym.h @@ -201,6 +201,7 @@ SDL_X11_SYM(Status,XCloseIM,(XIM a),(a),return) SDL_X11_SYM(void,Xutf8DrawString,(Display *a, Drawable b, XFontSet c, GC d, int e, int f, _Xconst char *g, int h),(a,b,c,d,e,f,g,h),) SDL_X11_SYM(int,Xutf8TextExtents,(XFontSet a, _Xconst char* b, int c, XRectangle* d, XRectangle* e),(a,b,c,d,e),return) SDL_X11_SYM(char*,XSetLocaleModifiers,(const char *a),(a),return) +SDL_X11_SYM(char*,Xutf8ResetIC,(XIC a),(a),return) #endif #ifndef NO_SHARED_MEMORY