feat: low-latency controller and touch toggles in the session drawer (#808)

This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-10-15 07:53:25 -04:00
1 parent ef8e748a94
commit 7c73adb3aa
7 files changed
+121 -22

No files matched your search

@@ -261,6 +261,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
private var drawerPage by mutableStateOf(SessionDrawerPage.CONTROLLER)
private var drawerControllerActive by mutableStateOf(false)
private var backActionsInverted by mutableStateOf(false)
private var lowLatencyController by mutableStateOf(false)
private var lowLatencyTouch by mutableStateOf(false)
private var padType by mutableStateOf(SessionPrefs.CONTROLLER_DECK)
private var pcKeyboardOpen by mutableStateOf(false)
private var achievementsInFront by mutableStateOf<AchievementsInFront?>(null)
@@ -631,6 +633,18 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
SessionPrefs.setBackActionsInverted(this@SessionActivity, inverted)
backActionsInverted = inverted
},
lowLatencyController = lowLatencyController,
lowLatencyTouch = lowLatencyTouch,
onLowLatencyController = { on ->
SessionPrefs.setLowLatencyController(this@SessionActivity, on)
lowLatencyController = on
applyLowLatency()
},
onLowLatencyTouch = { on ->
SessionPrefs.setLowLatencyTouch(this@SessionActivity, on)
lowLatencyTouch = on
applyLowLatency()
},
onOsc = { v ->
SessionPrefs.setOscMode(this@SessionActivity, v)
readPrefs()
@@ -1101,6 +1115,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
steamDownloadsInBackground = SessionPrefs.steamDownloadsInBackground(this)
oscMode = SessionPrefs.oscMode(this)
backActionsInverted = SessionPrefs.backActionsInverted(this)
lowLatencyController = SessionPrefs.lowLatencyController(this)
lowLatencyTouch = SessionPrefs.lowLatencyTouch(this)
padType = SessionPrefs.steamController(this)
}
@@ -2442,8 +2458,16 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
super.onAttachedToWindow()
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) return
val decor = window.decorView
decor.requestUnbufferedDispatch(UNBUFFERED_SOURCES)
decor.viewTreeObserver.addOnGlobalFocusChangeListener { _, _ -> decor.post { decor.requestUnbufferedDispatch(UNBUFFERED_SOURCES) } }
decor.requestUnbufferedDispatch(unbufferedSources())
decor.viewTreeObserver.addOnGlobalFocusChangeListener { _, _ -> decor.post { decor.requestUnbufferedDispatch(unbufferedSources()) } }
}
private fun unbufferedSources() =
if (lowLatencyTouch) UNBUFFERED_SOURCES or InputDevice.SOURCE_CLASS_POINTER else UNBUFFERED_SOURCES
private fun applyLowLatency() {
com.droiddeck.launcher.input.FakeInputWriter.setLowLatency(lowLatencyController, lowLatencyTouch)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) window.decorView.requestUnbufferedDispatch(unbufferedSources())
}
override fun onWindowFocusChanged(hasFocus: Boolean) {
@@ -79,6 +79,10 @@ public class FakeInputWriter {
private static final int DECK_CONTROLS_OFFSET = IMU_OFFSET + 40;
private static final int PAD_TYPE_OFFSET = IMU_OFFSET + 44;
private static final int PAD_TYPE_SET = 0x80000000;
private static final int LATENCY_OFFSET = IMU_OFFSET + 48;
public static final int LATENCY_CONTROLLER = 1;
public static final int LATENCY_TOUCH = 2;
private static volatile int latency = 0;
public static final int PAD_TYPE_DECK = 0;
public static final int PAD_TYPE_STEAM = 1;
public static final int PAD_TYPE_XBOX = 2;
@@ -214,6 +218,7 @@ public class FakeInputWriter {
data.putInt(DECK_CONTROLS_OFFSET, 0);
int type = padType;
data.putInt(PAD_TYPE_OFFSET, type >= 0 ? PAD_TYPE_SET | type : 0);
data.putInt(LATENCY_OFFSET, latency);
data.putInt(TRITON_OFFSET, TRITON_MAGIC);
data.putInt(TRITON_CONNECTED_OFFSET, tritonConnected ? 1 : 0);
data.putLong(TRITON_INPUT_SEQ_OFFSET, 0L);
@@ -514,6 +519,22 @@ public class FakeInputWriter {
}
}
public static void setLowLatency(boolean controller, boolean touch) {
int flags = (controller ? LATENCY_CONTROLLER : 0) | (touch ? LATENCY_TOUCH : 0);
latency = flags;
RingSlot ringSlot;
synchronized (RING_LOCK) {
ringSlot = RING_SLOTS[0];
}
if (ringSlot == null) return;
synchronized (ringSlot) {
ByteBuffer ring = ringSlot.data;
if (ring == null) return;
nativeStoreFence();
ring.putInt(LATENCY_OFFSET, flags);
}
}
public static void setTritonConnected(int slot, boolean connected) {
tritonConnected = connected;
RingSlot ringSlot = tritonSlot(slot);
@@ -130,6 +130,18 @@ object SessionPrefs {
private fun mangoappSession(context: Context) =
SessionState.mode == SessionService.MODE_STEAM && mangoapp(context)
fun lowLatencyController(context: Context): Boolean = prefs(context).getBoolean("lowLatencyController", false)
fun setLowLatencyController(context: Context, on: Boolean) {
prefs(context).edit().putBoolean("lowLatencyController", on).apply()
}
fun lowLatencyTouch(context: Context): Boolean = prefs(context).getBoolean("lowLatencyTouch", false)
fun setLowLatencyTouch(context: Context, on: Boolean) {
prefs(context).edit().putBoolean("lowLatencyTouch", on).apply()
}
fun backActionsInverted(context: Context): Boolean = prefs(context).getBoolean("backActionsInverted", false)
fun setBackActionsInverted(context: Context, inverted: Boolean) {
@@ -610,6 +610,7 @@ class SessionService : Service() {
SessionState.deckPad = deckBinds.isNotEmpty()
if (wantsDeck && !SessionState.deckPad) Log.w(TAG, "deck pad: not available this session; the pad stays an Xbox 360 controller")
logControllersAtStart()
com.droiddeck.launcher.input.FakeInputWriter.setLowLatency(SessionPrefs.lowLatencyController(this), SessionPrefs.lowLatencyTouch(this))
if (uinput) {
guest.add("FAKE_EVDEV_UINPUT=1")
if (SessionState.deckPad) {
@@ -233,6 +233,10 @@ class DrawerActions(
val onSuspendPolicy: (String) -> Unit,
val onSteamDownloadsInBackground: (Boolean) -> Unit = {},
val onBackActionsInverted: (Boolean) -> Unit,
val lowLatencyController: Boolean = false,
val lowLatencyTouch: Boolean = false,
val onLowLatencyController: (Boolean) -> Unit = {},
val onLowLatencyTouch: (Boolean) -> Unit = {},
val onTouch: (String) -> Unit,
val onFexPreset: (String) -> Unit,
val onUpscaler: (Int) -> Unit = {},
@@ -497,6 +501,14 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
stringResource(R.string.unfolded_controls_hint), a.unfoldedControls,
chipModifier = focus.track(page, "unfolded-controls"), onChange = a.onUnfoldedControls)
}
SettingsGroup(stringResource(R.string.drawer_latency)) {
ToggleRow(host, "low-latency-controller", stringResource(R.string.drawer_low_latency_controller),
stringResource(R.string.drawer_low_latency_controller_hint), a.lowLatencyController,
chipModifier = focus.track(page, "low-latency-controller"), onChange = a.onLowLatencyController)
ToggleRow(host, "low-latency-touch", stringResource(R.string.drawer_low_latency_touch),
stringResource(R.string.drawer_low_latency_touch_hint), a.lowLatencyTouch,
chipModifier = focus.track(page, "low-latency-touch"), onChange = a.onLowLatencyTouch)
}
SettingsGroup(stringResource(R.string.drawer_keyboard)) {
Row(horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.fillMaxWidth().padding(8.dp)) {
DrawerOutlineButton(stringResource(R.string.drawer_pc_keyboard), modifier = Modifier.weight(1f).height(48.dp).then(focus.track(page, "hardware"))) {