diff --git a/app/src/main/java/com/gaurav/avnc/ui/vnc/FrameView.kt b/app/src/main/java/com/gaurav/avnc/ui/vnc/FrameView.kt index fb82df78..800faa42 100644 --- a/app/src/main/java/com/gaurav/avnc/ui/vnc/FrameView.kt +++ b/app/src/main/java/com/gaurav/avnc/ui/vnc/FrameView.kt @@ -54,6 +54,10 @@ class FrameView(context: Context?, attrs: AttributeSet? = null) : GLSurfaceView( * Input connection used for intercepting key events */ inner class InputConnection : BaseInputConnection(this, false) { + override fun commitText(text: CharSequence?, newCursorPosition: Int): Boolean { + return keyHandler.onCommitText(text) || super.commitText(text, newCursorPosition) + } + override fun sendKeyEvent(event: KeyEvent): Boolean { return keyHandler.onKeyEvent(event) || super.sendKeyEvent(event) } diff --git a/app/src/main/java/com/gaurav/avnc/ui/vnc/KeyHandler.kt b/app/src/main/java/com/gaurav/avnc/ui/vnc/KeyHandler.kt index b08cc68b..a964f30d 100644 --- a/app/src/main/java/com/gaurav/avnc/ui/vnc/KeyHandler.kt +++ b/app/src/main/java/com/gaurav/avnc/ui/vnc/KeyHandler.kt @@ -85,6 +85,14 @@ import com.gaurav.avnc.vnc.XTKeyCode */ class KeyHandler(private val dispatcher: Dispatcher, private val cfLegacyKeysym: Boolean, prefs: AppPreferences) { + /** + * Pre-KeyEvent hook. + * This is NOT triggered for all characters. + */ + fun onCommitText(text: CharSequence?): Boolean { + return handleCCedilla(text) + } + /** * Shortcut to send both up & down events. Useful for Virtual Keys. */ @@ -313,6 +321,29 @@ class KeyHandler(private val dispatcher: Dispatcher, private val cfLegacyKeysym: return true } + /** + * 'Ç' & 'ç' requires special handling because Android generates them with extra ALT key press, + * and gives no indication in KeyEvents that accents are involved. So we have to handle these + * before events are synthesized by InputConnection in FrameView. + */ + private fun handleCCedilla(text: CharSequence?): Boolean { + if (text == "ç") { + emitForUnicodeChar('ç'.code, true) + emitForUnicodeChar('ç'.code, false) + return true + } + + if (text == "Ç") { + emitForAndroidKeyCode(KeyEvent.KEYCODE_SHIFT_LEFT, true) + emitForUnicodeChar('Ç'.code, true) + emitForUnicodeChar('Ç'.code, false) + emitForAndroidKeyCode(KeyEvent.KEYCODE_SHIFT_LEFT, false) + return true + } + + return false + } + /************************************************************************************ * Custom key-mappings ***********************************************************************************/