Skip to content

Commit

Permalink
Don't highlight for dead keys
Browse files Browse the repository at this point in the history
  • Loading branch information
tsayao committed Sep 3, 2023
1 parent 3b80ba5 commit 5d6bd04
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,16 @@ protected void _finishInputMethodComposition(long ptr) {
//nothing
}

protected void notifyInputMethodLinux(String str, int attrib, int length, int cursor) {
if (attrib == 4) {
// attrib == 4 means we are going to commit changes, so commitLength should be non-zero
protected void notifyInputMethodLinux(String str, boolean commit, int length, int cursor, byte[] attr) {
if (commit) {
notifyInputMethod(str, null, null, null, length, cursor, 0);
} else {
int[] boundary = new int[length + 1];
byte[] values = new byte[length + 1];

for (int i = 0; i < boundary.length; i++) {
boundary[i] = i;
values[i] = IME_ATTR_TARGET_NOTCONVERTED;
}

notifyInputMethod(str, boundary, boundary, values, 0, cursor, 0);
notifyInputMethod(str, boundary, boundary, attr, 0, cursor, 0);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ JNI_OnLoad(JavaVM *jvm, void *reserved)

clazz = env->FindClass("com/sun/glass/ui/gtk/GtkView");
if (env->ExceptionCheck()) return JNI_ERR;
jViewNotifyInputMethodLinux = env->GetMethodID(clazz, "notifyInputMethodLinux", "(Ljava/lang/String;III)V");
jViewNotifyInputMethodLinux = env->GetMethodID(clazz, "notifyInputMethodLinux", "(Ljava/lang/String;ZII[B)V");
if (env->ExceptionCheck()) return JNI_ERR;

clazz = env->FindClass("com/sun/glass/ui/Window");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ struct jni_exception: public std::exception {
extern jmethodID jViewNotifyDragDrop; //com.sun.glass.ui.View#notifyDragDrop (IIIII)I
extern jmethodID jViewNotifyDragLeave; //com.sun.glass.ui.View#notifyDragLeave ()V
extern jmethodID jViewNotifyScroll; //com.sun.glass.ui.View#notifyScroll (IIIIDDIIIIIDD)V
extern jmethodID jViewNotifyInputMethodLinux; //com.sun.glass.ui.View#notifyInputMethodLinux ((Ljava/lang/String;IIIII)V
extern jmethodID jViewNotifyInputMethodLinux; //com.sun.glass.ui.View#notifyInputMethodLinux (Ljava/lang/String;ZII[B)V
extern jmethodID jViewNotifyInputMethodCandidateRelativePosRequest; //com.sun.glass.ui.View#notifyInputMethodCandidateRelativePosRequest (I)[D

extern jmethodID jViewNotifyMenu; //com.sun.glass.ui.View#notifyMenu (IIIIZ)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,52 @@
void on_preedit_start(GtkIMContext *im_context, gpointer user_data) {
WindowContext *ctx = (WindowContext *) user_data;
ctx->setOnPreEdit(true);
g_print("on_preedit_start\n");
}

void on_preedit_changed(GtkIMContext *im_context, gpointer user_data) {
gchar *preedit_text;
WindowContext *ctx = (WindowContext *) user_data;
jbyteArray attr = NULL;

gtk_im_context_get_preedit_string(im_context, &preedit_text, NULL, NULL);
ctx->updateCaretPos();

jstring jstr = mainEnv->NewStringUTF(preedit_text);
EXCEPTION_OCCURED(mainEnv);
g_free(preedit_text);

jsize slen = mainEnv->GetStringLength(jstr);

g_print("on_preedit_changed: %s - %d\n", preedit_text, slen);
attr = mainEnv->NewByteArray(slen);
CHECK_JNI_EXCEPTION(mainEnv)
jbyte v[slen];
for (int i = 0; i < slen; i++) {
gunichar chr = g_utf8_get_char(&preedit_text[i]);

if (g_unichar_type(chr) == G_UNICODE_MODIFIER_SYMBOL) {
v[i] = com_sun_glass_ui_View_IME_ATTR_CONVERTED;
} else {
v[i] = com_sun_glass_ui_View_IME_ATTR_TARGET_NOTCONVERTED;
}
}

g_free(preedit_text);

mainEnv->SetByteArrayRegion(attr, 0, slen, v);
CHECK_JNI_EXCEPTION(mainEnv)

mainEnv->CallVoidMethod(ctx->get_jview(),
jViewNotifyInputMethodLinux,
jstr,
0,
false,
slen,
0);
0,
attr);
LOG_EXCEPTION(mainEnv)
}

void on_preedit_end(GtkIMContext *im_context, gpointer user_data) {
WindowContext *ctx = (WindowContext *) user_data;
ctx->setOnPreEdit(false);
g_print("on_preedit_end\n");
}

void on_commit(GtkIMContext *im_context, gchar* str, gpointer user_data) {
Expand All @@ -72,9 +87,7 @@ void on_commit(GtkIMContext *im_context, gchar* str, gpointer user_data) {
}

void WindowContextBase::commitIME(gchar *str) {
g_print("commitIME: %s\n", str);
if (!im_ctx.on_preedit) {
g_print("not on preedit: %s\n", str);
jchar key = g_utf8_get_char(str);
guint key_val = gdk_unicode_to_keyval(key);

Expand Down Expand Up @@ -102,13 +115,13 @@ void WindowContextBase::commitIME(gchar *str) {
EXCEPTION_OCCURED(mainEnv);
jsize slen = mainEnv->GetStringLength(jstr);

g_print("jViewNotifyInputMethodLinux: %s\n", str);
mainEnv->CallVoidMethod(jview,
jViewNotifyInputMethodLinux,
jstr,
4,
true,
slen,
slen,
slen);
NULL);
LOG_EXCEPTION(mainEnv)
}
}
Expand Down Expand Up @@ -137,7 +150,6 @@ void WindowContextBase::updateCaretPos() {
0);

nativePos = mainEnv->GetDoubleArrayElements(pos, NULL);
g_print("updateCaretPos POS: %f, %f\n", nativePos[0], nativePos[1]);

GdkRectangle rect;
if (nativePos) {
Expand Down

0 comments on commit 5d6bd04

Please sign in to comment.