Adam Williamson 18e1ed
From a30ae31351ffa701ca860779495d4f52db4c462c Mon Sep 17 00:00:00 2001
Adam Williamson 18e1ed
From: Adam Williamson <awilliam@redhat.com>
Adam Williamson 18e1ed
Date: Fri, 15 Sep 2023 15:35:36 -0700
Adam Williamson 18e1ed
Subject: [PATCH 1/2] find_legacy_keymap: fix empty variant matching
Adam Williamson 18e1ed
Adam Williamson 18e1ed
We should give a match bonus if the X context variant is empty
Adam Williamson 18e1ed
and the xvariant column in kbd-model-map is "-" (which means
Adam Williamson 18e1ed
none). Currently, we don't, which means that if you call this
Adam Williamson 18e1ed
on a context with layouts bg,us and no variant, you get the
Adam Williamson 18e1ed
console layout bg_pho-utf8 instead of bg_bds-utf8 (because both
Adam Williamson 18e1ed
score the same, and the bg_pho-utf8 row comes first). You should
Adam Williamson 18e1ed
get bg_bds-utf8 in this case.
Adam Williamson 18e1ed
Adam Williamson 18e1ed
Signed-off-by: Adam Williamson <awilliam@redhat.com>
Adam Williamson 18e1ed
---
Adam Williamson 18e1ed
 src/locale/localed-util.c      |  2 +-
Adam Williamson 18e1ed
 src/locale/test-localed-util.c | 12 ++++++++++++
Adam Williamson 18e1ed
 2 files changed, 13 insertions(+), 1 deletion(-)
Adam Williamson 18e1ed
Adam Williamson 18e1ed
diff --git a/src/locale/localed-util.c b/src/locale/localed-util.c
Adam Williamson 18e1ed
index 02fac9786b..6a05b50a31 100644
Adam Williamson 18e1ed
--- a/src/locale/localed-util.c
Adam Williamson 18e1ed
+++ b/src/locale/localed-util.c
Adam Williamson 18e1ed
@@ -825,7 +825,7 @@ int find_legacy_keymap(const X11Context *xc, char **ret) {
Adam Williamson 18e1ed
                         if (isempty(xc->model) || streq_ptr(xc->model, a[2])) {
Adam Williamson 18e1ed
                                 matching++;
Adam Williamson 18e1ed
 
Adam Williamson 18e1ed
-                                if (streq_ptr(xc->variant, a[3])) {
Adam Williamson 18e1ed
+                                if (streq_ptr(xc->variant, a[3]) || (isempty(xc->variant) && streq(a[3], "-"))) {
Adam Williamson 18e1ed
                                         matching++;
Adam Williamson 18e1ed
 
Adam Williamson 18e1ed
                                         if (streq_ptr(xc->options, a[4]))
Adam Williamson 18e1ed
diff --git a/src/locale/test-localed-util.c b/src/locale/test-localed-util.c
Adam Williamson 18e1ed
index cb66dffd48..a19d80a967 100644
Adam Williamson 18e1ed
--- a/src/locale/test-localed-util.c
Adam Williamson 18e1ed
+++ b/src/locale/test-localed-util.c
Adam Williamson 18e1ed
@@ -173,6 +173,18 @@ TEST(x11_convert_to_vconsole) {
Adam Williamson 18e1ed
         assert_se(streq(vc.keymap, "es-dvorak"));
Adam Williamson 18e1ed
         vc_context_clear(&vc);
Adam Williamson 18e1ed
 
Adam Williamson 18e1ed
+        /* es no-variant test is not very good as the desired match
Adam Williamson 18e1ed
+        comes first in the list so will win if both candidates score
Adam Williamson 18e1ed
+        the same. in this case the desired match comes second so will
Adam Williamson 18e1ed
+        not win unless we correctly give the no-variant match a bonus
Adam Williamson 18e1ed
+        */
Adam Williamson 18e1ed
+        log_info("/* test without variant, desired match second (bg,us:) */");
Adam Williamson 18e1ed
+        assert_se(free_and_strdup(&xc.layout, "bg,us") >= 0);
Adam Williamson 18e1ed
+        assert_se(free_and_strdup(&xc.variant, NULL) >= 0);
Adam Williamson 18e1ed
+        assert_se(x11_convert_to_vconsole(&xc, &vc) >= 0);
Adam Williamson 18e1ed
+        assert_se(streq(vc.keymap, "bg_bds-utf8"));
Adam Williamson 18e1ed
+        vc_context_clear(&vc);
Adam Williamson 18e1ed
+
Adam Williamson 18e1ed
         log_info("/* test with old mapping (fr:latin9) */");
Adam Williamson 18e1ed
         assert_se(free_and_strdup(&xc.layout, "fr") >= 0);
Adam Williamson 18e1ed
         assert_se(free_and_strdup(&xc.variant, "latin9") >= 0);
Adam Williamson 18e1ed
-- 
Adam Williamson 18e1ed
2.41.0
Adam Williamson 18e1ed