Commit e6cc0b1f authored by Fabian Vogt's avatar Fabian Vogt
Browse files

[kcms/keyboard] Avoid serializing list options as \\0

VariantList, DisplayNames and Options are comma-delimited string lists in a
setxkbmap/libxkbcommon compatible format, but serializing a QStringList with
a single empty string ends up as "\\0" in the config file, which is not
compatible. This can't happen for LayoutList, because layout strings are never
empty.

Add a kconf_update script to convert \\0 into empty lists for the affected
entries.

This restores the old format for compatibility with e.g. KWin.

BUG: 433265
parent e7c4bb17
......@@ -593,11 +593,20 @@ void KCMKeyboardWidget::configureXkbOptionsChanged()
void KCMKeyboardWidget::saveXkbOptions()
{
if (uiWidget->configureKeyboardOptionsChk->isChecked()) {
keyboardConfig->setXkbOptions(xkbOptionsFromUI());
} else {
keyboardConfig->setXkbOptions(QStringList());
QStringList options;
if(uiWidget->configureKeyboardOptionsChk->isChecked()) {
options = xkbOptionsFromUI();
// QStringLists with a single empty string are serialized as "\\0", avoid that
// by saving them as an empty list instead. This way it can be passed as-is to
// libxkbcommon/setxkbmap. Before KConfigXT it used QStringList::join(",").
if (options.size() == 1 && options.constFirst().isEmpty()) {
options.clear();
}
}
keyboardConfig->setXkbOptions(options);
}
QStringList KCMKeyboardWidget::xkbOptionsFromUI() const
......
......@@ -2,3 +2,7 @@ install(FILES kxkb_variants.upd
DESTINATION ${KDE_INSTALL_KCONFUPDATEDIR})
install(PROGRAMS kxkb_variants.awk
DESTINATION ${KDE_INSTALL_KCONFUPDATEDIR})
install(FILES kxkb.upd
DESTINATION ${KDE_INSTALL_KCONFUPDATEDIR})
install(PROGRAMS kxkb_emptylists.awk
DESTINATION ${KDE_INSTALL_KCONFUPDATEDIR})
Version=5
# After the KConfigXT port, DisplayNames/VariantList and Options could end up
# being serialized as "\\0" (single empty element) instead of an empty string.
Id=remove-empty-lists
File=kxkbrc
Group=Layout
Script=kxkb_emptylists.awk
#! /usr/bin/awk -f
# - Input:
# DisplayNames=\\0
# VariantList=\\0
# Options=\\0
#
# - Output:
# # DELETE DisplayNames
# # DELETE VariantList
# # DELETE Options
BEGIN { FS = "=" }
$2 == "\\\\0" && ($1 == "DisplayNames" || $1 == "VariantList" || $1 == "Options") {
print "# DELETE", $1;
}
......@@ -122,6 +122,16 @@ void KeyboardConfig::save()
displayNames.append(layoutUnit.getRawDisplayName());
}
// QStringLists with a single empty string are serialized as "\\0", avoid that
// by saving them as an empty list instead. This way it can be passed as-is to
// libxkbcommon/setxkbmap. Before KConfigXT it used QStringList::join(",").
if (variants.size() == 1 && variants.constFirst().isEmpty()) {
variants.clear();
}
if (displayNames.size() == 1 && displayNames.constFirst().isEmpty()) {
displayNames.clear();
}
setLayoutList(layoutList);
setVariantList(variants);
setDisplayNames(displayNames);
......
......@@ -10,6 +10,10 @@ SPDX-License-Identifier: GPL-2.0-or-later
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile name="kxkbrc" />
<group name="Layout">
<!-- Note: LayoutList/VariantList/Options are meant to be in
a setxkbmap/libxkbcommon-compatible format. This means that
they must not be set to a list with a single empty string,
which gets serialized as "\\0" by KConfig. -->
<entry name="layoutList" key="LayoutList" type="StringList">
<default code="true">QStringList()</default>
</entry>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment