From 7b40a6a0e44bf27be0dacb0da9b7992501241f87 Mon Sep 17 00:00:00 2001 From: rdb Date: Sat, 29 Feb 2020 16:59:36 +0100 Subject: [PATCH] x11: restore locale after opening input method Fixes #728 --- panda/src/x11display/x11GraphicsPipe.cxx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/panda/src/x11display/x11GraphicsPipe.cxx b/panda/src/x11display/x11GraphicsPipe.cxx index a7efba30af..985360adc6 100644 --- a/panda/src/x11display/x11GraphicsPipe.cxx +++ b/panda/src/x11display/x11GraphicsPipe.cxx @@ -49,6 +49,13 @@ x11GraphicsPipe(const std::string &display) : display_spec = ":0.0"; } + // Store the current locale, so that we can restore it later. + std::string saved_locale; + char *saved_locale_p = setlocale(LC_ALL, nullptr); + if (saved_locale_p != nullptr) { + saved_locale = saved_locale_p; + } + // The X docs say we should do this to get international character support // from the keyboard. setlocale(LC_ALL, ""); @@ -338,6 +345,11 @@ x11GraphicsPipe(const std::string &display) : XFree(im_supported_styles); */ + // Restore the previous locale. + if (!saved_locale.empty()) { + setlocale(LC_ALL, saved_locale.c_str()); + } + // Get some X atom numbers. _wm_delete_window = XInternAtom(_display, "WM_DELETE_WINDOW", false); _net_wm_pid = XInternAtom(_display, "_NET_WM_PID", false);