Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix 20241207 #1525

Merged
merged 5 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/src/main/java/com/osfans/trime/core/KeyModifier.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ value class KeyModifiers(
val meta get() = has(KeyModifier.Meta)
val capsLock get() = has(KeyModifier.Lock)

val release get() = has(KeyModifier.Release)

val metaState: Int get() {
var metaState = 0
if (alt) metaState = KeyEvent.META_ALT_ON or KeyEvent.META_ALT_LEFT_ON
Expand Down
16 changes: 7 additions & 9 deletions app/src/main/java/com/osfans/trime/core/Rime.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,31 +77,27 @@ class Rime :
override suspend fun processKey(
value: Int,
modifiers: UInt,
code: Int,
up: Boolean,
): Boolean =
withRimeContext {
processRimeKey(value, modifiers.toInt()).also {
if (it) {
ipcResponseCallback()
} else {
keyEventCallback(KeyValue(value), KeyModifiers(modifiers), code, up)
keyEventCallback(KeyValue(value), KeyModifiers(modifiers))
}
}
}

override suspend fun processKey(
value: KeyValue,
modifiers: KeyModifiers,
code: Int,
up: Boolean,
): Boolean =
withRimeContext {
processRimeKey(value.value, modifiers.toInt()).also {
if (it) {
ipcResponseCallback()
} else {
keyEventCallback(value, modifiers, code, up)
keyEventCallback(value, modifiers)
}
}
}
Expand Down Expand Up @@ -427,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 @@ -470,10 +469,9 @@ class Rime :
private fun keyEventCallback(
value: KeyValue,
modifiers: KeyModifiers,
code: Int,
up: Boolean,
) {
handleRimeEvent(RimeEvent.EventType.Key, RimeEvent.KeyEvent.Data(value, modifiers, code, up))
val unicode = getRimeKeyUnicode(value.value)
handleRimeEvent(RimeEvent.EventType.Key, RimeEvent.KeyEvent.Data(value, modifiers, unicode))
}

private fun <T> handleRimeEvent(
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/java/com/osfans/trime/core/RimeApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,11 @@ interface RimeApi {
suspend fun processKey(
value: Int,
modifiers: UInt = 0u,
code: Int = 0,
up: Boolean = false,
): Boolean

suspend fun processKey(
value: KeyValue,
modifiers: KeyModifiers,
code: Int = 0,
up: Boolean = false,
): Boolean

suspend fun selectCandidate(idx: Int): Boolean
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/osfans/trime/core/RimeEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ sealed class RimeEvent<T>(
val value: KeyValue,
val modifiers: KeyModifiers,
val unicode: Int,
val up: Boolean,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import android.text.InputType
import android.view.InputDevice
import android.view.KeyCharacterMap
import android.view.KeyEvent
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import android.view.Window
Expand All @@ -42,7 +41,6 @@ import com.osfans.trime.core.RimeEvent
import com.osfans.trime.core.RimeKeyMapping
import com.osfans.trime.core.RimeNotification
import com.osfans.trime.core.RimeProto
import com.osfans.trime.core.ScancodeMapping
import com.osfans.trime.daemon.RimeDaemon
import com.osfans.trime.daemon.RimeSession
import com.osfans.trime.data.db.DraftHelper
Expand Down Expand Up @@ -243,16 +241,16 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
// TODO: look for better workaround for this
if (keyCode == KeyEvent.KEYCODE_ENTER) {
handleReturnKey()
return@event
return
}
val eventTime = SystemClock.uptimeMillis()
if (it.up) {
if (it.modifiers.release) {
sendUpKeyEvent(eventTime, keyCode, it.modifiers.metaState)
} else {
sendDownKeyEvent(eventTime, keyCode, it.modifiers.metaState)
}
} else {
if (!it.up && it.unicode > 0) {
if (!it.modifiers.release && it.unicode > 0) {
commitText(Char(it.unicode).toString())
} else {
Timber.w("Unhandled Rime KeyEvent: $it")
Expand Down Expand Up @@ -603,7 +601,7 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
0,
metaState,
KeyCharacterMap.VIRTUAL_KEYBOARD,
ScancodeMapping.keyCodeToScancode(keyEventCode),
0,
KeyEvent.FLAG_SOFT_KEYBOARD or KeyEvent.FLAG_KEEP_TOUCH_MODE,
InputDevice.SOURCE_KEYBOARD,
),
Expand All @@ -625,7 +623,7 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
0,
metaState,
KeyCharacterMap.VIRTUAL_KEYBOARD,
ScancodeMapping.keyCodeToScancode(keyEventCode),
0,
KeyEvent.FLAG_SOFT_KEYBOARD or KeyEvent.FLAG_KEEP_TOUCH_MODE,
InputDevice.SOURCE_KEYBOARD,
),
Expand Down Expand Up @@ -719,19 +717,18 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
}

private fun forwardKeyEvent(event: KeyEvent): Boolean {
val up = event.action == MotionEvent.ACTION_UP
val modifiers = KeyModifiers.fromKeyEvent(event)
val charCode = event.unicodeChar
if (charCode > 0 && charCode != '\t'.code) {
if (charCode > 0 && charCode != '\t'.code && charCode != '\n'.code) {
postRimeJob {
processKey(charCode, modifiers.modifiers, event.scanCode, up)
processKey(charCode, modifiers.modifiers)
}
return true
}
val keyVal = KeyValue.fromKeyEvent(event)
if (keyVal.value != RimeKeyMapping.RimeKey_VoidSymbol) {
postRimeJob {
processKey(keyVal, modifiers, event.scanCode, up)
processKey(keyVal, modifiers)
}
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import com.osfans.trime.core.KeyModifiers
import com.osfans.trime.core.Rime
import com.osfans.trime.core.RimeApi
import com.osfans.trime.core.RimeKeyMapping
import com.osfans.trime.core.ScancodeMapping
import com.osfans.trime.daemon.RimeSession
import com.osfans.trime.daemon.launchOnReady
import com.osfans.trime.data.prefs.AppPrefs
Expand Down Expand Up @@ -261,9 +260,8 @@ class CommonKeyboardActionListener(
.takeIf { it != RimeKeyMapping.RimeKey_VoidSymbol }
?: Rime.getRimeKeycodeByName(Keycode.keyNameOf(keyEventCode))
val modifiers = KeyModifiers.fromMetaState(metaState).modifiers
val code = ScancodeMapping.keyCodeToScancode(keyEventCode)
service.postRimeJob {
if (processKey(value, modifiers, code)) {
if (processKey(value, modifiers)) {
shouldReleaseKey = true
Timber.d("handleKey: processKey")
return@postRimeJob
Expand Down
93 changes: 0 additions & 93 deletions app/src/main/java/com/osfans/trime/util/GraphicUtils.kt

This file was deleted.

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
Loading