1
0
mirror of https://github.com/systemd/systemd.git synced 2025-02-14 05:57:40 +03:00

find_legacy_keymap: try matching with layout order reversed

The lines in kbd-model-map date back to ye olde times (RH's old
system-config-keyboard), and I think predate this bug:

https://bugzilla.redhat.com/show_bug.cgi?id=1039185

where we got strong feedback that, for 'switched' layout setups
like Russian, US English should be the *first* layout and the
native layout the *second* one. This is how anaconda and, as of
recently, gnome-initial-setup configure such cases - but that
means, if we try to use localed to convert these configurations
using kbd-model-map, we get the wrong result (we get "us" as the
console layout). See also:

https://bugzilla.redhat.com/show_bug.cgi?id=1912609

where we first noticed this wasn't working right, but sadly, we
'fixed' it with a not-really-correct bodge in anaconda instead
of doing it properly.

Signed-off-by: Adam Williamson <awilliam@redhat.com>
This commit is contained in:
Adam Williamson 2023-09-15 16:02:29 -07:00
parent bf09ab0184
commit a22567f54e
2 changed files with 32 additions and 15 deletions

View File

@ -803,21 +803,35 @@ int find_legacy_keymap(const X11Context *xc, char **ret) {
/* If we got an exact match, this is the best */
matching = 10;
else {
/* We have multiple X layouts, look for an
* entry that matches our key with everything
* but the first layout stripped off. */
if (startswith_comma(xc->layout, a[1]))
matching = 5;
/* see if we get an exact match with the order reversed */
_cleanup_strv_free_ char **b = NULL;
_cleanup_free_ char *c = NULL;
r = strv_split_full(&b, a[1], ",", 0);
if (r < 0)
return r;
strv_reverse(b);
c = strv_join(b, ",");
if (!c)
return log_oom();
if (streq(xc->layout, c))
matching = 9;
else {
_cleanup_free_ char *x = NULL;
/* We have multiple X layouts, look for an
* entry that matches our key with everything
* but the first layout stripped off. */
if (startswith_comma(xc->layout, a[1]))
matching = 5;
else {
_cleanup_free_ char *x = NULL;
/* If that didn't work, strip off the
* other layouts from the entry, too */
x = strdupcspn(a[1], ",");
if (!x)
return -ENOMEM;
if (startswith_comma(xc->layout, x))
matching = 1;
/* If that didn't work, strip off the
* other layouts from the entry, too */
x = strdupcspn(a[1], ",");
if (!x)
return -ENOMEM;
if (startswith_comma(xc->layout, x))
matching = 1;
}
}
}
@ -848,7 +862,7 @@ int find_legacy_keymap(const X11Context *xc, char **ret) {
}
}
if (best_matching < 10 && !isempty(xc->layout)) {
if (best_matching < 9 && !isempty(xc->layout)) {
_cleanup_free_ char *l = NULL, *v = NULL, *converted = NULL;
/* The best match is only the first part of the X11

View File

@ -192,11 +192,14 @@ TEST(x11_convert_to_vconsole) {
assert_se(streq(vc.keymap, "fr-latin9"));
vc_context_clear(&vc);
/* https://bugzilla.redhat.com/show_bug.cgi?id=1039185 */
/* us,ru is the x config users want, but they still want ru
as the console layout in this case */
log_info("/* test with a compound mapping (us,ru:) */");
assert_se(free_and_strdup(&xc.layout, "us,ru") >= 0);
assert_se(free_and_strdup(&xc.variant, NULL) >= 0);
assert_se(x11_convert_to_vconsole(&xc, &vc) >= 0);
assert_se(streq(vc.keymap, "us"));
assert_se(streq(vc.keymap, "ru"));
vc_context_clear(&vc);
log_info("/* test with a compound mapping (ru,us:) */");