int vconsole_convert_to_x11(Context *c) { const char *map; int modified = -1; map = systemd_kbd_model_map(); if (isempty(c->vc_keymap)) { modified = !isempty(c->x11_layout) || !isempty(c->x11_model) || !isempty(c->x11_variant) || !isempty(c->x11_options); context_free_x11(c); } else { _cleanup_fclose_ FILE *f = NULL; unsigned n = 0; f = fopen(map, "re"); if (!f) return -errno; for (;;) { _cleanup_strv_free_ char **a = NULL; int r; r = read_next_mapping(map, 5, UINT_MAX, f, &n, &a); if (r < 0) return r; if (r == 0) break; if (!streq(c->vc_keymap, a[0])) continue; if (!streq_ptr(c->x11_layout, strnulldash(a[1])) || !streq_ptr(c->x11_model, strnulldash(a[2])) || !streq_ptr(c->x11_variant, strnulldash(a[3])) || !streq_ptr(c->x11_options, strnulldash(a[4]))) { if (free_and_strdup(&c->x11_layout, strnulldash(a[1])) < 0 || free_and_strdup(&c->x11_model, strnulldash(a[2])) < 0 || free_and_strdup(&c->x11_variant, strnulldash(a[3])) < 0 || free_and_strdup(&c->x11_options, strnulldash(a[4])) < 0) return -ENOMEM; modified = true; } break; } } if (modified > 0) log_info("Changing X11 keyboard layout to '%s' model '%s' variant '%s' options '%s'", strempty(c->x11_layout), strempty(c->x11_model), strempty(c->x11_variant), strempty(c->x11_options)); else if (modified < 0) log_notice("X11 keyboard layout was not modified: no conversion found for \"%s\".", c->vc_keymap); else log_debug("X11 keyboard layout did not need to be modified."); return modified > 0; }
static int vconsole_convert_to_x11(Context *c, sd_bus *bus) { bool modified = false; assert(bus); if (isempty(c->vc_keymap)) { modified = !isempty(c->x11_layout) || !isempty(c->x11_model) || !isempty(c->x11_variant) || !isempty(c->x11_options); context_free_x11(c); } else { _cleanup_fclose_ FILE *f = NULL; unsigned n = 0; f = fopen(SYSTEMD_KBD_MODEL_MAP, "re"); if (!f) return -errno; for (;;) { _cleanup_strv_free_ char **a = NULL; int r; r = read_next_mapping(f, &n, &a); if (r < 0) return r; if (r == 0) break; if (!streq(c->vc_keymap, a[0])) continue; if (!streq_ptr(c->x11_layout, strnulldash(a[1])) || !streq_ptr(c->x11_model, strnulldash(a[2])) || !streq_ptr(c->x11_variant, strnulldash(a[3])) || !streq_ptr(c->x11_options, strnulldash(a[4]))) { if (free_and_strdup(&c->x11_layout, strnulldash(a[1])) < 0 || free_and_strdup(&c->x11_model, strnulldash(a[2])) < 0 || free_and_strdup(&c->x11_variant, strnulldash(a[3])) < 0 || free_and_strdup(&c->x11_options, strnulldash(a[4])) < 0) return -ENOMEM; modified = true; } break; } } if (modified) { int r; r = x11_write_data(c); if (r < 0) return log_error_errno(r, "Failed to set X11 keyboard layout: %m"); log_info("Changed X11 keyboard layout to '%s' model '%s' variant '%s' options '%s'", strempty(c->x11_layout), strempty(c->x11_model), strempty(c->x11_variant), strempty(c->x11_options)); sd_bus_emit_properties_changed(bus, "/org/freedesktop/locale1", "org.freedesktop.locale1", "X11Layout", "X11Model", "X11Variant", "X11Options", NULL); } else log_debug("X11 keyboard layout was not modified."); return 0; }
static int convert_vconsole_to_x11(DBusConnection *connection) { bool modified = false; assert(connection); if (isempty(state.vc_keymap)) { modified = !isempty(state.x11_layout) || !isempty(state.x11_model) || !isempty(state.x11_variant) || !isempty(state.x11_options); free_data_x11(); } else { FILE *f; unsigned n = 0; f = fopen(SYSTEMD_KBD_MODEL_MAP, "re"); if (!f) return -errno; for (;;) { char **a; int r; r = read_next_mapping(f, &n, &a); if (r < 0) { fclose(f); return r; } if (r == 0) break; if (!streq(state.vc_keymap, a[0])) { strv_free(a); continue; } if (!streq_ptr(state.x11_layout, strnulldash(a[1])) || !streq_ptr(state.x11_model, strnulldash(a[2])) || !streq_ptr(state.x11_variant, strnulldash(a[3])) || !streq_ptr(state.x11_options, strnulldash(a[4]))) { if (free_and_set(&state.x11_layout, strnulldash(a[1])) < 0 || free_and_set(&state.x11_model, strnulldash(a[2])) < 0 || free_and_set(&state.x11_variant, strnulldash(a[3])) < 0 || free_and_set(&state.x11_options, strnulldash(a[4])) < 0) { strv_free(a); fclose(f); return -ENOMEM; } modified = true; } strv_free(a); break; } fclose(f); } if (modified) { dbus_bool_t b; DBusMessage *changed; int r; r = write_data_x11(); if (r < 0) log_error("Failed to set X11 keyboard layout: %s", strerror(-r)); changed = bus_properties_changed_new( "/org/freedesktop/locale1", "org.freedesktop.locale1", "X11Layout\0" "X11Model\0" "X11Variant\0" "X11Options\0"); if (!changed) return -ENOMEM; b = dbus_connection_send(connection, changed, NULL); dbus_message_unref(changed); if (!b) return -ENOMEM; } return 0; }