From 21cb990e75843d62182e82618a1e4ed7e1a9ecdf Mon Sep 17 00:00:00 2001 From: yw05 <37980625+yw05@users.noreply.github.com> Date: Sun, 18 Apr 2021 21:27:15 +0200 Subject: [PATCH] Fix misbehaving input after IME changes (Linux) --- source/Irrlicht/CIrrDeviceLinux.cpp | 36 ++++++++++++++++------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/source/Irrlicht/CIrrDeviceLinux.cpp b/source/Irrlicht/CIrrDeviceLinux.cpp index f482ec68..ec3a5259 100644 --- a/source/Irrlicht/CIrrDeviceLinux.cpp +++ b/source/Irrlicht/CIrrDeviceLinux.cpp @@ -829,7 +829,7 @@ bool CIrrDeviceLinux::run() { XEvent event; XNextEvent(XDisplay, &event); - if (acceptsIME() && XFilterEvent(&event, None)) + if (XFilterEvent(&event, None)) continue; switch (event.type) @@ -1156,23 +1156,27 @@ bool CIrrDeviceLinux::run() break; } // end switch + // Update IME information + if (XInputContext && GUIEnvironment) + { + gui::IGUIElement *elem = GUIEnvironment->getFocus(); + if (elem && elem->acceptsIME()) + { + core::rect r = elem->getAbsolutePosition(); + XPoint p; + p.x = (short)r.UpperLeftCorner.X; + p.y = (short)r.LowerRightCorner.Y; + XSetICFocus(XInputContext); + XVaNestedList l = XVaCreateNestedList(0, XNSpotLocation, &p, NULL); + XSetICValues(XInputContext, XNPreeditAttributes, l, NULL); + XFree(l); + } else { + XUnsetICFocus(XInputContext); + } + } + } // end while - // Update IME information - if (XInputContext && GUIEnvironment) - { - gui::IGUIElement *elem = GUIEnvironment->getFocus(); - if (elem && elem->acceptsIME()) - { - core::rect r = elem->getAbsolutePosition(); - XPoint p; - p.x = (short)r.UpperLeftCorner.X; - p.y = (short)r.LowerRightCorner.Y; - XVaNestedList l = XVaCreateNestedList(0, XNSpotLocation, &p, NULL); - XSetICValues(XInputContext, XNPreeditAttributes, l, NULL); - XFree(l); - } - } } #endif //_IRR_COMPILE_WITH_X11_