JBR-1573: restore current input context after cleanup

(cherry picked from commit b7acd7f6f6)
(cherry picked from commit 9dbdd24cc3)
This commit is contained in:
Artem Bochkarev
2019-07-03 12:30:19 +03:00
committed by jbrbot
parent 0a074e0fd8
commit b3d8a11acb
4 changed files with 34 additions and 16 deletions

View File

@@ -72,16 +72,16 @@ public class XInputMethod extends X11InputMethod {
return createXICNative(peer.getContentWindow());
}
protected boolean recreateXIC() {
protected boolean recreateXIC(int ctxid) {
final XComponentPeer peer = (XComponentPeer)getPeer(clientComponentWindow);
if (peer == null || pData == 0)
return true;
return recreateXICNative(peer.getContentWindow(), pData);
return recreateXICNative(peer.getContentWindow(), pData, ctxid);
}
protected void releaseXIC() {
protected int releaseXIC() {
if (pData == 0)
return;
releaseXICNative(pData);
return 0;
return releaseXICNative(pData);
}
private static volatile long xicFocus;
@@ -161,8 +161,8 @@ public class XInputMethod extends X11InputMethod {
*/
private native boolean openXIMNative(long display);
private native boolean createXICNative(long window);
private native boolean recreateXICNative(long window, long px11data);
private native void releaseXICNative(long px11data);
private native boolean recreateXICNative(long window, long px11data, int ctxid);
private native int releaseXICNative(long px11data);
private native void setXICFocusNative(long window,
boolean value, boolean active);
private native void adjustStatusWindow(long window);

View File

@@ -25,6 +25,7 @@
package sun.awt;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
@@ -34,6 +35,7 @@ import java.awt.font.TextAttribute;
import java.awt.font.TextHitInfo;
import java.awt.peer.ComponentPeer;
import java.text.AttributedString;
import java.util.Map;
import sun.util.logging.PlatformLogger;
@@ -364,19 +366,21 @@ public abstract class X11InputMethod extends X11InputMethodBase {
static void recreateAllXIC() {
// NOTE: called from native within AWT_LOCK
for (X11InputMethod im : activeInputMethods)
im.releaseXIC();
Map<X11InputMethod, Integer> im2ctxid = new HashMap<>(activeInputMethods.size());
for (X11InputMethod im : activeInputMethods) {
im2ctxid.put(im, im.releaseXIC());
}
if (!recreateX11InputMethod()) {
log.warning("can't recreate X11 InputMethod");
return;
}
for (X11InputMethod im : activeInputMethods) {
if (!im.recreateXIC())
if (!im.recreateXIC(im2ctxid.get(im)))
log.warning("can't recreate XIC for " + im.toString());
}
}
protected abstract boolean recreateXIC();
protected abstract void releaseXIC();
protected abstract boolean recreateXIC(int ctxid);
protected abstract int releaseXIC();
private static native boolean recreateX11InputMethod();
}

View File

@@ -1426,21 +1426,35 @@ finally:
JNIEXPORT jboolean JNICALL
Java_sun_awt_X11_XInputMethod_recreateXICNative(JNIEnv *env,
jobject this,
jlong window, jlong pData)
jlong window, jlong pData, jint ctxid)
{
// NOTE: must be called under AWT_LOCK
return createXIC(env, (X11InputMethodData *)pData, window);
X11InputMethodData * pX11IMData = (X11InputMethodData *)pData;
jboolean result = createXIC(env, pX11IMData, window);
if (result) {
if (ctxid == 1)
pX11IMData->current_ic = pX11IMData->ic_active;
else if (ctxid == 2)
pX11IMData->current_ic = pX11IMData->ic_passive;
}
return result;
}
JNIEXPORT void JNICALL
JNIEXPORT int JNICALL
Java_sun_awt_X11_XInputMethod_releaseXICNative(JNIEnv *env,
jobject this,
jlong pData)
{
// NOTE: must be called under AWT_LOCK
X11InputMethodData * pX11IMData = (X11InputMethodData *)pData;
int result = 0;
if (pX11IMData->current_ic == pX11IMData->ic_active)
result = 1;
else if (pX11IMData->current_ic == pX11IMData->ic_passive)
result = 2;
pX11IMData->current_ic = NULL;
destroyXInputContexts(pX11IMData);
return result;
}

View File

@@ -673,7 +673,7 @@ static void checkBrokenInputMethod(XEvent * event, jboolean isEventFiltered) {
if (parsedVal > 0)
filteredEventsThreshold = parsedVal;
else if (strncmp(utf8string, "true", 4) == 0)
filteredEventsThreshold = 10;
filteredEventsThreshold = 5;
}
(*env)->ReleaseStringUTFChars(env, jvalue, utf8string);
}