Reduce on-screen stick load and honour Low latency off (#2048)

* Reduce on-screen stick load and honour Low latency off

On-screen controls requested unbuffered touch on every press, so turning
Low latency off had no effect on them. They now follow the setting.

Every stick move also redrew the whole overlay. Redraws during movement are
capped at 30 per second in both overlays, and stick moves under a pixel
are dropped in the standard overlay.

* Keep full stick deflection reachable

Moves under a pixel were dropped even at the edge of the stick, so the pad
could stop just short of full range.
This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-11-03 16:12:08 -05:00
1 parent ad90d9e200
commit f3650d3d37
3 files changed
+46 -11

No files matched your search

@@ -13,6 +13,7 @@ import android.view.HapticFeedbackConstants
import android.view.MotionEvent
import android.view.View
import android.view.WindowInsets
import com.droiddeck.launcher.session.SessionPrefs
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
@@ -59,15 +60,20 @@ class OnScreenControls(
return dx * dx + dy * dy <= hit * hit
}
fun drag(x: Float, y: Float) {
fun drag(x: Float, y: Float): Boolean {
var dx = x - ax
var dy = y - ay
val d = sqrt(dx * dx + dy * dy)
if (d > radius) { dx = dx / d * radius; dy = dy / d * radius }
val atLimit = d > radius
if (atLimit) { dx = dx / d * radius; dy = dy / d * radius }
if (!atLimit && abs(dx - kx) < MIN_STICK_MOVE_PX && abs(dy - ky) < MIN_STICK_MOVE_PX) return false
kx = dx; ky = dy; dirty = true
return true
}
}
private val stickRedraw = ThrottledRedraw(this, STICK_REDRAW_MS)
private val controls = listOf(
Control("up", "dpad", -1, 26f, 0f, -52f),
Control("right", "dpad", -1, 26f, 52f, 0f),
@@ -211,6 +217,7 @@ class OnScreenControls(
}
override fun onDetachedFromWindow() {
stickRedraw.cancel()
releaseAll()
super.onDetachedFromWindow()
}
@@ -542,7 +549,7 @@ class OnScreenControls(
control.ay = if (adaptive) event.getY(index) else control.cy
control.drag(event.getX(index), event.getY(index))
}
requestUnbufferedDispatch(event)
if (SessionPrefs.lowLatency(context)) requestUnbufferedDispatch(event)
apply()
return true
}
@@ -551,13 +558,14 @@ class OnScreenControls(
if (keyboardPressedBy != -1) return true
if (quickPressedBy != -1) return true
var changed = false
var stickMoved = false
for (index in 0 until event.pointerCount) {
val pointer = event.getPointerId(index)
if (forwardedPointerBits and (1 shl pointer) != 0) continue
val x = event.getX(index)
val y = event.getY(index)
val stick = controls.firstOrNull { it.stick >= 0 && it.pressedBy == pointer }
if (stick != null) { stick.drag(x, y); changed = true; continue }
if (stick != null) { stickMoved = stick.drag(x, y) || stickMoved; continue }
val over = controlAt(x, y)?.takeIf { it.stick < 0 }
for (control in controls) {
if (control.stick < 0 && control.pressedBy == pointer && control !== over) {
@@ -570,7 +578,7 @@ class OnScreenControls(
changed = true
}
}
if (changed) apply()
if (changed) apply() else if (stickMoved) apply(stickOnly = true)
return true
}
MotionEvent.ACTION_UP, MotionEvent.ACTION_POINTER_UP, MotionEvent.ACTION_CANCEL -> {
@@ -704,7 +712,7 @@ class OnScreenControls(
else -> control.target != ControllerPrefs.OFF
}
private fun apply() {
private fun apply(stickOnly: Boolean = false) {
val bridge = pad
if (bridge == null || editing) { invalidate(); return }
val qamHeld = controls.any { it.id == "qam" && it.pressedBy != -1 }
@@ -736,7 +744,7 @@ class OnScreenControls(
for (target in used) write(state, target, target in held)
}
}
invalidate()
if (stickOnly) stickRedraw.request() else invalidate()
}
private fun write(state: PadState, target: String, down: Boolean) {
@@ -778,6 +786,8 @@ class OnScreenControls(
private companion object {
const val DOUBLE_TAP_MS = 300L
const val STICK_REDRAW_MS = 33L
const val MIN_STICK_MOVE_PX = 1f
const val MIN_FACE_MM = 9.5f
const val FULL_SIZE_HEIGHT_MM = 85f
const val BOTTOM_MARGIN_MM = 5f
@@ -139,6 +139,7 @@ class SteamTouchControls(
override fun onDetachedFromWindow() {
handler.removeCallbacks(poll)
moveRedraw.cancel()
sensors.unregisterListener(shakeListener)
releaseAll()
super.onDetachedFromWindow()
@@ -546,7 +547,7 @@ class SteamTouchControls(
return bits
}
private fun publish() {
private fun publish(moving: Boolean = false) {
var buttons = 0L
val sticks = ShortArray(4)
val pads = ShortArray(6)
@@ -577,7 +578,7 @@ class SteamTouchControls(
}
}
device.setControls(buttons, sticks, pads)
invalidate()
if (moving) moveRedraw.request() else invalidate()
}
fun releaseAll() {
@@ -586,6 +587,8 @@ class SteamTouchControls(
invalidate()
}
private val moveRedraw = ThrottledRedraw(this, MOVE_REDRAW_MS)
private fun keepHeldFingers() {
val moved = SteamTouchConfig.remapHeld(fingers.mapValues { it.value.element?.type }, live())
fingers.keys.retainAll(moved.keys)
@@ -634,7 +637,7 @@ class SteamTouchControls(
if (forwardedPointerBits != 0) forwardPointers(event, forwardedPointerBits)
fingers[event.getPointerId(index)] = Finger(e, x, y)
if (feedback) performHapticFeedback(android.view.HapticFeedbackConstants.VIRTUAL_KEY)
requestUnbufferedDispatch(event)
if (com.droiddeck.launcher.session.SessionPrefs.lowLatency(context)) requestUnbufferedDispatch(event)
publish()
return true
}
@@ -653,7 +656,7 @@ class SteamTouchControls(
}
}
}
publish()
publish(moving = true)
return true
}
MotionEvent.ACTION_UP, MotionEvent.ACTION_POINTER_UP, MotionEvent.ACTION_CANCEL -> {
@@ -1469,6 +1472,7 @@ class SteamTouchControls(
companion object {
private const val TAG = "SteamTouch"
private const val POLL_MS = 150L
private const val MOVE_REDRAW_MS = 33L
const val BIG_PICTURE = 769
private const val ICON_PX = 128
private const val MARK_D = "M-31.98 0H56.055V40.489A71.81 71.81 0 0 0 56.055 183.231V223.72H-31.98Z" +
@@ -0,0 +1,21 @@
package com.droiddeck.launcher.input
import android.os.SystemClock
import android.view.View
internal class ThrottledRedraw(private val view: View, private val intervalMs: Long) {
private var last = 0L
private val redraw = Runnable {
last = SystemClock.uptimeMillis()
view.invalidate()
}
fun request() {
view.removeCallbacks(redraw)
view.postDelayed(redraw, (last + intervalMs - SystemClock.uptimeMillis()).coerceAtLeast(0L))
}
fun cancel() {
view.removeCallbacks(redraw)
}
}