os: new Input::Event representation

This commit changes the 'Input::Event' type to be more safe and to
deliver symbolic character information along with press events.

Issue #2761
Fixes #2786
This commit is contained in:
Norman Feske
2018-04-20 14:27:45 +02:00
committed by Christian Helmuth
parent df3ceda052
commit afcad2a968
46 changed files with 1170 additions and 1209 deletions

View File

@ -61,23 +61,16 @@ class Window_content : public Scout::Element
Point mouse_position = ev.mouse_position - _element->abs_position();
int code = 0;
auto motion = [&] (Point p) { return Input::Absolute_motion{p.x(), p.y()}; };
if (ev.type == Event::PRESS || ev.type == Event::RELEASE)
code = ev.code;
if (ev.type == Event::MOTION)
_input_session.submit(motion(mouse_position));
Input::Event::Type type;
if (ev.type == Event::PRESS)
_input_session.submit(Input::Press{Input::Keycode(ev.code)});
type = (ev.type == Event::MOTION) ? Input::Event::MOTION
: (ev.type == Event::PRESS) ? Input::Event::PRESS
: (ev.type == Event::RELEASE) ? Input::Event::RELEASE
: Input::Event::INVALID;
if (type != Input::Event::INVALID)
_input_session.submit(Input::Event(type, code, mouse_position.x(),
mouse_position.y(),
mouse_position.x() - _old_mouse_position.x(),
mouse_position.y() - _old_mouse_position.y()));
if (ev.type == Event::RELEASE)
_input_session.submit(Input::Release{Input::Keycode(ev.code)});
_old_mouse_position = mouse_position;
}

View File

@ -448,7 +448,9 @@ struct Nitlog::Main
Attached_dataspace _ev_ds { _env.rm(), _nitpicker.input()->dataspace() };
Nitpicker::Point _old_mouse_pos { };
Nitpicker::Point const _initial_mouse_pos { -1, -1 };
Nitpicker::Point _old_mouse_pos = _initial_mouse_pos;
unsigned _key_cnt = 0;
@ -463,20 +465,24 @@ struct Nitlog::Main
Input::Event const &ev = ev_buf[i];
if (ev.type() == Input::Event::PRESS) _key_cnt++;
if (ev.type() == Input::Event::RELEASE) _key_cnt--;
Nitpicker::Point mouse_pos(ev.ax(), ev.ay());
if (ev.press()) _key_cnt++;
if (ev.release()) _key_cnt--;
/* move view */
if (ev.type() == Input::Event::MOTION && _key_cnt > 0)
_view.move(_view.pos() + mouse_pos - _old_mouse_pos);
ev.handle_absolute_motion([&] (int x, int y) {
Nitpicker::Point const mouse_pos(x, y);
if (_key_cnt && _old_mouse_pos != _initial_mouse_pos)
_view.move(_view.pos() + mouse_pos - _old_mouse_pos);
_old_mouse_pos = mouse_pos;
});
/* find selected view and bring it to front */
if (ev.type() == Input::Event::PRESS && _key_cnt == 1)
if (ev.press() && _key_cnt == 1)
_view.top();
_old_mouse_pos = mouse_pos;
}
}