From b2030f6d73bc289cfa2532384ca47ec1afc17fe3 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 18 Dec 2014 02:52:06 +0100 Subject: [PATCH] Fixed X11 character input for C locale. Fixes #396. --- README.md | 1 + include/GLFW/glfw3.h | 6 ++++++ src/x11_init.c | 4 ++++ tests/events.c | 3 --- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 216bf47a..8d461b36 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,7 @@ GLFW bundles a number of dependencies in the `deps/` directory. - [X11] Bugfix: X-axis scroll offsets were inverted - [X11] Bugfix: Full screen override redirect windows were not always positioned over the specified monitor + - [X11] Bugfix: Character input did not work for the default `"C"` locale ## Contact diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index b88867a5..9601c334 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -1089,6 +1089,12 @@ typedef struct GLFWimage * bundle, if present. This can be disabled with a * [compile-time option](@ref compile_options_osx). * + * @remarks __X11:__ If the `LC_CTYPE` category of the current locale is set to + * `"C"` then the environment's locale will be applied to that category. This + * is done because character input will not function when `LC_CTYPE` is set to + * `"C"`. If another locale was set before this function was called, it will + * be left untouched. + * * @par Thread Safety * This function may only be called from the main thread. * diff --git a/src/x11_init.c b/src/x11_init.c index 7430765c..2a122229 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -33,6 +33,7 @@ #include #include #include +#include // Translate an X11 key code to a GLFW key code. @@ -709,6 +710,9 @@ Cursor _glfwCreateCursor(const GLFWimage* image, int xhot, int yhot) int _glfwPlatformInit(void) { + if (strcmp(setlocale(LC_CTYPE, NULL), "C") == 0) + setlocale(LC_CTYPE, ""); + XInitThreads(); _glfw.x11.display = XOpenDisplay(NULL); diff --git a/tests/events.c b/tests/events.c index fda68164..c1203330 100644 --- a/tests/events.c +++ b/tests/events.c @@ -37,7 +37,6 @@ #include #include #include -#include #include "getopt.h" @@ -443,8 +442,6 @@ int main(int argc, char** argv) GLFWmonitor* monitor = NULL; int ch, i, width, height, count = 1; - setlocale(LC_ALL, ""); - glfwSetErrorCallback(error_callback); if (!glfwInit())