Skip to content

Commit

Permalink
feat: add keyval unicode mapping to process unhandled-by-librime key
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiredPlanck committed Dec 9, 2024
1 parent cbf7384 commit ee0a85b
Show file tree
Hide file tree
Showing 4 changed files with 934 additions and 2 deletions.
6 changes: 5 additions & 1 deletion app/src/main/java/com/osfans/trime/core/Rime.kt
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,9 @@ class Rime :
@JvmStatic
external fun getRimeKeycodeByName(name: String): Int

@JvmStatic
external fun getRimeKeyUnicode(keycode: Int): Int

@JvmStatic
external fun getAvailableRimeSchemaList(): Array<SchemaItem>

Expand Down Expand Up @@ -467,7 +470,8 @@ class Rime :
value: KeyValue,
modifiers: KeyModifiers,
) {
handleRimeEvent(RimeEvent.EventType.Key, RimeEvent.KeyEvent.Data(value, modifiers, value.value))
val unicode = getRimeKeyUnicode(value.value)
handleRimeEvent(RimeEvent.EventType.Key, RimeEvent.KeyEvent.Data(value, modifiers, unicode))
}

private fun <T> handleRimeEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,11 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
sendDownKeyEvent(eventTime, keyCode, it.modifiers.metaState)
}
} else {
Timber.w("Unhandled Rime KeyEvent: $it")
if (!it.modifiers.release && it.unicode > 0) {
commitText(Char(it.unicode).toString())
} else {
Timber.w("Unhandled Rime KeyEvent: $it")
}
}
}
else -> {}
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/jni/librime_jni/key_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "key_table.h"

#include <rime/key_table.h>

#include "jni-utils.h"
Expand All @@ -19,3 +21,9 @@ Java_com_osfans_trime_core_Rime_getRimeKeycodeByName(JNIEnv *env,
jstring name) {
return RimeGetKeycodeByName(CString(env, name));
}

extern "C" JNIEXPORT jint JNICALL
Java_com_osfans_trime_core_Rime_getRimeKeyUnicode(JNIEnv *env, jclass clazz,
jint keycode) {
return RimeGetKeyUnicode(keycode);
}
Loading

0 comments on commit ee0a85b

Please sign in to comment.