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 | bool Xkb::stringIsEmptyOrNull(const char *str) | ||||
144 | { | ||||
145 | return str == nullptr || str[0] == '\0'; | ||||
146 | } | ||||
147 | | ||||
148 | void Xkb::applyEnvironmentRules(xkb_rule_names &ruleNames) | ||||
149 | { | ||||
150 | if (stringIsEmptyOrNull(ruleNames.rules)) { | ||||
151 | ruleNames.rules = getenv("XKB_DEFAULT_RULES"); | ||||
152 | } | ||||
153 | | ||||
154 | if (stringIsEmptyOrNull(ruleNames.model)) { | ||||
155 | ruleNames.model = getenv("XKB_DEFAULT_MODEL"); | ||||
156 | } | ||||
157 | | ||||
158 | if (stringIsEmptyOrNull(ruleNames.layout)) { | ||||
159 | ruleNames.layout = getenv("XKB_DEFAULT_LAYOUT"); | ||||
160 | ruleNames.variant = getenv("XKB_DEFAULT_VARIANT"); | ||||
161 | } | ||||
162 | | ||||
163 | if (ruleNames.options == nullptr) { | ||||
164 | ruleNames.options = getenv("XKB_DEFAULT_OPTIONS"); | ||||
165 | } | ||||
166 | } | ||||
167 | | ||||
143 | xkb_keymap *Xkb::loadKeymapFromConfig() | 168 | xkb_keymap *Xkb::loadKeymapFromConfig() | ||
144 | { | 169 | { | ||
145 | // load config | 170 | // load config | ||
146 | if (!m_config) { | 171 | if (!m_config) { | ||
147 | return nullptr; | 172 | return nullptr; | ||
148 | } | 173 | } | ||
149 | const KConfigGroup config = m_config->group("Layout"); | 174 | const KConfigGroup config = m_config->group("Layout"); | ||
150 | const QByteArray model = config.readEntry("Model", "pc104").toLocal8Bit(); | 175 | const QByteArray model = config.readEntry("Model", "pc104").toLocal8Bit(); | ||
151 | const QByteArray layout = config.readEntry("LayoutList", "").toLocal8Bit(); | 176 | const QByteArray layout = config.readEntry("LayoutList", "").toLocal8Bit(); | ||
152 | const QByteArray options = config.readEntry("Options", "").toLocal8Bit(); | 177 | const QByteArray options = config.readEntry("Options", "").toLocal8Bit(); | ||
153 | 178 | | |||
154 | xkb_rule_names ruleNames = { | 179 | xkb_rule_names ruleNames = { | ||
155 | .rules = nullptr, | 180 | .rules = nullptr, | ||
156 | .model = model.constData(), | 181 | .model = model.constData(), | ||
157 | .layout = layout.constData(), | 182 | .layout = layout.constData(), | ||
158 | .variant = nullptr, | 183 | .variant = nullptr, | ||
159 | .options = options.constData() | 184 | .options = options.constData() | ||
160 | }; | 185 | }; | ||
186 | applyEnvironmentRules(ruleNames); | ||||
161 | return xkb_keymap_new_from_names(m_context, &ruleNames, XKB_KEYMAP_COMPILE_NO_FLAGS); | 187 | return xkb_keymap_new_from_names(m_context, &ruleNames, XKB_KEYMAP_COMPILE_NO_FLAGS); | ||
162 | } | 188 | } | ||
163 | 189 | | |||
164 | xkb_keymap *Xkb::loadDefaultKeymap() | 190 | xkb_keymap *Xkb::loadDefaultKeymap() | ||
165 | { | 191 | { | ||
166 | return xkb_keymap_new_from_names(m_context, nullptr, XKB_KEYMAP_COMPILE_NO_FLAGS); | 192 | xkb_rule_names ruleNames = {}; | ||
193 | applyEnvironmentRules(ruleNames); | ||||
194 | return xkb_keymap_new_from_names(m_context, &ruleNames, XKB_KEYMAP_COMPILE_NO_FLAGS); | ||||
167 | } | 195 | } | ||
168 | 196 | | |||
169 | void Xkb::installKeymap(int fd, uint32_t size) | 197 | void Xkb::installKeymap(int fd, uint32_t size) | ||
170 | { | 198 | { | ||
171 | if (!m_context) { | 199 | if (!m_context) { | ||
172 | return; | 200 | return; | ||
173 | } | 201 | } | ||
174 | char *map = reinterpret_cast<char*>(mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0)); | 202 | 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 |