teknoraver / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone

Blame SOURCES/0300-localed-check-for-partially-matching-converted-keyma.patch

84b277
From 6dd719fad5521a24f6278cf005c250c99292a762 Mon Sep 17 00:00:00 2001
84b277
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
84b277
Date: Wed, 3 Sep 2014 22:55:54 -0400
84b277
Subject: [PATCH] localed: check for partially matching converted keymaps
84b277
84b277
If a user specifies multiple X11 keymaps, with a (at least the first
84b277
one) nonempty variant, and we don't match the whole combo, use
84b277
a converted keymap which includes the variant in preference to
84b277
the default, variantless, keymap.
84b277
84b277
E.g.: We would convert X11 config "layout=fr variant=mac" to "fr-mac",
84b277
but "layout=fr,us variant=mac," to "fr", because we don't have a
84b277
converted keymap which would match "fr,us", and we don't have a legacy
84b277
mapping for "fr,us". This is unexpected, and if we cannot match both,
84b277
it is still better to match the primary mapping and use "fr-mac".
84b277
84b277
Conflicts:
84b277
        src/locale/localed.c
84b277
84b277
(cherry picked from commit 78bd12a05a9252cf573da28394b23e2b891cbba8)
84b277
84b277
Resolves: #1109145
84b277
---
84b277
 src/locale/localed.c | 36 ++++++++++++++++++++++++++++--------
84b277
 1 file changed, 28 insertions(+), 8 deletions(-)
84b277
84b277
diff --git a/src/locale/localed.c b/src/locale/localed.c
84b277
index 56900a6..592fab9 100644
84b277
--- a/src/locale/localed.c
84b277
+++ b/src/locale/localed.c
84b277
@@ -776,8 +776,10 @@ static int convert_vconsole_to_x11(DBusConnection *connection) {
84b277
                 int r;
84b277
 
84b277
                 r = write_data_x11();
84b277
-                if (r < 0)
84b277
+                if (r < 0) {
84b277
                         log_error("Failed to set X11 keyboard layout: %s", strerror(-r));
84b277
+                        return r;
84b277
+                }
84b277
 
84b277
                 log_info("Changed X11 keyboard layout to '%s' model '%s' variant '%s' options '%s'",
84b277
                          strempty(state.x11_layout),
84b277
@@ -807,14 +809,14 @@ static int convert_vconsole_to_x11(DBusConnection *connection) {
84b277
         return 0;
84b277
 }
84b277
 
84b277
-static int find_converted_keymap(char **new_keymap) {
84b277
+static int find_converted_keymap(const char *x11_layout, const char *x11_variant, char **new_keymap) {
84b277
         const char *dir;
84b277
         _cleanup_free_ char *n;
84b277
 
84b277
-        if (state.x11_variant)
84b277
-                n = strjoin(state.x11_layout, "-", state.x11_variant, NULL);
84b277
+        if (x11_variant)
84b277
+                n = strjoin(x11_layout, "-", x11_variant, NULL);
84b277
         else
84b277
-                n = strdup(state.x11_layout);
84b277
+                n = strdup(x11_layout);
84b277
         if (!n)
84b277
                 return -ENOMEM;
84b277
 
84b277
@@ -845,7 +847,7 @@ static int find_legacy_keymap(char **new_keymap) {
84b277
         _cleanup_fclose_ FILE *f;
84b277
         unsigned n = 0;
84b277
         unsigned best_matching = 0;
84b277
-
84b277
+        int r;
84b277
 
84b277
         f = fopen(SYSTEMD_KBD_MODEL_MAP, "re");
84b277
         if (!f)
84b277
@@ -854,7 +856,6 @@ static int find_legacy_keymap(char **new_keymap) {
84b277
         for (;;) {
84b277
                 _cleanup_strv_free_ char **a = NULL;
84b277
                 unsigned matching = 0;
84b277
-                int r;
84b277
 
84b277
                 r = read_next_mapping(f, &n, &a);
84b277
                 if (r < 0)
84b277
@@ -913,6 +914,25 @@ static int find_legacy_keymap(char **new_keymap) {
84b277
                 }
84b277
         }
84b277
 
84b277
+        if (best_matching < 10 && state.x11_layout) {
84b277
+                /* The best match is only the first part of the X11
84b277
+                 * keymap. Check if we have a converted map which
84b277
+                 * matches just the first layout.
84b277
+                 */
84b277
+                char *l, *v = NULL, *converted;
84b277
+
84b277
+                l = strndupa(state.x11_layout, strcspn(state.x11_layout, ","));
84b277
+                if (state.x11_variant)
84b277
+                        v = strndupa(state.x11_variant, strcspn(state.x11_variant, ","));
84b277
+                r = find_converted_keymap(l, v, &converted);
84b277
+                if (r < 0)
84b277
+                        return r;
84b277
+                if (r > 0) {
84b277
+                        free(*new_keymap);
84b277
+                        *new_keymap = converted;
84b277
+                }
84b277
+        }
84b277
+
84b277
         return 0;
84b277
 }
84b277
 
84b277
@@ -932,7 +952,7 @@ static int convert_x11_to_vconsole(DBusConnection *connection) {
84b277
         } else {
84b277
                 char *new_keymap = NULL;
84b277
 
84b277
-                r = find_converted_keymap(&new_keymap);
84b277
+                r = find_converted_keymap(state.x11_layout, state.x11_variant, &new_keymap);
84b277
                 if (r < 0)
84b277
                         return r;
84b277
                 else if (r == 0) {