os: Input::Event:Axis event type

This event type can be used to propagate analog values such as joypads.

Issue #3669
This commit is contained in:
Norman Feske 2022-02-01 13:41:09 +01:00
parent 50c2b0066f
commit cbe3e49c7f

View File

@ -25,6 +25,13 @@ namespace Input {
struct Touch_id { unsigned value; };
struct Axis_id
{
enum { X = 1, Y = 2 };
unsigned value;
};
/*
* Event attributes
*/
@ -40,6 +47,7 @@ namespace Input {
struct Touch { Touch_id id; float x, y; };
struct Touch_release { Touch_id id; };
struct Seq_number { unsigned value; };
struct Axis { Axis_id id; float value; };
class Event;
class Binding;
@ -52,7 +60,7 @@ class Input::Event
enum Type { INVALID, PRESS, RELEASE, REL_MOTION, ABS_MOTION, WHEEL,
FOCUS_ENTER, FOCUS_LEAVE, HOVER_LEAVE, TOUCH, TOUCH_RELEASE,
SEQ_NUMBER };
SEQ_NUMBER, AXIS };
Type _type = INVALID;
@ -67,6 +75,7 @@ class Input::Event
Touch touch;
Touch_release touch_release;
Seq_number seq_number;
Axis axis;
};
} _attr { };
@ -107,6 +116,7 @@ class Input::Event
Event(Touch arg) : _type(TOUCH) { _attr.touch = arg; }
Event(Touch_release arg) : _type(TOUCH_RELEASE) { _attr.touch_release = arg; }
Event(Seq_number arg) : _type(SEQ_NUMBER) { _attr.seq_number = arg; }
Event(Axis arg) : _type(AXIS) { _attr.axis = arg; }
/************************************
@ -125,6 +135,7 @@ class Input::Event
bool touch() const { return _type == TOUCH; }
bool touch_release() const { return _type == TOUCH_RELEASE; }
bool seq_number() const { return _type == SEQ_NUMBER; }
bool axis() const { return _type == AXIS; }
bool key_press(Keycode key) const
{
@ -199,6 +210,13 @@ class Input::Event
fn(_attr.seq_number);
}
template <typename FN>
void handle_axis(FN const &fn) const
{
if (axis())
fn(_attr.axis.id, _attr.axis.value);
}
inline void print(Genode::Output &out) const;
};
@ -221,6 +239,8 @@ void Input::Event::print(Genode::Output &out) const
case TOUCH: print(out, "TOUCH ", _attr.touch.id.value, " ",
_xy<float>(_attr.touch)); break;
case SEQ_NUMBER: print(out, "SEQ_NUMBER ", _attr.seq_number.value); break;
case AXIS: print(out, "AXIS ", _attr.axis.id.value, " ",
_attr.axis.value); break;
};
}