mirror of
https://github.com/systemd/systemd
synced 2024-10-07 00:30:59 +00:00
locale: when no xvariant match select the entry with an empty xvariant
When doing a conversion and the specified 'xc->xvariant' has no match, select the x11 layout entry with a matching layout and an empty xvariant if such entry exists. It's still better than no conversion at all.
This commit is contained in:
parent
c821ad7d60
commit
b35f71ac1a
|
@ -722,6 +722,11 @@ int vconsole_convert_to_x11(const VCContext *vc, X11Context *ret) {
|
||||||
/* This sanity check seems redundant with the verification of the X11 layout done on the next
|
/* This sanity check seems redundant with the verification of the X11 layout done on the next
|
||||||
* step. However xkbcommon is an optional dependency hence the verification might be a NOP. */
|
* step. However xkbcommon is an optional dependency hence the verification might be a NOP. */
|
||||||
r = find_converted_keymap(&xc, &converted);
|
r = find_converted_keymap(&xc, &converted);
|
||||||
|
if (r == 0 && xc.variant) {
|
||||||
|
/* If we still haven't find a match, try with no variant, it's still better than nothing. */
|
||||||
|
xc.variant = NULL;
|
||||||
|
r = find_converted_keymap(&xc, &converted);
|
||||||
|
}
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
@ -890,8 +895,17 @@ int x11_convert_to_vconsole(const X11Context *xc, VCContext *ret) {
|
||||||
}
|
}
|
||||||
|
|
||||||
r = find_converted_keymap(xc, &keymap);
|
r = find_converted_keymap(xc, &keymap);
|
||||||
if (r == 0)
|
if (r == 0) {
|
||||||
r = find_legacy_keymap(xc, &keymap);
|
r = find_legacy_keymap(xc, &keymap);
|
||||||
|
if (r == 0 && xc->variant)
|
||||||
|
/* If we still haven't find a match, try with no variant, it's still better than
|
||||||
|
* nothing. */
|
||||||
|
r = find_converted_keymap(
|
||||||
|
&(X11Context) {
|
||||||
|
.layout = xc->layout,
|
||||||
|
},
|
||||||
|
&keymap);
|
||||||
|
}
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,7 @@ TEST(find_converted_keymap) {
|
||||||
|
|
||||||
assert_se(r == 1);
|
assert_se(r == 1);
|
||||||
assert_se(streq(ans, "pl"));
|
assert_se(streq(ans, "pl"));
|
||||||
|
ans = mfree(ans);
|
||||||
|
|
||||||
assert_se(find_converted_keymap(
|
assert_se(find_converted_keymap(
|
||||||
&(X11Context) {
|
&(X11Context) {
|
||||||
|
@ -73,6 +74,7 @@ TEST(find_legacy_keymap) {
|
||||||
TEST(vconsole_convert_to_x11) {
|
TEST(vconsole_convert_to_x11) {
|
||||||
_cleanup_(x11_context_clear) X11Context xc = {};
|
_cleanup_(x11_context_clear) X11Context xc = {};
|
||||||
_cleanup_(vc_context_clear) VCContext vc = {};
|
_cleanup_(vc_context_clear) VCContext vc = {};
|
||||||
|
int r;
|
||||||
|
|
||||||
log_info("/* test empty keymap */");
|
log_info("/* test empty keymap */");
|
||||||
assert_se(vconsole_convert_to_x11(&vc, &xc) >= 0);
|
assert_se(vconsole_convert_to_x11(&vc, &xc) >= 0);
|
||||||
|
@ -111,6 +113,34 @@ TEST(vconsole_convert_to_x11) {
|
||||||
assert_se(vconsole_convert_to_x11(&vc, &xc) >= 0);
|
assert_se(vconsole_convert_to_x11(&vc, &xc) >= 0);
|
||||||
assert_se(streq(xc.layout, "us"));
|
assert_se(streq(xc.layout, "us"));
|
||||||
assert_se(xc.variant == NULL);
|
assert_se(xc.variant == NULL);
|
||||||
|
x11_context_clear(&xc);
|
||||||
|
|
||||||
|
/* "gh" has no mapping in kbd-model-map and kbd provides a converted keymap for this layout. */
|
||||||
|
log_info("/* test with a converted keymap (gh:) */");
|
||||||
|
assert_se(free_and_strdup(&vc.keymap, "gh") >= 0);
|
||||||
|
r = vconsole_convert_to_x11(&vc, &xc);
|
||||||
|
if (r == 0) {
|
||||||
|
log_info("Skipping rest of %s: keymaps are not installed", __func__);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
assert_se(r > 0);
|
||||||
|
assert_se(streq(xc.layout, "gh"));
|
||||||
|
assert_se(xc.variant == NULL);
|
||||||
|
x11_context_clear(&xc);
|
||||||
|
|
||||||
|
log_info("/* test with converted keymap and with a known variant (gh:ewe) */");
|
||||||
|
assert_se(free_and_strdup(&vc.keymap, "gh-ewe") >= 0);
|
||||||
|
assert_se(vconsole_convert_to_x11(&vc, &xc) > 0);
|
||||||
|
assert_se(streq(xc.layout, "gh"));
|
||||||
|
assert_se(streq(xc.variant, "ewe"));
|
||||||
|
x11_context_clear(&xc);
|
||||||
|
|
||||||
|
log_info("/* test with converted keymap and with an unknown variant (gh:ewe) */");
|
||||||
|
assert_se(free_and_strdup(&vc.keymap, "gh-foobar") > 0);
|
||||||
|
assert_se(vconsole_convert_to_x11(&vc, &xc) > 0);
|
||||||
|
assert_se(streq(xc.layout, "gh"));
|
||||||
|
assert_se(xc.variant == NULL);
|
||||||
|
x11_context_clear(&xc);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(x11_convert_to_vconsole) {
|
TEST(x11_convert_to_vconsole) {
|
||||||
|
|
|
@ -273,15 +273,15 @@ test_vc_keymap() {
|
||||||
assert_in "XKBVARIANT=intl" "$vc"
|
assert_in "XKBVARIANT=intl" "$vc"
|
||||||
assert_in "XKBOPTIONS=terminate:ctrl_alt_bksp" "$vc"
|
assert_in "XKBOPTIONS=terminate:ctrl_alt_bksp" "$vc"
|
||||||
elif [[ "$i" =~ ^us-.* ]]; then
|
elif [[ "$i" =~ ^us-.* ]]; then
|
||||||
assert_in "X11 Layout: .unset." "$output"
|
assert_in "X11 Layout: us" "$output"
|
||||||
assert_not_in "X11 Model:" "$output"
|
assert_in "X11 Model: microsoftpro" "$output"
|
||||||
assert_not_in "X11 Variant:" "$output"
|
assert_in "X11 Variant:" "$output"
|
||||||
assert_not_in "X11 Options:" "$output"
|
assert_in "X11 Options: terminate:ctrl_alt_bksp" "$output"
|
||||||
|
|
||||||
assert_not_in "XKBLAYOUT" "$vc"
|
assert_in "XKBLAYOUT=us" "$vc"
|
||||||
assert_not_in "XKBMODEL" "$vc"
|
assert_in "XKBMODEL=microsoftpro" "$vc"
|
||||||
assert_not_in "XKBVARIANT" "$vc"
|
assert_in "XKBVARIANT=" "$vc"
|
||||||
assert_not_in "XKBOPTIONS" "$vc"
|
assert_in "XKBOPTIONS=terminate:ctrl_alt_bksp" "$vc"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue