input: disarm obnoxious press/release events

This patch adds a sanity check to the Event::type accessor. If the key
code of a given PRESS or RELEASE event is out of the valid range, it
reports an INVALID event. This way, client side code does not need to
deal with such edge cases. E.g., on Lenovo notebooks, the ps2 driver
reports strange key events when pressing shift-pageup/pagedown,
violating the general assumption that there is a release event for each
press event. By flagging these events as INVALID, the client-side logic
stays intact.
This commit is contained in:
Norman Feske 2017-11-14 17:21:04 +01:00 committed by Christian Helmuth
parent f2a5648deb
commit a255ffaee9

View File

@ -83,10 +83,22 @@ class Input::Event
((unsigned)utf8.b1 << 8) | ((unsigned)utf8.b0 << 0))
{ }
/**
* Return event type
*/
Type type() const
{
/* prevent obnoxious events from being processed by clients */
if ((_type == PRESS || _type == RELEASE)
&& (_code <= KEY_RESERVED || _code >= KEY_UNKNOWN))
return INVALID;
return _type;
}
/**
* Accessors
*/
Type type() const { return _type; }
int code() const { return _code; }
int ax() const { return _ax; }
int ay() const { return _ay; }