Refactor mouse-triggered Back-key interception

This commit is contained in:
Gaurav Ujjwal 2022-03-30 23:33:59 +05:30
parent bfd34747e8
commit ee49c2d1b4
5 changed files with 18 additions and 30 deletions

View file

@ -73,6 +73,8 @@ class Dispatcher(private val activity: VncActivity) {
private val swipe2Action = selectSwipeAction(gesturePref.swipe2)
private val dragAction = selectSwipeAction(gesturePref.drag)
private val mouseBackAction = selectPointAction(viewModel.pref.input.mouseBack)
private fun selectPointAction(actionName: String): (PointF) -> Unit {
return when (actionName) {
"left-click" -> { p -> defaultMode.doClick(PointerButton.Left, p) }
@ -130,6 +132,7 @@ class Dispatcher(private val activity: VncActivity) {
fun onMouseButtonUp(button: PointerButton, p: PointF) = directMode.doButtonUp(button, p)
fun onMouseMove(p: PointF) = directMode.doMovePointer(p, 0f, 0f)
fun onMouseScroll(p: PointF, hs: Float, vs: Float) = directMode.doRemoteScrollFromMouse(p, hs, vs)
fun onMouseBack(p: PointF) = mouseBackAction(p)
fun onStylusTap(p: PointF) = directMode.doClick(PointerButton.Left, p)
fun onStylusDoubleTap(p: PointF) = directMode.doDoubleClick(PointerButton.Left, p)

View file

@ -44,8 +44,7 @@ class TouchHandler(private val viewModel: VncViewModel, private val dispatcher:
fun onHoverEvent(event: MotionEvent): Boolean {
if (event.actionMasked == MotionEvent.ACTION_HOVER_MOVE) {
lastHoverPoint = event.point()
dispatcher.onMouseMove(lastHoverPoint)
dispatcher.onMouseMove(event.point())
return true
}
return false
@ -59,24 +58,9 @@ class TouchHandler(private val viewModel: VncViewModel, private val dispatcher:
}
}
//Temporary workaround for emulating mouse right-click until
//pointer-position is implemented in VncClient
private var lastHoverPoint = PointF()
private var mouseBack = viewModel.pref.input.mouseBack
fun fakeMouseClick(isDown: Boolean): Boolean {
if (mouseBack == "default")
return false
var buttonToMap = PointerButton.Right;
when (mouseBack) {
"right" -> buttonToMap = PointerButton.Right
"middle" -> buttonToMap = PointerButton.Middle
}
if (isDown) dispatcher.onMouseButtonDown(buttonToMap, lastHoverPoint)
else dispatcher.onMouseButtonUp(buttonToMap, lastHoverPoint)
return true
fun onMouseBack() {
val p = PointF(viewModel.client.pointerX.toFloat(), viewModel.client.pointerY.toFloat())
dispatcher.onMouseBack(p)
}
/****************************************************************************************

View file

@ -322,12 +322,12 @@ class VncActivity : AppCompatActivity() {
//giving apps a chance to handle it. For better or worse, they set the 'source'
//for such key events to Mouse, enabling the following workarounds.
if (keyEvent.keyCode == KeyEvent.KEYCODE_BACK &&
InputDevice.getDevice(keyEvent.deviceId).supportsSource(InputDevice.SOURCE_MOUSE)) {
val isDown = keyEvent.action == KeyEvent.ACTION_DOWN
return touchHandler.fakeMouseClick(isDown)
InputDevice.getDevice(keyEvent.deviceId).supportsSource(InputDevice.SOURCE_MOUSE) &&
viewModel.pref.input.interceptMouseBack) {
if (keyEvent.action == KeyEvent.ACTION_DOWN)
touchHandler.onMouseBack()
return true
}
return false
}
}

View file

@ -56,7 +56,8 @@ class AppPreferences(context: Context) {
val mousePassthrough; get() = prefs.getBoolean("mouse_passthrough", true)
val hideLocalCursor; get() = prefs.getBoolean("hide_local_cursor", false)
val hideRemoteCursor; get() = prefs.getBoolean("hide_remote_cursor", false)
val mouseBack; get() = prefs.getString("mouse_back", "right")!!
val mouseBack; get() = prefs.getString("mouse_back", "right-click")!!
val interceptMouseBack; get() = mouseBack != "default"
val kmLanguageSwitchToSuper; get() = prefs.getBoolean("km_language_switch_to_super", false)
val kmRightAltToSuper; get() = prefs.getBoolean("km_right_alt_to_super", false)

View file

@ -103,12 +103,12 @@
<string-array name="mouse_back_action_entries">
<item>@string/pref_mouse_back_action_default</item>
<item>@string/pref_mouse_back_action_right</item>
<item>@string/pref_mouse_back_action_middle</item>
<item>@string/pref_gesture_action_middle_click</item>
<item>@string/pref_gesture_action_right_click</item>
</string-array>
<string-array name="mouse_back_action_values">
<item>default</item>
<item>right</item>
<item>middle</item>
<item>middle-click</item>
<item>right-click</item>
</string-array>
</resources>