bell-sw / LibericaNIK

Native Image Kit
4 stars 0 forks source link

Input Method Editor (IME) not working #25

Open PlusLake opened 2 months ago

PlusLake commented 2 months ago

I found that IME (input method editor) is not working. So that user in Japan / Taiwan / Korea / China may have difficulty to input. (Copy & paste is a temporary workaround)

I have tried JTextArea and JTextField and I believe others cannot work too.

https://github.com/bell-sw/LibericaNIK/assets/42900821/f9f2e6ca-3ec1-4523-a317-bcae580fbe15

At the end of the video, I clicked "Restart" on the Fcitx menu and the application crashed entirely. (I am not sure it is related or not)

Exception in thread "AWT-XAWT": java.lang.NoSuchMethodError
java.lang.NoSuchMethodError: sun.awt.X11.XInputMethod.flushText()V
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.functions.JNIFunctions$Support.getMethodID(JNIFunctions.java:1347)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.functions.JNIFunctions$Support.getMethodID(JNIFunctions.java:1332)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.functions.JNIFunctions.GetMethodID(JNIFunctions.java:434)
    at java.desktop@22.0.1/sun.awt.X11.XlibWrapper.XFilterEvent(Native Method)
    at java.desktop@22.0.1/sun.awt.X11.XToolkit.run(XToolkit.java:725)
    at java.desktop@22.0.1/sun.awt.X11.XToolkit.run(XToolkit.java:651)
    at java.base@22.0.1/java.lang.Thread.runWith(Thread.java:1583)
    at java.base@22.0.1/java.lang.Thread.run(Thread.java:1570)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:858)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:834)

Version Info

Minimal reproducible example

import javax.swing.*;
import java.awt.*;

public class Example {
    public static void main(String[] args) {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.add(new JTextArea());
        frame.setSize(new Dimension(300, 200));
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

(Appreciate for the great work on AWT! Love to see my application rendered extremelly smooth)

qq602431132 commented 1 month ago

It has been verified that fcitx-Chinese input method is also unable to input. Restarting fcitx will cause the program to crash. However, when I execute

java -agentlib:native-image-agent=config-output-dir=config -Djdk.gtk.version=2 -jar lessions.jar

and restart the fcitx input method framework, it does not crash.

native-image --no-fallback -H:+AddAllCharsets -H:ConfigurationFileDirectories=config --enable-url-protocols=https,http -Djava.awt.headless=false  --allow-incomplete-classpath -J-Xmx16G -Djdk.gtk.version=2 -jar lessions.jar
./lession

Then executing the program generated by native-image will not crash too.

export GRAALVM_HOME=/home/mxh/software/graalvm-jdk-21.0.3+7.1 export JAVA_HOME=/home/mxh/software/graalvm-jdk-21.0.3+7.1 export PATH=$JAVA_HOME/bin:$PATH export GRAALVM_HOME

Operating System: UOS Desktop 20 Professional Kernel: Linux 6.1.32-amd64-desktop-hwe Architecture: x86-64 fcitx: 1:4.2.9.32.46-1

And it seems like there should be two bugs. one is that JTextField cannot recognize Chinese IME; and the other bug is that fcitx restarts and the program crashes.(This issue can be resolved by modifying the steps.)

I also have an idea that has not been completed for verification, popping up a swing program through javafx, I wonder if this swing program can accept Chinese input? Gluon-maven-plugin does not seem to support exporting javafx+swing program.