mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
fix(input): reach full guest screen with glasses pointer (#2145)
fix: the glasses pointer reaches the whole guest screen Absolute input was clamped to the letterboxed picture rect computed for the phone view, while the compositor reads the input space against the glasses output. With different shapes that limited the guest pointer to a middle band of the scene, so the bottom and top edges were unreachable. Send absolute pointer positions as the full-view fraction (the compositor already clamps to the scene) and use the whole view for the touchpad bounds and relative scale while the glasses own the output. Fixes #2055 Co-authored-by: Moroni Granja <moronigranja@gmail.com>
This commit is contained in:
1 parent
d64205ba5b
commit
5624b483fb
3 files changed
+73
-12
No files matched your search
@@ -85,6 +85,7 @@ import com.droiddeck.launcher.input.SteamControllerBle
|
||||
import com.droiddeck.launcher.input.DirectTouchHold
|
||||
import com.droiddeck.launcher.input.GestureTouchStreamGate
|
||||
import com.droiddeck.launcher.input.PointerGestures
|
||||
import com.droiddeck.launcher.input.PointerSpace
|
||||
import com.droiddeck.launcher.input.SecondScreenDisplay
|
||||
import com.droiddeck.launcher.input.SecondScreenDisplays
|
||||
import com.droiddeck.launcher.input.SecondScreenMode
|
||||
@@ -2980,7 +2981,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
|
||||
private val gestureOutput = object : TouchscreenGestures.Output {
|
||||
override fun moveTo(x: Float, y: Float) {
|
||||
val rect = drawnRect() ?: return
|
||||
val rect = pointerSurfaceRect() ?: return
|
||||
if (pointerLocked) {
|
||||
if (gesturePointerReady) moveBy(x - gesturePointerX, y - gesturePointerY, true)
|
||||
} else movePointer(x, y)
|
||||
@@ -2990,7 +2991,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
cursorVisible = false
|
||||
}
|
||||
override fun moveBy(dx: Float, dy: Float, relative: Boolean) {
|
||||
val rect = drawnRect() ?: return
|
||||
val rect = (if (pointerLocked) drawnRect() else pointerSurfaceRect()) ?: return
|
||||
if (relative || pointerLocked) {
|
||||
val scale = sceneScale(rect)
|
||||
sendSceneDelta(dx * scale, dy * scale)
|
||||
@@ -3001,7 +3002,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
}
|
||||
override fun prepareRelativePan() {
|
||||
if (pointerLocked) return
|
||||
val rect = drawnRect() ?: return
|
||||
val rect = pointerSurfaceRect() ?: return
|
||||
moveTo(rect.centerX(), rect.centerY())
|
||||
}
|
||||
override fun key(code: Int, down: Boolean) {
|
||||
@@ -3045,7 +3046,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
|
||||
private val scrollListener = object : ScrollTouchGestures.Listener {
|
||||
override fun onMove(x: Float, y: Float) {
|
||||
val rect = drawnRect() ?: return
|
||||
val rect = pointerSurfaceRect() ?: return
|
||||
val cx = x.coerceIn(rect.left, rect.right)
|
||||
val cy = y.coerceIn(rect.top, rect.bottom)
|
||||
WaylandCompositor.nativeSendPointer(1, InputSpace.x(cx, outputView().width), InputSpace.y(cy, outputView().height))
|
||||
@@ -3055,7 +3056,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
WaylandCompositor.nativeSendSceneInput(3, button, if (pressed) 1 else 0)
|
||||
}
|
||||
override fun onScroll(dx: Float, dy: Float) {
|
||||
val rect = drawnRect() ?: return
|
||||
val rect = pointerSurfaceRect() ?: return
|
||||
val out = SessionState.outputSize
|
||||
scrollRestX += dx * out.first / rect.width()
|
||||
scrollRestY += dy * out.second / rect.height()
|
||||
@@ -3074,7 +3075,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
override fun onScrollStart() {
|
||||
scrollRestX = 0f
|
||||
scrollRestY = 0f
|
||||
val rect = drawnRect() ?: return
|
||||
val rect = pointerSurfaceRect() ?: return
|
||||
val x = rect.left + rect.width() * PAD_SCROLL_POINTER_X
|
||||
WaylandCompositor.nativeSendPointer(1, InputSpace.x(x, outputView().width), InputSpace.y(rect.centerY(), outputView().height))
|
||||
cursorVisible = false
|
||||
@@ -3087,7 +3088,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
override fun onNavigate() {
|
||||
cursorVisible = false
|
||||
}
|
||||
override fun scrollSpeed(): Float = (drawnRect()?.height() ?: 0f) * PAD_SCROLL_HEIGHTS_PER_S
|
||||
override fun scrollSpeed(): Float = (pointerSurfaceRect()?.height() ?: 0f) * PAD_SCROLL_HEIGHTS_PER_S
|
||||
}
|
||||
|
||||
private fun padMouseMode(): Boolean {
|
||||
@@ -3105,7 +3106,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
(routedTouchMode == SessionPrefs.TOUCH_AUTO || routedTouchMode == SessionPrefs.TOUCH_DIRECT) && padMouseMode()
|
||||
|
||||
private fun fingerScroll(dx: Float, dy: Float) {
|
||||
val rect = drawnRect() ?: return
|
||||
val rect = pointerSurfaceRect() ?: return
|
||||
val out = SessionState.outputSize
|
||||
scrollRestX += dx * out.first / rect.width() * AXIS_UNITS_PER_PIXEL
|
||||
scrollRestY += dy * out.second / rect.height() * AXIS_UNITS_PER_PIXEL
|
||||
@@ -3128,7 +3129,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
if (!WaylandCompositor.nativeCursorInputPos(cursorPosBuf)) return
|
||||
val x = cursorPosBuf[0] / InputSpace.WIDTH.toFloat() * outputView().width
|
||||
val y = cursorPosBuf[1] / InputSpace.HEIGHT.toFloat() * outputView().height
|
||||
if (rect.contains(x, y)) touchpad.place(x, y)
|
||||
touchpad.place(x.coerceIn(rect.left, rect.right), y.coerceIn(rect.top, rect.bottom))
|
||||
}
|
||||
|
||||
private fun moveLockedPointer(x: Float, y: Float) {
|
||||
@@ -3140,7 +3141,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
}
|
||||
|
||||
private fun movePointer(x: Float, y: Float, fromMouse: Boolean = false) {
|
||||
val rect = drawnRect() ?: return
|
||||
val rect = pointerSurfaceRect() ?: return
|
||||
val cx = x.coerceIn(rect.left, rect.right)
|
||||
val cy = y.coerceIn(rect.top, rect.bottom)
|
||||
WaylandCompositor.nativeSendPointer(1, InputSpace.x(cx, outputView().width), InputSpace.y(cy, outputView().height))
|
||||
@@ -3511,7 +3512,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
if (width <= 0f || height <= 0f) return
|
||||
val nx = (x / width).coerceIn(0f, 1f)
|
||||
val ny = (y / height).coerceIn(0f, 1f)
|
||||
val rect = drawnRect() ?: return
|
||||
val rect = pointerSurfaceRect() ?: return
|
||||
val px = rect.left + nx * rect.width()
|
||||
val py = rect.top + ny * rect.height()
|
||||
WaylandCompositor.nativeSendPointer(1, InputSpace.x(px, outputView().width), InputSpace.y(py, outputView().height))
|
||||
@@ -3694,6 +3695,16 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
return android.graphics.RectF(left, top, left + drawnW, top + drawnH)
|
||||
}
|
||||
|
||||
/**
|
||||
* Where the pointer can travel on this view. With the glasses owning the output the view is
|
||||
* not showing the picture, so the whole view is the touchpad; using the letterboxed picture
|
||||
* rect there would leave the pointer unable to reach the scene edges.
|
||||
*/
|
||||
private fun pointerSurfaceRect(): android.graphics.RectF? {
|
||||
val view = outputView()
|
||||
return PointerSpace.area(view.width, view.height, glassesOutputActive, drawnRect())
|
||||
}
|
||||
|
||||
private var ignoreGameTouch = false
|
||||
private var touchEditorOpen by mutableStateOf(false)
|
||||
private var lockedSwipeUsed = false
|
||||
@@ -3755,7 +3766,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
if (threeFingerTap.active || wasActive) return true
|
||||
}
|
||||
if (route == com.droiddeck.launcher.input.TouchRouter.Route.TOUCHPAD) {
|
||||
val rect = drawnRect() ?: return false
|
||||
val rect = (if (pointerLocked) drawnRect() else pointerSurfaceRect()) ?: return false
|
||||
if (touchpad.bounds != rect) {
|
||||
val fresh = touchpad.bounds.width() <= 1f
|
||||
touchpad.bounds = rect
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.graphics.RectF
|
||||
|
||||
/**
|
||||
* The area of the session view that drives the guest pointer.
|
||||
*
|
||||
* The view is also the compositor output only while it shows the picture: the phone, or the
|
||||
* bottom screen. With the glasses owning the output the view is a touchpad for a scene drawn
|
||||
* elsewhere, so the whole view has to drive the pointer. Using the picture rect there would
|
||||
* confine it to the letterboxed band the scene would occupy on the phone, and the pointer could
|
||||
* not reach the scene edges.
|
||||
*/
|
||||
object PointerSpace {
|
||||
fun area(viewWidth: Int, viewHeight: Int, glassesOwnOutput: Boolean, picture: RectF?): RectF? {
|
||||
if (viewWidth <= 0 || viewHeight <= 0) return null
|
||||
if (glassesOwnOutput) return RectF(0f, 0f, viewWidth.toFloat(), viewHeight.toFloat())
|
||||
return picture
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user