mirror of
https://github.com/genodelabs/genode.git
synced 2025-04-12 05:41:36 +00:00
event_filter: add <ignore-key> node
Fixes genodelabs#4069
This commit is contained in:
parent
e86387d557
commit
c802de2cf9
@ -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.
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user