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
This commit is contained in:
parent
42b099355c
commit
eb69e87288
1 changed files with 34 additions and 1 deletions
35
xkb.cpp
35
xkb.cpp
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue