From 73ea9f032864566cc019d286b2f210b78cd70a3d Mon Sep 17 00:00:00 2001 From: Liang Qi Date: Fri, 4 Jun 2021 12:01:15 +0200 Subject: xkb.compose: get locale from user env settings The setlocale call will only give useful results if the program had previously set the current locale using setlocale... See also "Compose Locale" section in xkbcommon doc: https://xkbcommon.org/doc/current/group__compose.html#compose-locale Fixes: QTBUG-85529 Pick-to: 6.2 6.1 6.0 5.15 Change-Id: I65b1ac86ea54445bc3a2e1707df79bd9f732ab46 Reviewed-by: Edward Welbourne --- .../compose/qcomposeplatforminputcontext.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/plugins/platforminputcontexts/compose') diff --git a/src/plugins/platforminputcontexts/compose/qcomposeplatforminputcontext.cpp b/src/plugins/platforminputcontexts/compose/qcomposeplatforminputcontext.cpp index 4e9828663f..da5235e491 100644 --- a/src/plugins/platforminputcontexts/compose/qcomposeplatforminputcontext.cpp +++ b/src/plugins/platforminputcontexts/compose/qcomposeplatforminputcontext.cpp @@ -71,10 +71,16 @@ void QComposeInputContext::ensureInitialized() } m_initialized = true; - const char *locale = setlocale(LC_CTYPE, ""); - if (!locale) - locale = setlocale(LC_CTYPE, nullptr); - qCDebug(lcXkbCompose) << "detected locale (LC_CTYPE):" << locale; + // Get locale from user env settings, see also + // https://xkbcommon.org/doc/current/group__compose.html#compose-locale + const char *locale = getenv("LC_ALL"); + if (!locale || !*locale) + locale = getenv("LC_CTYPE"); + if (!locale || !*locale) + locale = getenv("LANG"); + if (!locale || !*locale) + locale = "C"; + qCDebug(lcXkbCompose) << "detected locale:" << locale; m_composeTable = xkb_compose_table_new_from_locale(m_XkbContext, locale, XKB_COMPOSE_COMPILE_NO_FLAGS); if (m_composeTable) -- cgit v1.2.3