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>
This commit is contained in:
Liang Qi 2021-06-04 12:01:15 +02:00
parent d49f19e661
commit 73ea9f0328

View File

@ -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)