Changeset View
Changeset View
Standalone View
Standalone View
xkb.cpp
Show First 20 Lines • Show All 134 Lines • ▼ Show 20 Line(s) | 123 | { | |||
---|---|---|---|---|---|
135 | } | 135 | } | ||
136 | if (keymap) { | 136 | if (keymap) { | ||
137 | updateKeymap(keymap); | 137 | updateKeymap(keymap); | ||
138 | } else { | 138 | } else { | ||
139 | qCDebug(KWIN_XKB) << "Could not create default xkb keymap"; | 139 | qCDebug(KWIN_XKB) << "Could not create default xkb keymap"; | ||
140 | } | 140 | } | ||
141 | } | 141 | } | ||
142 | 142 | | |||
143 | static bool stringIsEmptyOrNull(const char *str) | ||||
144 | { | ||||
145 | return str == nullptr || str[0] == '\0'; | ||||
146 | } | ||||
147 | | ||||
148 | /** | ||||
149 | * libxkbcommon uses secure_getenv to read the XKB_DEFAULT_* variables. | ||||
150 | * As kwin_wayland may have the CAP_SET_NICE capability, it returns nullptr | ||||
151 | * so we need to do it ourselves (see xkb_context_sanitize_rule_names). | ||||
152 | **/ | ||||
153 | static void applyEnvironmentRules(xkb_rule_names &ruleNames) | ||||
154 | { | ||||
155 | if (stringIsEmptyOrNull(ruleNames.rules)) { | ||||
156 | ruleNames.rules = getenv("XKB_DEFAULT_RULES"); | ||||
157 | } | ||||
158 | | ||||
159 | if (stringIsEmptyOrNull(ruleNames.model)) { | ||||
160 | ruleNames.model = getenv("XKB_DEFAULT_MODEL"); | ||||
161 | } | ||||
162 | | ||||
163 | if (stringIsEmptyOrNull(ruleNames.layout)) { | ||||
164 | ruleNames.layout = getenv("XKB_DEFAULT_LAYOUT"); | ||||
165 | ruleNames.variant = getenv("XKB_DEFAULT_VARIANT"); | ||||
166 | } | ||||
167 | | ||||
168 | if (ruleNames.options == nullptr) { | ||||
169 | ruleNames.options = getenv("XKB_DEFAULT_OPTIONS"); | ||||
170 | } | ||||
171 | } | ||||
172 | | ||||
143 | xkb_keymap *Xkb::loadKeymapFromConfig() | 173 | xkb_keymap *Xkb::loadKeymapFromConfig() | ||
144 | { | 174 | { | ||
145 | // load config | 175 | // load config | ||
146 | if (!m_config) { | 176 | if (!m_config) { | ||
147 | return nullptr; | 177 | return nullptr; | ||
148 | } | 178 | } | ||
149 | const KConfigGroup config = m_config->group("Layout"); | 179 | const KConfigGroup config = m_config->group("Layout"); | ||
150 | const QByteArray model = config.readEntry("Model", "pc104").toLocal8Bit(); | 180 | const QByteArray model = config.readEntry("Model", "pc104").toLocal8Bit(); | ||
151 | const QByteArray layout = config.readEntry("LayoutList", "").toLocal8Bit(); | 181 | const QByteArray layout = config.readEntry("LayoutList", "").toLocal8Bit(); | ||
152 | const QByteArray options = config.readEntry("Options", "").toLocal8Bit(); | 182 | const QByteArray options = config.readEntry("Options", "").toLocal8Bit(); | ||
153 | 183 | | |||
154 | xkb_rule_names ruleNames = { | 184 | xkb_rule_names ruleNames = { | ||
155 | .rules = nullptr, | 185 | .rules = nullptr, | ||
156 | .model = model.constData(), | 186 | .model = model.constData(), | ||
157 | .layout = layout.constData(), | 187 | .layout = layout.constData(), | ||
158 | .variant = nullptr, | 188 | .variant = nullptr, | ||
159 | .options = options.constData() | 189 | .options = options.constData() | ||
160 | }; | 190 | }; | ||
191 | applyEnvironmentRules(ruleNames); | ||||
161 | return xkb_keymap_new_from_names(m_context, &ruleNames, XKB_KEYMAP_COMPILE_NO_FLAGS); | 192 | return xkb_keymap_new_from_names(m_context, &ruleNames, XKB_KEYMAP_COMPILE_NO_FLAGS); | ||
162 | } | 193 | } | ||
163 | 194 | | |||
164 | xkb_keymap *Xkb::loadDefaultKeymap() | 195 | xkb_keymap *Xkb::loadDefaultKeymap() | ||
165 | { | 196 | { | ||
166 | return xkb_keymap_new_from_names(m_context, nullptr, XKB_KEYMAP_COMPILE_NO_FLAGS); | 197 | xkb_rule_names ruleNames = {}; | ||
198 | applyEnvironmentRules(ruleNames); | ||||
199 | return xkb_keymap_new_from_names(m_context, &ruleNames, XKB_KEYMAP_COMPILE_NO_FLAGS); | ||||
167 | } | 200 | } | ||
168 | 201 | | |||
169 | void Xkb::installKeymap(int fd, uint32_t size) | 202 | void Xkb::installKeymap(int fd, uint32_t size) | ||
170 | { | 203 | { | ||
171 | if (!m_context) { | 204 | if (!m_context) { | ||
172 | return; | 205 | return; | ||
173 | } | 206 | } | ||
174 | char *map = reinterpret_cast<char*>(mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0)); | 207 | char *map = reinterpret_cast<char*>(mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0)); | ||
▲ Show 20 Lines • Show All 346 Lines • Show Last 20 Lines |