From 1354affd288b8bc3b354a155f27201cda31dfa7f Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Wed, 12 Feb 2025 17:17:14 -0500
Subject: [PATCH] haiku: Fixed keyboard input.
_GetWinID() doesn't work with keyboard-related BMessages, because Haiku
assumes you know what window has keyboard focus at the time, so these events
don't have a `window-id` property. So when this call failed, the key event
handler would return early.
This was probably a copy/paste error that snuck in at some point, as SDL2
doesn't have this issue.
---
src/core/haiku/SDL_BApp.h | 25 ++++++++++++-------------
1 file changed, 12 insertions(+), 13 deletions(-)
diff --git a/src/core/haiku/SDL_BApp.h b/src/core/haiku/SDL_BApp.h
index b13b9e6d6e530..cbd3e3a005c24 100644
--- a/src/core/haiku/SDL_BApp.h
+++ b/src/core/haiku/SDL_BApp.h
@@ -293,12 +293,9 @@ class SDL_BLooper : public BLooper
void _HandleKey(BMessage *msg)
{
- SDL_Window *win;
- int32 winID;
int32 scancode;
- bool down;
+ bool down;
if (
- !_GetWinID(msg, &winID) ||
msg->FindInt32("key-scancode", &scancode) != B_OK ||
msg->FindBool("key-down", &down) != B_OK) {
return;
@@ -306,15 +303,17 @@ class SDL_BLooper : public BLooper
SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, scancode, HAIKU_GetScancodeFromBeKey(scancode), down);
- win = GetSDLWindow(winID);
- if (down && SDL_TextInputActive(win)) {
- const int8 *keyUtf8;
- ssize_t count;
- if (msg->FindData("key-utf8", B_INT8_TYPE, (const void **)&keyUtf8, &count) == B_OK) {
- char text[64];
- SDL_zeroa(text);
- SDL_memcpy(text, keyUtf8, count);
- SDL_SendKeyboardText(text);
+ if (down) {
+ SDL_Window *win = SDL_GetKeyboardFocus();
+ if (win && SDL_TextInputActive(win)) {
+ const int8 *keyUtf8;
+ ssize_t count;
+ if (msg->FindData("key-utf8", B_INT8_TYPE, (const void **)&keyUtf8, &count) == B_OK) {
+ char text[64];
+ SDL_zeroa(text);
+ SDL_memcpy(text, keyUtf8, count);
+ SDL_SendKeyboardText(text);
+ }
}
}
}