From a255ffaee9e4867063c596f270e810db2da57365 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Tue, 14 Nov 2017 17:21:04 +0100 Subject: [PATCH] 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. --- repos/os/include/input/event.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/repos/os/include/input/event.h b/repos/os/include/input/event.h index bb949f6fa6..e27876e13f 100644 --- a/repos/os/include/input/event.h +++ b/repos/os/include/input/event.h @@ -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; }