Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
SDL: Improve handling of IMEs (#285)
Browse files Browse the repository at this point in the history
* Set text input rectangle for IMEs
* Avoid unnecessarily "restarting" text input
  • Loading branch information
y5nw authored Feb 8, 2024
1 parent f150409 commit 6779ac8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 20 additions & 1 deletion source/Irrlicht/CIrrDeviceSDL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions source/Irrlicht/CIrrDeviceSDL.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ namespace irr

bool Resizable;

core::rect<s32> lastElemPos;

struct SKeyMap
{
SKeyMap() {}
Expand Down

0 comments on commit 6779ac8

Please sign in to comment.