From 1930b1134675fea101df822be3fc2a4adbbc8268 Mon Sep 17 00:00:00 2001 From: y5nw <37980625+y5nw@users.noreply.github.com> Date: Thu, 8 Feb 2024 00:36:00 +0100 Subject: [PATCH] [SDL] Avoid unnecessarily "restarting" text input --- source/Irrlicht/CIrrDeviceSDL.cpp | 33 +++++++++++++++++++++++-------- source/Irrlicht/CIrrDeviceSDL.h | 2 ++ 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/source/Irrlicht/CIrrDeviceSDL.cpp b/source/Irrlicht/CIrrDeviceSDL.cpp index 7b643ce2..0ed8864c 100644 --- a/source/Irrlicht/CIrrDeviceSDL.cpp +++ b/source/Irrlicht/CIrrDeviceSDL.cpp @@ -219,17 +219,29 @@ void CIrrDeviceSDL::resetReceiveTextInputEvents() { gui::IGUIElement *elem = GUIEnvironment->getFocus(); if (elem && elem->acceptsIME()) { - core::rect pos = elem->getAbsolutePosition(); - 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(); + core::rect *pos = new core::rect(elem->getAbsolutePosition()); + if (lastElemPos == NULL || *lastElemPos != *pos) + { + if (lastElemPos != NULL) + delete lastElemPos; + 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 + { + delete pos; + } } else { + delete lastElemPos; + lastElemPos = NULL; SDL_StopTextInput(); } } @@ -310,6 +322,8 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param) createGUIAndScene(); VideoDriver->OnResize(core::dimension2d(Width, Height)); } + + lastElemPos = NULL; } @@ -323,6 +337,9 @@ CIrrDeviceSDL::~CIrrDeviceSDL() for (u32 i=0; i *lastElemPos; + struct SKeyMap { SKeyMap() {}