From e2fb78f6fec563a4ad3601bd0611a0c7dbaa7504 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Mon, 29 May 2017 11:51:26 -0400 Subject: [PATCH] work on the Linux locale init problem --- linux_4ed.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/linux_4ed.cpp b/linux_4ed.cpp index 93ef4526..05a69625 100644 --- a/linux_4ed.cpp +++ b/linux_4ed.cpp @@ -1739,10 +1739,23 @@ LinuxInputInit(Display *dpy, Window XWindow){ XIMStyle style; unsigned long xim_event_mask = 0; - setlocale(LC_ALL, ""); - XSetLocaleModifiers(""); - fprintf(stderr, "Supported locale?: %s.\n", XSupportsLocale() ? "Yes" : "No"); - // TODO(inso): handle the case where it isn't supported somehow? + char *prev_locale = setlocale(LC_ALL, ""); + char *prev_modifiers = XSetLocaleModifiers(""); + b32 locale_supported = XSupportsLocale(); + fprintf(stderr, "Supported locale?: %s.\n", locale_supported ? "Yes" : "No"); + if (!locale_supported){ + fprintf(stderr, "Previous locale was %s\n", prev_locale); + fprintf(stderr, "Previous modifiers were %s\n", prev_modifiers); + fprintf(stderr, "Reverting to previous locale setup ... "); + if (prev_locale != 0){ + setlocale(LC_ALL, prev_locale); + } + if (prev_modifiers != 0){ + XSetLocaleModifiers(prev_modifiers); + } + locale_supported = XSupportsLocale(); + fprintf(stderr, "Previous is supported? %s.\n", locale_supported ? "Yes" : "No"); + } result.input_method = XOpenIM(dpy, 0, 0, 0); if (!result.input_method){ @@ -1776,11 +1789,13 @@ LinuxInputInit(Display *dpy, Window XWindow){ else{ result = null_init_input_result; fputs("Could not get minimum required input style.\n", stderr); + exit(1); } } else{ result = null_init_input_result; fprintf(stderr, "Could not open X Input Method.\n"); + exit(1); } u32 flags = ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | FocusChangeMask | StructureNotifyMask | MappingNotify | ExposureMask | VisibilityChangeMask | xim_event_mask;