2011-12-22 15:19:25 +00:00
|
|
|
/*
|
|
|
|
* \brief Input event structure
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2006-08-16
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 12:23:52 +00:00
|
|
|
* Copyright (C) 2006-2017 Genode Labs GmbH
|
2011-12-22 15:19:25 +00:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 12:23:52 +00:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2011-12-22 15:19:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _INCLUDE__INPUT__EVENT_H_
|
|
|
|
#define _INCLUDE__INPUT__EVENT_H_
|
|
|
|
|
2013-09-06 12:43:12 +00:00
|
|
|
#include <input/keycodes.h>
|
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
namespace Input { class Event; }
|
|
|
|
|
|
|
|
|
|
|
|
class Input::Event
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2017-01-30 14:50:04 +00:00
|
|
|
enum Type { INVALID, MOTION, PRESS, RELEASE, WHEEL, FOCUS, LEAVE, TOUCH,
|
|
|
|
CHARACTER };
|
2015-03-04 20:12:14 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2017-01-30 14:50:04 +00:00
|
|
|
Type _type = INVALID;
|
2015-03-04 20:12:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For PRESS and RELEASE events, '_code' contains the key code.
|
|
|
|
* For FOCUS events, '_code' is set to 1 (focus) or 0 (unfocus).
|
|
|
|
*/
|
2017-01-30 14:50:04 +00:00
|
|
|
int _code = 0;
|
2015-03-04 20:12:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Absolute pointer position coordinates
|
|
|
|
*/
|
2017-01-30 14:50:04 +00:00
|
|
|
int _ax = 0, _ay = 0;
|
2015-03-04 20:12:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Relative pointer motion vector
|
|
|
|
*/
|
2017-01-30 14:50:04 +00:00
|
|
|
int _rx = 0, _ry = 0;
|
2015-03-04 20:12:14 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
2017-01-30 14:50:04 +00:00
|
|
|
* UTF8-encoded symbolic character
|
2015-03-04 20:12:14 +00:00
|
|
|
*/
|
2017-01-30 14:50:04 +00:00
|
|
|
struct Utf8
|
|
|
|
{
|
|
|
|
typedef unsigned char byte;
|
|
|
|
|
|
|
|
byte b0, b1, b2, b3;
|
2015-03-04 20:12:14 +00:00
|
|
|
|
2017-01-30 14:50:04 +00:00
|
|
|
Utf8(byte b0, byte b1 = 0, byte b2 = 0, byte b3 = 0)
|
|
|
|
: b0(b0), b1(b1), b2(b2), b3(b3) { }
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Default constructor creates an invalid event
|
|
|
|
*/
|
|
|
|
Event() { }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor creates a low-level event
|
|
|
|
*/
|
2015-03-04 20:12:14 +00:00
|
|
|
Event(Type type, int code, int ax, int ay, int rx, int ry):
|
|
|
|
_type(type), _code(code),
|
|
|
|
_ax(ax), _ay(ay), _rx(rx), _ry(ry) { }
|
|
|
|
|
2017-01-30 14:50:04 +00:00
|
|
|
/**
|
|
|
|
* Constructor creates a symbolic character event
|
|
|
|
*/
|
|
|
|
Event(Utf8 const &utf8)
|
|
|
|
:
|
|
|
|
_type(CHARACTER),
|
|
|
|
_code(((unsigned)utf8.b3 << 24) | ((unsigned)utf8.b2 << 16) |
|
|
|
|
((unsigned)utf8.b1 << 8) | ((unsigned)utf8.b0 << 0))
|
|
|
|
{ }
|
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
/**
|
|
|
|
* Accessors
|
|
|
|
*/
|
|
|
|
Type type() const { return _type; }
|
|
|
|
int code() const { return _code; }
|
|
|
|
int ax() const { return _ax; }
|
|
|
|
int ay() const { return _ay; }
|
|
|
|
int rx() const { return _rx; }
|
|
|
|
int ry() const { return _ry; }
|
|
|
|
|
2017-01-30 14:50:04 +00:00
|
|
|
/**
|
|
|
|
* Return symbolic character encoded as UTF8 byte sequence
|
|
|
|
*
|
|
|
|
* This method must only be called if type is CHARACTER.
|
|
|
|
*/
|
|
|
|
Utf8 utf8() const { return Utf8(_code, _code >> 8, _code >> 16, _code >> 24); }
|
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
/**
|
|
|
|
* Return key code for press/release events
|
|
|
|
*/
|
|
|
|
Keycode keycode() const
|
|
|
|
{
|
|
|
|
return _type == PRESS || _type == RELEASE ? (Keycode)_code : KEY_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2016-05-11 16:21:47 +00:00
|
|
|
bool absolute_motion() const { return _type == MOTION && !_rx && !_ry; }
|
|
|
|
bool relative_motion() const { return _type == MOTION && (_rx || _ry); }
|
|
|
|
bool touch_release() const { return _type == TOUCH && (_rx == -1) && (_ry == -1); }
|
|
|
|
|
|
|
|
/*
|
|
|
|
* \deprecated use methods without the 'is_' prefix instead
|
|
|
|
*/
|
|
|
|
bool is_absolute_motion() const { return absolute_motion(); }
|
|
|
|
bool is_relative_motion() const { return relative_motion(); }
|
|
|
|
bool is_touch_release() const { return touch_release(); }
|
2015-03-09 11:42:37 +00:00
|
|
|
|
|
|
|
static Event create_touch_event(int ax, int ay, int id, bool last = false)
|
|
|
|
{
|
|
|
|
return Event(Type::TOUCH, id, ax, ay, last ? -1 : 0, last ? -1 : 0);
|
|
|
|
}
|
2015-03-04 20:12:14 +00:00
|
|
|
};
|
2011-12-22 15:19:25 +00:00
|
|
|
|
|
|
|
#endif /* _INCLUDE__INPUT__EVENT_H_ */
|