Skip to content

Commit

Permalink
WIP: 8221261: fix IME deadlock when using JFXPanel -- call IME handle…
Browse files Browse the repository at this point in the history
…r on AppKitThread
  • Loading branch information
kevinrushforth committed Jan 4, 2024
1 parent ade4074 commit c2cd2c1
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions src/java.desktop/macosx/classes/sun/lwawt/macosx/CInputMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,29 @@ public class CInputMethod extends InputMethodAdapter {
public CInputMethod() {
}

private void trace(String meth) {
/*
System.err.println("CInputMethod::" + meth + " : " +
"fAwtFocussedComponent = " + fAwtFocussedComponent + " " +
"fIMContext = " + fIMContext);
*/
}

private boolean isJFXPanel(Component component) {
// FIXME: need a more robust way to determine this
return "javafx.embed.swing.JFXPanel".equals(component.getClass().getName());
}

private void invokeAndWaitIME(Runnable runnable, Component component)
throws InvocationTargetException {

if (isJFXPanel(component)) {
System.err.println("Detected JFXPanel...run directly");
runnable.run();
} else {
LWCToolkit.invokeAndWait(runnable, component);
}
}

/**
* Sets the input method context, which is used to dispatch input method
Expand Down Expand Up @@ -587,7 +610,8 @@ private synchronized String attributedSubstringFromRange(final int locationIn, f
final String[] retString = new String[1];

try {
LWCToolkit.invokeAndWait(new Runnable() {
trace("attributedSubstringFromRange");
invokeAndWaitIME(new Runnable() {
public void run() { synchronized(retString) {
int location = locationIn;
int length = lengthIn;
Expand Down Expand Up @@ -639,7 +663,8 @@ private synchronized int[] selectedRange() {
final int[] returnValue = new int[2];

try {
LWCToolkit.invokeAndWait(new Runnable() {
trace("selectedRange");
invokeAndWaitIME(new Runnable() {
public void run() { synchronized(returnValue) {
AttributedCharacterIterator theIterator = fIMContext.getSelectedText(null);
if (theIterator == null) {
Expand Down Expand Up @@ -690,7 +715,8 @@ private synchronized int[] markedRange() {
final int[] returnValue = new int[2];

try {
LWCToolkit.invokeAndWait(new Runnable() {
trace("markedRange");
invokeAndWaitIME(new Runnable() {
public void run() { synchronized(returnValue) {
// The insert position is always after the composed text, so the range start is the
// insert spot less the length of the composed text.
Expand All @@ -714,7 +740,8 @@ private synchronized int[] firstRectForCharacterRange(final int absoluteTextOffs
final int[] rect = new int[4];

try {
LWCToolkit.invokeAndWait(new Runnable() {
trace("firstRectForCharacterRange");
invokeAndWaitIME(new Runnable() {
public void run() { synchronized(rect) {
int insertOffset = fIMContext.getInsertPositionOffset();
int composedTextOffset = absoluteTextOffset - insertOffset;
Expand Down Expand Up @@ -758,7 +785,8 @@ private synchronized int characterIndexForPoint(final int screenX, final int scr
final int[] insertPositionOffset = new int[1];

try {
LWCToolkit.invokeAndWait(new Runnable() {
trace("characterIndexForPoint");
invokeAndWaitIME(new Runnable() {
public void run() { synchronized(offsetInfo) {
offsetInfo[0] = fIMContext.getLocationOffset(screenX, screenY);
insertPositionOffset[0] = fIMContext.getInsertPositionOffset();
Expand Down

0 comments on commit c2cd2c1

Please sign in to comment.