From 264ee999a14ac0c6cf1d005776554cf25af7b2d6 Mon Sep 17 00:00:00 2001 From: Christian Helmuth Date: Tue, 31 Jan 2023 16:33:13 +0100 Subject: [PATCH] acpi_event: generalize config for any key Fixes #4748 --- repos/libports/src/app/acpi_event/main.cc | 35 ++++------------------- repos/os/include/input/keycodes.h | 2 +- 2 files changed, 6 insertions(+), 31 deletions(-) diff --git a/repos/libports/src/app/acpi_event/main.cc b/repos/libports/src/app/acpi_event/main.cc index 1edd981939..a879ca11e9 100644 --- a/repos/libports/src/app/acpi_event/main.cc +++ b/repos/libports/src/app/acpi_event/main.cc @@ -147,7 +147,7 @@ struct Transform::Main uint64_t acpi_value = 0; String<8> acpi_type; String<8> acpi_value_string; - String<32> to_key; + Input::Key_name to_key; String<16> key_type("PRESS_RELEASE"); Keys::Type press_release = Keys::Type::PRESS_RELEASE; @@ -185,24 +185,7 @@ struct Transform::Main } else map_node.attribute("value").value(acpi_value); - Input::Keycode key_code = Input::Keycode::KEY_UNKNOWN; - - if (to_key == "KEY_VENDOR") - key_code = Input::Keycode::KEY_VENDOR; - else if (to_key == "KEY_POWER") - key_code = Input::Keycode::KEY_POWER; - else if (to_key == "KEY_SLEEP") - key_code = Input::Keycode::KEY_SLEEP; - else if (to_key == "KEY_WAKEUP") - key_code = Input::Keycode::KEY_WAKEUP; - else if (to_key == "KEY_BATTERY") - key_code = Input::Keycode::KEY_BATTERY; - else if (to_key == "KEY_BRIGHTNESSUP") - key_code = Input::Keycode::KEY_BRIGHTNESSUP; - else if (to_key == "KEY_BRIGHTNESSDOWN") - key_code = Input::Keycode::KEY_BRIGHTNESSDOWN; - else if (to_key == "KEY_FN_F4") - key_code = Input::Keycode::KEY_FN_F4; + Input::Keycode key_code = Input::key_code(to_key); if (key_code == Input::Keycode::KEY_UNKNOWN) throw 4; @@ -228,17 +211,9 @@ struct Transform::Main throw 5; } catch (...) { - using namespace Genode; - - map_node.with_raw_node([&] (char const *start, size_t length) { - - String<64> invalid_node(Cstring(start, length)); - error("map item : '", invalid_node, "'"); - - /* abort on malformed configuration */ - class Invalid_config { }; - throw Invalid_config(); - }); + /* abort on malformed configuration */ + error("map item '", map_node, "' Aborting..."); + env.parent().exit(1); } }); diff --git a/repos/os/include/input/keycodes.h b/repos/os/include/input/keycodes.h index c61962cf99..1fe9e23229 100644 --- a/repos/os/include/input/keycodes.h +++ b/repos/os/include/input/keycodes.h @@ -489,7 +489,7 @@ namespace Input { /** * Return key code for name (linear search) */ - Keycode key_code(Key_name name) + static inline Keycode key_code(Key_name const &name) { for (unsigned i = 0; i < KEY_MAX; ++i) { Keycode const code = Keycode(i);