event_filter: allow remapping of KEY_UNKNOWN

KEY_UNKNOWN is a collective symbols for all unknown keycodes.
Remapping thus requires iterating through all corresponding codes
instead of only applying the policy to the first match.

Issue genodelabs#4069
This commit is contained in:
Johannes Schlatow 2021-04-08 16:37:44 +02:00 committed by Norman Feske
parent f6aabfe233
commit e86387d557
2 changed files with 25 additions and 7 deletions

View File

@ -36,6 +36,24 @@ namespace Event_filter {
} }
throw Unknown_key(); throw Unknown_key();
} }
/*
* \throw Unknown_key
*/
template<typename FN>
void for_each_key_with_name(Key_name const &name, FN const &fn)
{
bool found = false;
for (unsigned i = 0; i < Input::KEY_MAX; i++) {
Input::Keycode const code = Input::Keycode(i);
if (name == Input::key_name(code)) {
fn(code);
found = true;
}
}
if (!found)
throw Unknown_key();
}
} }
#endif /* _EVENT_FILTER__KEY_CODE_BY_NAME_H_ */ #endif /* _EVENT_FILTER__KEY_CODE_BY_NAME_H_ */

View File

@ -106,13 +106,13 @@ class Event_filter::Remap_source : public Source, Source::Filter
Key_name const key_name = node.attribute_value("name", Key_name()); Key_name const key_name = node.attribute_value("name", Key_name());
try { try {
Input::Keycode const code = key_code_by_name(key_name); for_each_key_with_name(key_name, [&] (Input::Keycode code) {
if (node.has_attribute("to")) { if (node.has_attribute("to")) {
Key_name const to = node.attribute_value("to", Key_name()); Key_name const to = node.attribute_value("to", Key_name());
try { _keys[code].code = key_code_by_name(to); } try { _keys[code].code = key_code_by_name(to); }
catch (Unknown_key) { warning("ignoring remap rule ", node); } catch (Unknown_key) { warning("ignoring remap rule ", node); }
} }
});
} }
catch (Unknown_key) { catch (Unknown_key) {
warning("invalid key name ", key_name); } warning("invalid key name ", key_name); }