summaryrefslogtreecommitdiff
path: root/src/locale
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2023-01-26 17:41:47 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2023-01-28 14:53:18 +0900
commit71fa933b46fa1160e4c4eb037e5e9cec9c05c082 (patch)
tree6a75bec29a8904d4017721613f0a3929a744cb16 /src/locale
parent800f65f827c9828d4c872d44b19ca8a008505690 (diff)
downloadsystemd-71fa933b46fa1160e4c4eb037e5e9cec9c05c082.tar.gz
locale: sync two X11 contexts on update
Diffstat (limited to 'src/locale')
-rw-r--r--src/locale/localed-util.c13
-rw-r--r--src/locale/localed.c59
2 files changed, 38 insertions, 34 deletions
diff --git a/src/locale/localed-util.c b/src/locale/localed-util.c
index 87e232e08f..2d5d76e741 100644
--- a/src/locale/localed-util.c
+++ b/src/locale/localed-util.c
@@ -329,11 +329,6 @@ int x11_read_data(Context *c, sd_bus_message *m) {
if (r < 0)
return r;
- if (!x11_context_isempty(&c->x11_from_vc)) {
- log_debug("XKB settings loaded from vconsole.conf, not reading xorg.conf.d/00-keyboard.conf.");
- return 0;
- }
-
/* Do not try to re-read the file within single bus operation. */
if (m) {
if (m == c->x11_cache)
@@ -423,9 +418,6 @@ int x11_read_data(Context *c, sd_bus_message *m) {
in_section = false;
}
- if (!x11_context_isempty(&c->x11_from_xorg))
- log_debug("XKB settings loaded from xorg.conf.d/00-keyboard.conf.");
-
return 0;
}
@@ -438,11 +430,6 @@ int vconsole_write_data(Context *c) {
xc = context_get_x11_context(c);
- /* If the X11 context is from xorg.conf, then sync one from vconsole.conf with it. */
- r = x11_context_copy(&c->x11_from_vc, xc);
- if (r < 0)
- return r;
-
r = load_env_file(NULL, "/etc/vconsole.conf", &l);
if (r < 0 && r != -ENOENT)
return r;
diff --git a/src/locale/localed.c b/src/locale/localed.c
index 88f5604f1e..9070610b80 100644
--- a/src/locale/localed.c
+++ b/src/locale/localed.c
@@ -368,6 +368,7 @@ static int method_set_locale(sd_bus_message *m, void *userdata, sd_bus_error *er
static int method_set_vc_keyboard(sd_bus_message *m, void *userdata, sd_bus_error *error) {
Context *c = ASSERT_PTR(userdata);
int convert, interactive, r;
+ bool x_needs_update;
VCContext in;
assert(m);
@@ -415,15 +416,14 @@ static int method_set_vc_keyboard(sd_bus_message *m, void *userdata, sd_bus_erro
if (r < 0)
return log_oom();
+ r = x11_read_data(c, m);
+ if (r < 0) {
+ log_error_errno(r, "Failed to read X11 keyboard layout data: %m");
+ return sd_bus_error_set_errnof(error, r, "Failed to read X11 keyboard layout data: %m");
+ }
+
if (convert) {
_cleanup_(x11_context_clear) X11Context converted = {};
- X11Context *xc;
-
- r = x11_read_data(c, m);
- if (r < 0) {
- log_error_errno(r, "Failed to read X11 keyboard layout data: %m");
- return sd_bus_error_set_errnof(error, r, "Failed to read X11 keyboard layout data: %m");
- }
r = vconsole_convert_to_x11(&in, &converted);
if (r < 0) {
@@ -431,17 +431,32 @@ static int method_set_vc_keyboard(sd_bus_message *m, void *userdata, sd_bus_erro
return sd_bus_error_set_errnof(error, r, "Failed to convert keymap data: %m");
}
- /* save the result of conversion to emit changed properties later. */
- xc = context_get_x11_context(c);
- convert = !x11_context_equal(xc, &converted);
- x11_context_replace(xc, &converted);
+ x_needs_update = !x11_context_equal(&c->x11_from_vc, &converted) || !x11_context_equal(&c->x11_from_xorg, &converted);
+
+ r = x11_context_copy(&c->x11_from_vc, &converted);
+ if (r < 0)
+ return log_oom();
+ x11_context_replace(&c->x11_from_xorg, &converted);
+ } else {
+ const X11Context *xc = context_get_x11_context(c);
+
+ /* Even if the conversion is not requested, sync the two X11 contexts. */
+ x_needs_update = !x11_context_equal(&c->x11_from_vc, &c->x11_from_xorg);
+
+ r = x11_context_copy(&c->x11_from_vc, xc);
+ if (r < 0)
+ return log_oom();
+
+ r = x11_context_copy(&c->x11_from_xorg, xc);
+ if (r < 0)
+ return log_oom();
}
r = vconsole_write_data(c);
if (r < 0)
log_warning_errno(r, "Failed to write virtual console keymap, ignoring: %m");
- if (convert) {
+ if (x_needs_update) {
r = x11_write_data(c);
if (r < 0)
log_warning_errno(r, "Failed to write X11 keyboard layout, ignoring: %m");
@@ -457,10 +472,10 @@ static int method_set_vc_keyboard(sd_bus_message *m, void *userdata, sd_bus_erro
"/org/freedesktop/locale1",
"org.freedesktop.locale1",
"VConsoleKeymap", "VConsoleKeymapToggle",
- convert ? "X11Layout" : NULL,
- convert ? "X11Model" : NULL,
- convert ? "X11Variant" : NULL,
- convert ? "X11Options" : NULL,
+ x_needs_update ? "X11Layout" : NULL,
+ x_needs_update ? "X11Model" : NULL,
+ x_needs_update ? "X11Variant" : NULL,
+ x_needs_update ? "X11Options" : NULL,
NULL);
return sd_bus_reply_method_return(m, NULL);
@@ -570,7 +585,7 @@ static int verify_xkb_rmlvo(const char *model, const char *layout, const char *v
static int method_set_x11_keyboard(sd_bus_message *m, void *userdata, sd_bus_error *error) {
Context *c = ASSERT_PTR(userdata);
int convert, interactive, r;
- X11Context *xc, in;
+ X11Context in;
assert(m);
@@ -600,9 +615,7 @@ static int method_set_x11_keyboard(sd_bus_message *m, void *userdata, sd_bus_err
return sd_bus_error_set(error, SD_BUS_ERROR_FAILED, "Failed to read x11 keyboard layout data");
}
- xc = context_get_x11_context(c);
-
- if (x11_context_equal(xc, &in))
+ if (x11_context_equal(&c->x11_from_vc, &in) && x11_context_equal(&c->x11_from_xorg, &in))
return sd_bus_reply_method_return(m, NULL);
r = bus_verify_polkit_async(
@@ -619,7 +632,11 @@ static int method_set_x11_keyboard(sd_bus_message *m, void *userdata, sd_bus_err
if (r == 0)
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
- r = x11_context_copy(xc, &in);
+ r = x11_context_copy(&c->x11_from_vc, &in);
+ if (r < 0)
+ return log_oom();
+
+ r = x11_context_copy(&c->x11_from_xorg, &in);
if (r < 0)
return log_oom();