From 9311178b1ba2517a4939c5ae4b7c5b128fe95e50 Mon Sep 17 00:00:00 2001 From: Mel Date: Fri, 4 Sep 2026 01:29:13 +0200 Subject: Allow unmapped keys from GLFW (it sometimes also doesn't know what's going on) Signed-off-by: Mel --- src/Input.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/Input.cpp') diff --git a/src/Input.cpp b/src/Input.cpp index 2362794..b0b58bc 100644 --- a/src/Input.cpp +++ b/src/Input.cpp @@ -189,7 +189,7 @@ Key Input::from_glfw_key(I32 const key) { case GLFW_KEY_F10: return Key::F10; case GLFW_KEY_F11: return Key::F11; case GLFW_KEY_F12: return Key::F12; - default: UNREACHABLE("Unknown key."); return TO(Key, 0); + default: return Key::Unknown; } } @@ -198,13 +198,16 @@ Mouse Input::from_glfw_mouse(I32 const button) { case GLFW_MOUSE_BUTTON_LEFT: return Mouse::Left; case GLFW_MOUSE_BUTTON_RIGHT: return Mouse::Right; case GLFW_MOUSE_BUTTON_MIDDLE: return Mouse::Middle; - default: UNREACHABLE("Unknown mouse button."); return TO(Mouse, 0); + default: return Mouse::Unknown; } } -void Input::key_callback(GLFWwindow* _window, I32 const key, I32 _scancode, I32 const action, I32 _mods) { - if (action == GLFW_PRESS) s_key_buffer[key_value(from_glfw_key(key))] = true; - else if (action == GLFW_RELEASE) s_key_buffer[key_value(from_glfw_key(key))] = false; +void Input::key_callback(GLFWwindow* _window, I32 const key, I32 const scancode, I32 const action, I32 _mods) { + auto mapped = from_glfw_key(key); + if (mapped == Key::Unknown) return; + + if (action == GLFW_PRESS) s_key_buffer[key_value(mapped)] = true; + else if (action == GLFW_RELEASE) s_key_buffer[key_value(mapped)] = false; } void Input::cursor_position_callback(GLFWwindow* _window, F64 x, F64 y) { @@ -214,8 +217,11 @@ void Input::cursor_position_callback(GLFWwindow* _window, F64 x, F64 y) { } void Input::mouse_button_callback(GLFWwindow* _window, I32 const button, I32 const action, I32 _mods) { - if (action == GLFW_PRESS) s_mouse_buffer[mouse_button_value(from_glfw_mouse(button))] = true; - else if (action == GLFW_RELEASE) s_mouse_buffer[mouse_button_value(from_glfw_mouse(button))] = false; + auto mapped = from_glfw_mouse(button); + if (mapped == Mouse::Unknown) return; + + if (action == GLFW_PRESS) s_mouse_buffer[mouse_button_value(mapped)] = true; + else if (action == GLFW_RELEASE) s_mouse_buffer[mouse_button_value(mapped)] = false; } } -- cgit v1.3.1