Commit eb69e872 authored by Fabian Vogt's avatar Fabian Vogt

Manually take XKB_DEFAULT_{RULES,MODEL,LAYOUT,VARIANT,OPTIONS} into account

Summary:
As kwin_wayland can have the CAP_SYS_NICE capability, libxkbcommon does not
read environment variables (see secure_getenv).
So process them here, in the same way xkb_context_sanitize_rule_names would.

BUG: 388249

Test Plan: kwin_wayland has the capability set, keyboard layout is applied correctly.

Reviewers: #plasma, graesslin

Subscribers: kwin, plasma-devel, #kwin

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D9873
parent 42b09935
......@@ -140,6 +140,36 @@ void Xkb::reconfigure()
}
}
static bool stringIsEmptyOrNull(const char *str)
{
return str == nullptr || str[0] == '\0';
}
/**
* libxkbcommon uses secure_getenv to read the XKB_DEFAULT_* variables.
* As kwin_wayland may have the CAP_SET_NICE capability, it returns nullptr
* so we need to do it ourselves (see xkb_context_sanitize_rule_names).
**/
static void applyEnvironmentRules(xkb_rule_names &ruleNames)
{
if (stringIsEmptyOrNull(ruleNames.rules)) {
ruleNames.rules = getenv("XKB_DEFAULT_RULES");
}
if (stringIsEmptyOrNull(ruleNames.model)) {
ruleNames.model = getenv("XKB_DEFAULT_MODEL");
}
if (stringIsEmptyOrNull(ruleNames.layout)) {
ruleNames.layout = getenv("XKB_DEFAULT_LAYOUT");
ruleNames.variant = getenv("XKB_DEFAULT_VARIANT");
}
if (ruleNames.options == nullptr) {
ruleNames.options = getenv("XKB_DEFAULT_OPTIONS");
}
}
xkb_keymap *Xkb::loadKeymapFromConfig()
{
// load config
......@@ -158,12 +188,15 @@ xkb_keymap *Xkb::loadKeymapFromConfig()
.variant = nullptr,
.options = options.constData()
};
applyEnvironmentRules(ruleNames);
return xkb_keymap_new_from_names(m_context, &ruleNames, XKB_KEYMAP_COMPILE_NO_FLAGS);
}
xkb_keymap *Xkb::loadDefaultKeymap()
{
return xkb_keymap_new_from_names(m_context, nullptr, XKB_KEYMAP_COMPILE_NO_FLAGS);
xkb_rule_names ruleNames = {};
applyEnvironmentRules(ruleNames);
return xkb_keymap_new_from_names(m_context, &ruleNames, XKB_KEYMAP_COMPILE_NO_FLAGS);
}
void Xkb::installKeymap(int fd, uint32_t size)
......
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