mirror of https://github.com/encounter/SDL.git
Fixed bug 3461 - Implement TEXTINPUT events for Haiku
Kai Sterker Apparently, SDL2 on Haiku does not generate SDL_TEXTINPUT events. Attached is a patch that adds this functionality. Tested with SDLs own checkkeys program and different keymaps as well as my own SDL application and German keyboard layout to verify it generates the expected input.
This commit is contained in:
parent
6d67c98e70
commit
8a73f7e893
|
@ -193,7 +193,8 @@ public:
|
||||||
if(_current_context)
|
if(_current_context)
|
||||||
_current_context->UnlockGL();
|
_current_context->UnlockGL();
|
||||||
_current_context = newContext;
|
_current_context = newContext;
|
||||||
_current_context->LockGL();
|
if (_current_context)
|
||||||
|
_current_context->LockGL();
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
/* Event management */
|
/* Event management */
|
||||||
|
@ -272,6 +273,17 @@ private:
|
||||||
}
|
}
|
||||||
BE_SetKeyState(scancode, state);
|
BE_SetKeyState(scancode, state);
|
||||||
SDL_SendKeyboardKey(state, BE_GetScancodeFromBeKey(scancode));
|
SDL_SendKeyboardKey(state, BE_GetScancodeFromBeKey(scancode));
|
||||||
|
|
||||||
|
if (state == SDL_PRESSED && SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
|
||||||
|
const int8 *keyUtf8;
|
||||||
|
ssize_t count;
|
||||||
|
if (msg->FindData("key-utf8", B_INT8_TYPE, (const void**)&keyUtf8, &count) == B_OK) {
|
||||||
|
char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];
|
||||||
|
SDL_zero(text);
|
||||||
|
SDL_memcpy(text, keyUtf8, count);
|
||||||
|
SDL_SendKeyboardText(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _HandleMouseFocus(BMessage *msg) {
|
void _HandleMouseFocus(BMessage *msg) {
|
||||||
|
|
|
@ -337,16 +337,30 @@ class SDL_BWin:public BDirectWindow
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_KEY_DOWN:
|
case B_KEY_DOWN:
|
||||||
|
{
|
||||||
|
int32 i = 0;
|
||||||
|
int8 byte;
|
||||||
|
int8 bytes[4] = { 0, 0, 0, 0 };
|
||||||
|
while (i < 4 && msg->FindInt8("byte", i, &byte) == B_OK) {
|
||||||
|
bytes[i] = byte;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (msg->FindInt32("key", &key) == B_OK) {
|
||||||
|
_KeyEvent((SDL_Scancode)key, &bytes[0], i, SDL_PRESSED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case B_UNMAPPED_KEY_DOWN: /* modifier keys are unmapped */
|
case B_UNMAPPED_KEY_DOWN: /* modifier keys are unmapped */
|
||||||
if (msg->FindInt32("key", &key) == B_OK) {
|
if (msg->FindInt32("key", &key) == B_OK) {
|
||||||
_KeyEvent((SDL_Scancode)key, SDL_PRESSED);
|
_KeyEvent((SDL_Scancode)key, NULL, 0, SDL_PRESSED);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_KEY_UP:
|
case B_KEY_UP:
|
||||||
case B_UNMAPPED_KEY_UP: /* modifier keys are unmapped */
|
case B_UNMAPPED_KEY_UP: /* modifier keys are unmapped */
|
||||||
if (msg->FindInt32("key", &key) == B_OK) {
|
if (msg->FindInt32("key", &key) == B_OK) {
|
||||||
_KeyEvent(key, SDL_RELEASED);
|
_KeyEvent(key, NULL, 0, SDL_RELEASED);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -512,13 +526,15 @@ private:
|
||||||
_PostWindowEvent(msg);
|
_PostWindowEvent(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _KeyEvent(int32 keyCode, int32 keyState) {
|
void _KeyEvent(int32 keyCode, const int8 *keyUtf8, const ssize_t & len, int32 keyState) {
|
||||||
/* Create a message to pass along to the BeApp thread */
|
/* Create a message to pass along to the BeApp thread */
|
||||||
BMessage msg(BAPP_KEY);
|
BMessage msg(BAPP_KEY);
|
||||||
msg.AddInt32("key-state", keyState);
|
msg.AddInt32("key-state", keyState);
|
||||||
msg.AddInt32("key-scancode", keyCode);
|
msg.AddInt32("key-scancode", keyCode);
|
||||||
|
if (keyUtf8 != NULL) {
|
||||||
|
msg.AddData("key-utf8", B_INT8_TYPE, (const void*)keyUtf8, len);
|
||||||
|
}
|
||||||
be_app->PostMessage(&msg);
|
be_app->PostMessage(&msg);
|
||||||
/* Apparently SDL only uses the scancode */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _RepaintEvent() {
|
void _RepaintEvent() {
|
||||||
|
|
Loading…
Reference in New Issue