From 0ac013381be83fcd6e53ea874f09b1895943bd9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Thu, 6 Feb 2020 15:46:37 +0100 Subject: [PATCH] X11: Fix CJK IME input when locale CTYPE is "C" Fixes #1587. Fixes #1636. (cherry picked from commit 4381b86b6ba63598de82c3f05824dc00a2b3ec59) --- README.md | 2 +- include/GLFW/glfw3.h | 4 ++++ src/x11_init.c | 11 ++++------- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index a1a5f8cb..a9f0d935 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ information on what to include when reporting a bug. ## Changelog -There is nothing here yet. + - [X11] Bugfix: IME input of CJK was broken for "C" locale (#1587,#1636) ## Contact diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index 47a32ec8..255b5279 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -1753,6 +1753,10 @@ typedef struct GLFWgamepadstate * bundle, if present. This can be disabled with the @ref * GLFW_COCOA_CHDIR_RESOURCES init hint. * + * @remark @x11 This function will set the `LC_CTYPE` category of the + * application locale according to the current environment if that category is + * still "C". This is because the "C" locale breaks Unicode text input. + * * @thread_safety This function must only be called from the main thread. * * @sa @ref intro_init diff --git a/src/x11_init.c b/src/x11_init.c index 2f220ec5..ee6c8720 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -931,15 +931,12 @@ Cursor _glfwCreateCursorX11(const GLFWimage* image, int xhot, int yhot) int _glfwPlatformInit(void) { -#if !defined(X_HAVE_UTF8_STRING) - // HACK: If the current locale is "C" and the Xlib UTF-8 functions are - // unavailable, apply the environment's locale in the hope that it's - // both available and not "C" - // This is done because the "C" locale breaks wide character input, - // which is what we fall back on when UTF-8 support is missing + // HACK: If the application has left the locale as "C" then both wide + // character text input and explicit UTF-8 input via XIM will break + // This sets the CTYPE part of the current locale from the environment + // in the hope that it is set to something more sane than "C" if (strcmp(setlocale(LC_CTYPE, NULL), "C") == 0) setlocale(LC_CTYPE, ""); -#endif XInitThreads(); XrmInitialize();