2012-04-17 18:46:14 +02:00
|
|
|
/*
|
|
|
|
* \brief Virtualized input session
|
|
|
|
* \author Christian Prochaska
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2010-09-02
|
|
|
|
*
|
|
|
|
* This input service implementation is used by the virtualized nitpicker
|
|
|
|
* service to translate the input coordinate system from the coordinates
|
|
|
|
* seen by the user of the virtualized session and the physical coordinates
|
|
|
|
* dictated by the loader-session client.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2013-01-10 21:44:47 +01:00
|
|
|
* Copyright (C) 2010-2013 Genode Labs GmbH
|
2012-04-17 18:46:14 +02:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
|
|
* under the terms of the GNU General Public License version 2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _INPUT_H_
|
|
|
|
#define _INPUT_H_
|
|
|
|
|
|
|
|
#include <base/rpc_server.h>
|
|
|
|
#include <input/event.h>
|
|
|
|
#include <input/keycodes.h>
|
|
|
|
#include <input_session/client.h>
|
|
|
|
|
|
|
|
namespace Input {
|
|
|
|
|
|
|
|
using namespace Genode;
|
|
|
|
|
|
|
|
struct Transformer
|
|
|
|
{
|
|
|
|
struct Delta { int const x, y; };
|
|
|
|
|
|
|
|
virtual Delta delta() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Session_component : public Rpc_object<Session>
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
Session_client _real_input;
|
|
|
|
Transformer &_transformer;
|
|
|
|
Event * const _ev_buf;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
|
|
|
Session_component(Session_capability real_input,
|
|
|
|
Transformer &transformer)
|
|
|
|
:
|
|
|
|
_real_input(real_input), _transformer(transformer),
|
|
|
|
_ev_buf(env()->rm_session()->attach(_real_input.dataspace()))
|
|
|
|
{ }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor
|
|
|
|
*/
|
|
|
|
~Session_component() { env()->rm_session()->detach(_ev_buf); }
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************
|
|
|
|
** Input session interface **
|
|
|
|
*****************************/
|
|
|
|
|
2014-05-07 10:33:20 +02:00
|
|
|
Dataspace_capability dataspace() override { return _real_input.dataspace(); }
|
2012-04-17 18:46:14 +02:00
|
|
|
|
2014-05-07 10:33:20 +02:00
|
|
|
bool is_pending() const override { return _real_input.is_pending(); }
|
2012-04-17 18:46:14 +02:00
|
|
|
|
2014-05-07 10:33:20 +02:00
|
|
|
int flush() override
|
2012-04-17 18:46:14 +02:00
|
|
|
{
|
|
|
|
/* translate mouse position to child's coordinate system */
|
|
|
|
Transformer::Delta delta = _transformer.delta();
|
|
|
|
|
|
|
|
int const num_ev = _real_input.flush();
|
|
|
|
for (int i = 0; i < num_ev; i++) {
|
|
|
|
|
|
|
|
Input::Event &ev = _ev_buf[i];
|
|
|
|
|
2013-01-12 23:34:49 +01:00
|
|
|
if ((ev.type() == Input::Event::MOTION)
|
|
|
|
|| (ev.type() == Input::Event::WHEEL)
|
|
|
|
|| (ev.code() == Input::BTN_LEFT)
|
|
|
|
|| (ev.code() == Input::BTN_RIGHT)
|
|
|
|
|| (ev.code() == Input::BTN_MIDDLE)) {
|
2012-04-17 18:46:14 +02:00
|
|
|
|
|
|
|
ev = Input::Event(ev.type(),
|
2013-01-12 23:34:49 +01:00
|
|
|
ev.code(),
|
2012-04-17 18:46:14 +02:00
|
|
|
ev.ax() - delta.x,
|
|
|
|
ev.ay() - delta.y,
|
|
|
|
ev.rx(),
|
|
|
|
ev.ry());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return num_ev;
|
|
|
|
}
|
2014-05-07 10:33:20 +02:00
|
|
|
|
|
|
|
void sigh(Signal_context_capability sigh) override
|
|
|
|
{
|
|
|
|
_real_input.sigh(sigh);
|
|
|
|
}
|
2012-04-17 18:46:14 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* _INPUT_H_ */
|