event_filter: add <ignore-key> node

Fixes genodelabs#4069
This commit is contained in:
Johannes Schlatow 2021-04-08 16:37:32 +02:00 committed by Norman Feske
parent e86387d557
commit c802de2cf9
2 changed files with 27 additions and 3 deletions

View File

@ -27,6 +27,10 @@ one of the following filters:
the key name as 'name' attribute, may feature an optional 'to' attribute
with the name of the key that should be reported instead of 'name'.
It may also contain any number of '<ignore-key>' nodes to completely mute
certain keys. Each of those nodes has the key name as 'name' attribute.
This rule is applied before remapping.
A '<remap>' node may contain '<include>' nodes, which include further
content into the '<remap>' node. The included ROM must have a '<remap>'
top-level node.

View File

@ -37,6 +37,7 @@ class Event_filter::Remap_source : public Source, Source::Filter
};
Key _keys[Input::KEY_MAX];
bool _ignore_keys[Input::KEY_MAX] { };
Owner _owner;
@ -61,13 +62,16 @@ class Event_filter::Remap_source : public Source, Source::Filter
* The range of the 'key' is checked by the 'Event' handle methods,
* so it is safe to use as array index.
*/
auto remap = [&] (Input::Keycode key) { return _keys[key].code; };
auto remap = [&] (Input::Keycode key) { return _keys[key].code; };
auto ignore = [&] (Input::Keycode key) { return _ignore_keys[key]; };
event.handle_press([&] (Input::Keycode key, Codepoint codepoint) {
destination.submit(Input::Press_char{remap(key), codepoint}); });
if (!ignore(key))
destination.submit(Input::Press_char{remap(key), codepoint}); });
event.handle_release([&] (Input::Keycode key) {
destination.submit(Input::Release{remap(key)}); });
if (!ignore(key))
destination.submit(Input::Release{remap(key)}); });
}
void _apply_config(Xml_node const config, unsigned const max_recursion = 4)
@ -118,6 +122,22 @@ class Event_filter::Remap_source : public Source, Source::Filter
warning("invalid key name ", key_name); }
return;
}
/*
* Handle ignore-key nodes
*/
if (node.type() == "ignore-key") {
Key_name const key_name = node.attribute_value("name", Key_name());
try {
for_each_key_with_name(key_name, [&] (Input::Keycode code) {
_ignore_keys[code] = true;
});
}
catch (Unknown_key) {
warning("invalid key name ", key_name); }
return;
}
}
public: