Allow mapping 'Back' key to 'Escape'
It provides a workaround for some devices where Escape key is hardwired to produce Back key press. But we don't want to affect the Back button in navigation Bar which is used used for disconnecting. Github Issue: #12
This commit is contained in:
parent
479dfd167d
commit
7400a38c36
4 changed files with 32 additions and 6 deletions
|
|
@ -80,11 +80,6 @@ import com.gaurav.avnc.vnc.XKeySymUnicode
|
|||
*/
|
||||
class KeyHandler(private val dispatcher: Dispatcher, private val compatMode: Boolean, prefs: AppPreferences) {
|
||||
|
||||
init {
|
||||
if (prefs.input.kmLanguageSwitchToSuper) updateKeyMap(KeyEvent.KEYCODE_LANGUAGE_SWITCH, XKeySym.XK_Super_L)
|
||||
if (prefs.input.kmRightAltToSuper) updateKeyMap(KeyEvent.KEYCODE_ALT_RIGHT, XKeySym.XK_Super_L)
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut to send both up & down events. Useful for Virtual Keys.
|
||||
*/
|
||||
|
|
@ -99,7 +94,7 @@ class KeyHandler(private val dispatcher: Dispatcher, private val compatMode: Boo
|
|||
}
|
||||
|
||||
fun onKeyEvent(event: KeyEvent): Boolean {
|
||||
return handleKeyEvent(event)
|
||||
return handleKeyEvent(preProcessEvent(event))
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -273,6 +268,28 @@ class KeyHandler(private val dispatcher: Dispatcher, private val compatMode: Boo
|
|||
return false
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Custom key-mappings
|
||||
***********************************************************************************/
|
||||
|
||||
init {
|
||||
if (prefs.input.kmLanguageSwitchToSuper) updateKeyMap(KeyEvent.KEYCODE_LANGUAGE_SWITCH, XKeySym.XK_Super_L)
|
||||
if (prefs.input.kmRightAltToSuper) updateKeyMap(KeyEvent.KEYCODE_ALT_RIGHT, XKeySym.XK_Super_L)
|
||||
}
|
||||
|
||||
// We can't map Back key to Escape inside init because we don't
|
||||
// want to affect Back key events coming from Navigation Bar.
|
||||
// So we have to test each event.
|
||||
private val kmBackToEscape = prefs.input.kmBackToEscape
|
||||
|
||||
private fun preProcessEvent(event: KeyEvent): KeyEvent {
|
||||
if (event.keyCode == KeyEvent.KEYCODE_BACK && kmBackToEscape
|
||||
&& (event.flags and KeyEvent.FLAG_VIRTUAL_HARD_KEY == 0))
|
||||
return KeyEvent(event.action, KeyEvent.KEYCODE_ESCAPE)
|
||||
|
||||
return event
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Convert String to Array of Unicode code-points
|
||||
***********************************************************************************/
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ class AppPreferences(context: Context) {
|
|||
|
||||
val kmLanguageSwitchToSuper; get() = prefs.getBoolean("km_language_switch_to_super", false)
|
||||
val kmRightAltToSuper; get() = prefs.getBoolean("km_right_alt_to_super", false)
|
||||
val kmBackToEscape; get() = prefs.getBoolean("km_back_to_escape", false)
|
||||
}
|
||||
|
||||
inner class Server {
|
||||
|
|
|
|||
|
|
@ -138,6 +138,8 @@
|
|||
<string name="pref_km">Key Mappings</string>
|
||||
<string name="pref_km_right_alt_to_super">Right Alt to Super</string>
|
||||
<string name="pref_km_language_switch_to_super">Language Switch to Super</string>
|
||||
<string name="pref_km_back_to_escape">Back to Escape</string>
|
||||
<string name="pref_km_back_to_escape_summary">Navigation Bar is not affected by this</string>
|
||||
<string name="pref_fullscreen">Use Fullscreen</string>
|
||||
<string name="pref_enable_pip">Enable Picture-in-Picture</string>
|
||||
<string name="pref_toolbar">Toolbar</string>
|
||||
|
|
|
|||
|
|
@ -110,6 +110,12 @@
|
|||
app:defaultValue="false"
|
||||
app:key="km_language_switch_to_super"
|
||||
app:title="@string/pref_km_language_switch_to_super" />
|
||||
|
||||
<SwitchPreference
|
||||
app:defaultValue="false"
|
||||
app:key="km_back_to_escape"
|
||||
app:summary="@string/pref_km_back_to_escape_summary"
|
||||
app:title="@string/pref_km_back_to_escape" />
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
Loading…
Add table
Reference in a new issue