@@ -185,22 +185,13 @@ void InstanceArgument::printUsage() const {
185
185
186
186
InstancePrivate::InstancePrivate (Instance *q) : QPtrHolder<Instance>(q) {
187
187
#ifdef ENABLE_KEYBOARD
188
- auto locale = getEnvironment (" LC_ALL" );
189
- if (!locale) {
190
- locale = getEnvironment (" LC_CTYPE" );
191
- }
192
- if (!locale) {
193
- locale = getEnvironment (" LANG" );
194
- }
195
- if (!locale) {
196
- locale = " C" ;
197
- }
198
- assert (locale.has_value ());
188
+ const auto locale = getLocale ();
189
+ assert (!locale.empty ());
199
190
xkbContext_.reset (xkb_context_new (XKB_CONTEXT_NO_FLAGS));
200
191
if (xkbContext_) {
201
192
xkb_context_set_log_level (xkbContext_.get (), XKB_LOG_LEVEL_CRITICAL);
202
193
xkbComposeTable_.reset (xkb_compose_table_new_from_locale (
203
- xkbContext_.get (), locale-> data (), XKB_COMPOSE_COMPILE_NO_FLAGS));
194
+ xkbContext_.get (), locale. data (), XKB_COMPOSE_COMPILE_NO_FLAGS));
204
195
if (!xkbComposeTable_) {
205
196
FCITX_INFO ()
206
197
<< " Trying to fallback to compose table for en_US.UTF-8" ;
@@ -224,6 +215,18 @@ InstancePrivate::watchEvent(EventType type, EventWatcherPhase phase,
224
215
}
225
216
226
217
#ifdef ENABLE_KEYBOARD
218
+ std::string InstancePrivate::getLocale () {
219
+ const char *const variableList[] = {" LC_ALL" , " LC_CTYPE" , " LANG" };
220
+ for (const char *variable : variableList) {
221
+ const auto locale = getEnvironment (variable);
222
+ if (locale.has_value ()) {
223
+ return locale.value ();
224
+ }
225
+ }
226
+
227
+ return " C" ;
228
+ }
229
+
227
230
xkb_keymap *InstancePrivate::keymap (const std::string &display,
228
231
const std::string &layout,
229
232
const std::string &variant) {
0 commit comments