Skip to content

Commit

Permalink
refactor: remove scancode mapping
Browse files Browse the repository at this point in the history
We don't actually need this.

This reverts commit 1613c45 and parts of c940750.
  • Loading branch information
WhiredPlanck committed Dec 9, 2024
1 parent a1c11df commit 19c5cab
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 437 deletions.
9 changes: 3 additions & 6 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,29 @@ 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), up)
}
}
}

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, up)
}
}
}
Expand Down Expand Up @@ -470,10 +468,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))
handleRimeEvent(RimeEvent.EventType.Key, RimeEvent.KeyEvent.Data(value, modifiers, value.value, up))
}

private fun <T> handleRimeEvent(
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/java/com/osfans/trime/core/RimeApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,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 @@ -252,11 +251,7 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
sendDownKeyEvent(eventTime, keyCode, it.modifiers.metaState)
}
} else {
if (!it.up && it.unicode > 0) {
commitText(Char(it.unicode).toString())
} else {
Timber.w("Unhandled Rime KeyEvent: $it")
}
Timber.w("Unhandled Rime KeyEvent: $it")
}
}
else -> {}
Expand Down Expand Up @@ -603,7 +598,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 +620,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 @@ -724,14 +719,14 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
val charCode = event.unicodeChar
if (charCode > 0 && charCode != '\t'.code && charCode != '\n'.code) {
postRimeJob {
processKey(charCode, modifiers.modifiers, event.scanCode, up)
processKey(charCode, modifiers.modifiers, up)
}
return true
}
val keyVal = KeyValue.fromKeyEvent(event)
if (keyVal.value != RimeKeyMapping.RimeKey_VoidSymbol) {
postRimeJob {
processKey(keyVal, modifiers, event.scanCode, up)
processKey(keyVal, modifiers, up)
}
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
Loading

0 comments on commit 19c5cab

Please sign in to comment.