From 6779ac83f9c71555c18a356ac15cc5e7391237a5 Mon Sep 17 00:00:00 2001 From: y5nw <37980625+y5nw@users.noreply.github.com> Date: Fri, 9 Feb 2024 00:08:03 +0100 Subject: [PATCH] SDL: Improve handling of IMEs (#285) * Set text input rectangle for IMEs * Avoid unnecessarily "restarting" text input --- source/Irrlicht/CIrrDeviceSDL.cpp | 21 ++++++++++++++++++++- source/Irrlicht/CIrrDeviceSDL.h | 2 ++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/source/Irrlicht/CIrrDeviceSDL.cpp b/source/Irrlicht/CIrrDeviceSDL.cpp index d56e2ca8..f761a13d 100644 --- a/source/Irrlicht/CIrrDeviceSDL.cpp +++ b/source/Irrlicht/CIrrDeviceSDL.cpp @@ -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 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 diff --git a/source/Irrlicht/CIrrDeviceSDL.h b/source/Irrlicht/CIrrDeviceSDL.h index 1713a3b9..ebd8e032 100644 --- a/source/Irrlicht/CIrrDeviceSDL.h +++ b/source/Irrlicht/CIrrDeviceSDL.h @@ -303,6 +303,8 @@ namespace irr bool Resizable; + core::rect lastElemPos; + struct SKeyMap { SKeyMap() {}