event_filter: <log motion="true"> attribute

Per default, only key presses and releases are logged. The optional
'motion' attribute (boolean) enables logging of motion and touch events.

Issue #5105
This commit is contained in:
Christian Helmuth 2024-01-29 14:50:39 +01:00
parent 17724c5f1c
commit 7304a019e7
3 changed files with 16 additions and 11 deletions

View File

@ -581,11 +581,11 @@ append qemu_args " -nographic "
run_genode_until {.*child "test-event_filter" exited with exit value 0.*} 60
grep_output {mapped event}
grep_output {mapped Input event}
unify_output {\t} { }
compare_output_to {
[init -> event_filter] Unremapped event #0 PRESS KEY_UNKNOWN 65534 key count: 1
[init -> event_filter] Remapped event #0 PRESS KEY_A 65534 key count: 1
[init -> event_filter] Unremapped event #1 RELEASE KEY_UNKNOWN key count: 0
[init -> event_filter] Remapped event #1 RELEASE KEY_A key count: 0
[init -> event_filter] Unremapped Input event #0 PRESS KEY_UNKNOWN 65534 key count: 1
[init -> event_filter] Remapped Input event #0 PRESS KEY_A 65534 key count: 1
[init -> event_filter] Unremapped Input event #1 RELEASE KEY_UNKNOWN key count: 0
[init -> event_filter] Remapped Input event #1 RELEASE KEY_A key count: 0
}

View File

@ -37,8 +37,10 @@ one of the following filters:
:<log>:
Logs debug information about key presses and releases to the component's 'Log'
session. An optional 'prefix' attribute can be provided in order to
Logs debug information about input events to the component's 'Log'
session. Per default, only key presses and releases are logged. The
optional 'motion' attribute (boolean) enables logging of motion and touch
events too. An optional 'prefix' attribute can be provided in order to
distinguish multiple '<log>' filters. The given prefix is placed at the
beginning of each log message.

View File

@ -33,6 +33,8 @@ class Event_filter::Log_source : public Source, Source::Filter
Prefix _prefix = "";
bool _motion = false;
Owner _owner;
Source &_source;
@ -40,17 +42,17 @@ class Event_filter::Log_source : public Source, Source::Filter
unsigned _event_cnt = 0;
int _key_cnt = 0;
/**
* Filter interface
*/
void filter_event(Source::Sink &destination, Input::Event const &event) override
{
/* only log presses and releases */
if (event.press() || event.release()) {
if (_motion || event.press() || event.release()) {
if (event.press()) ++_key_cnt;
if (event.release()) --_key_cnt;
log(_prefix, "event #", _event_cnt++, "\t", event, "\tkey count: ", _key_cnt);
log(_prefix, "Input event #", _event_cnt++, "\t", event, "\tkey count: ", _key_cnt);
}
/* forward event */
@ -59,7 +61,8 @@ class Event_filter::Log_source : public Source, Source::Filter
void _apply_config(Xml_node const config)
{
_prefix = config.attribute_value("prefix", _prefix);
_prefix = config.attribute_value("prefix", Prefix());
_motion = config.attribute_value("motion", false);
}
public: