SDL: Improve handling of IMEs (#285)

* Set text input rectangle for IMEs
* Avoid unnecessarily "restarting" text input
This commit is contained in:
y5nw 2024-02-09 00:08:03 +01:00 committed by GitHub
parent f1504093d1
commit 6779ac83f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 1 deletions

@ -218,9 +218,28 @@ int CIrrDeviceSDL::findCharToPassToIrrlicht(int assumedChar, EKEY_CODE key) {
void CIrrDeviceSDL::resetReceiveTextInputEvents() {
gui::IGUIElement *elem = GUIEnvironment->getFocus();
if (elem && elem->acceptsIME())
SDL_StartTextInput();
{
// IBus seems to have an issue where dead keys and compose keys do not
// work (specifically, the individual characters in the sequence are
// sent as text input events instead of the result) when
// SDL_StartTextInput() is called on the same input box.
core::rect<s32> pos = elem->getAbsolutePosition();
if (!SDL_IsTextInputActive() || lastElemPos != pos)
{
lastElemPos = pos;
SDL_Rect rect;
rect.x = pos.UpperLeftCorner.X;
rect.y = pos.UpperLeftCorner.Y;
rect.w = pos.getWidth();
rect.h = pos.getHeight();
SDL_SetTextInputRect(&rect);
SDL_StartTextInput();
}
}
else
{
SDL_StopTextInput();
}
}
//! constructor

@ -303,6 +303,8 @@ namespace irr
bool Resizable;
core::rect<s32> lastElemPos;
struct SKeyMap
{
SKeyMap() {}