Skip to content

Commit

Permalink
Add support for typing C-Cedilla
Browse files Browse the repository at this point in the history
Re: #159, #165
  • Loading branch information
gujjwal00 committed Feb 3, 2024
1 parent 128cdb9 commit ddebd90
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/src/main/java/com/gaurav/avnc/ui/vnc/FrameView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
31 changes: 31 additions & 0 deletions app/src/main/java/com/gaurav/avnc/ui/vnc/KeyHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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
***********************************************************************************/
Expand Down

0 comments on commit ddebd90

Please sign in to comment.