mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-14 05:08:19 +00:00
input: provide keycode-by-name lookup
The new utility returns a key code for a passed name and is implemented by linear search, which is slow but sufficient in situations like config updates. Issue #4748
This commit is contained in:
@ -17,6 +17,8 @@
|
|||||||
#ifndef _INCLUDE__INPUT__KEYCODES_H_
|
#ifndef _INCLUDE__INPUT__KEYCODES_H_
|
||||||
#define _INCLUDE__INPUT__KEYCODES_H_
|
#define _INCLUDE__INPUT__KEYCODES_H_
|
||||||
|
|
||||||
|
#include <util/string.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* C++ provides no reflection of the names of enum values. So we use the
|
* C++ provides no reflection of the names of enum values. So we use the
|
||||||
* preprocessor to generate the bodies of both the enum type 'Keycode' and
|
* preprocessor to generate the bodies of both the enum type 'Keycode' and
|
||||||
@ -481,6 +483,21 @@ namespace Input {
|
|||||||
}
|
}
|
||||||
return "KEY_UNKNOWN";
|
return "KEY_UNKNOWN";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef Genode::String<22> Key_name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return key code for name (linear search)
|
||||||
|
*/
|
||||||
|
Keycode key_code(Key_name name)
|
||||||
|
{
|
||||||
|
for (unsigned i = 0; i < KEY_MAX; ++i) {
|
||||||
|
Keycode const code = Keycode(i);
|
||||||
|
if (name == key_name(code))
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
return KEY_UNKNOWN;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user