summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforminputcontexts/compose
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2021-06-04 12:01:15 +0200
committerLiang Qi <liang.qi@qt.io>2021-06-21 16:05:03 +0000
commit73ea9f032864566cc019d286b2f210b78cd70a3d (patch)
treed2f09ee0a708bd789fe6089e5a0155030362bcef /src/plugins/platforminputcontexts/compose
parentd49f19e66107f6f56271e32284ee952af598ff1b (diff)
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 <edward.welbourne@qt.io>
Diffstat (limited to 'src/plugins/platforminputcontexts/compose')
-rw-r--r--src/plugins/platforminputcontexts/compose/qcomposeplatforminputcontext.cpp14
1 files changed, 10 insertions, 4 deletions
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)