fix(input): restore Steam and Quick Access shortcuts (#2948)

This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-11-20 14:42:52 -05:00
1 parent 3c0d25d83b
commit cb8e70b940
17 files changed
+145 -37

No files matched your search

@@ -17,7 +17,7 @@ object ControlsPresenter {
val bottomScreen: Boolean,
)
data class Plan(val place: Place, val hidden: OnScreenControls.Hidden? = null) {
data class Plan(val place: Place, val hidden: OnScreenControls.Hidden? = null, val shortcutsOnly: Boolean = false) {
val shown get() = place != Place.NONE && hidden == null
}
@@ -27,7 +27,7 @@ object ControlsPresenter {
else -> Plan(
when {
state.bottomScreen -> Place.BOTTOM
state.steamLayout -> Place.STEAM
state.steamLayout && state.mode != SessionPrefs.OSC_STEAM_QAM -> Place.STEAM
else -> Place.MAIN
},
when {
@@ -35,6 +35,7 @@ object ControlsPresenter {
state.mode == SessionPrefs.OSC_AUTO && state.controllerInUse -> OnScreenControls.Hidden.BY_CONTROLLER
else -> null
},
shortcutsOnly = state.mode == SessionPrefs.OSC_STEAM_QAM,
)
}
}
@@ -120,5 +120,7 @@ internal fun InputAction.validFor(control: InputControl): Boolean = when (this)
internal fun defaultElementAction(id: String): InputAction = when (id) {
KitLayout.DPAD_ID -> InputAction.Native()
KitLayout.KEYBOARD_ID -> InputAction.Command(InputCommand.KEYBOARD)
OnScreenLayout.STEAM_SHORTCUT_ID -> InputAction.Command(InputCommand.STEAM)
OnScreenLayout.QAM_SHORTCUT_ID -> InputAction.Command(InputCommand.QUICK_ACCESS)
else -> InputAction.Disabled
}
@@ -32,6 +32,8 @@ class OnScreenControls(context: Context, pad: PadBridge?, val dock: OnScreenLayo
private val corner = CornerButton(context)
var hidden: Hidden? = null
private set
var shortcutsOnly = false
private set
/** Holding the corner button opens DroidDeck's controller menu. */
var onCornerHold: (() -> Unit)? = null
/** The player tapped the corner button. */
@@ -56,18 +58,24 @@ class OnScreenControls(context: Context, pad: PadBridge?, val dock: OnScreenLayo
render()
}
fun setHidden(value: Hidden?) {
if (hidden == value) return
fun setPresentation(value: Hidden?, shortcuts: Boolean = false) {
if (hidden == value && shortcutsOnly == shortcuts) return
releaseAll()
hidden = value
shortcutsOnly = shortcuts
render()
}
private fun render() {
val placed = OnScreenLayout.elements(context, layout, viewWidth, viewHeight, safe, dock, cutouts,
rearButtons = SessionPrefs.oscRearButtons(context), trackpads = SessionPrefs.oscTrackpads(context))
surface.updateCustomLayout(if (hidden != null) placed.filter { it.alwaysShown } else placed)
surface.updateStyle(layout?.style ?: InputSurfaceStyle())
val style = layout?.style ?: InputSurfaceStyle()
val visible = if (hidden == null && !shortcutsOnly) placed else {
val pinned = placed.filter { it.alwaysShown && !style.hides(it) }
if (hidden != null) pinned else pinned + OnScreenLayout.steamShortcuts(viewWidth, viewHeight, safe, resources.displayMetrics.density, pinned)
}
surface.updateCustomLayout(visible)
surface.updateStyle(style)
corner.visibility = if (layout == null || dock != null) GONE else VISIBLE
corner.alpha = (layout?.style?.opacity ?: 100) / 100f
val density = resources.displayMetrics.density
@@ -148,7 +156,7 @@ class OnScreenControls(context: Context, pad: PadBridge?, val dock: OnScreenLayo
else if (armed && event.x in 0f..width.toFloat() && event.y in 0f..height.toFloat()) {
performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY)
val next = if (hidden == null) Hidden.BY_TAP else null
setHidden(next)
setPresentation(next, shortcutsOnly)
onCornerTap?.invoke(next)
}
armed = false
@@ -44,6 +44,43 @@ object OnScreenLayout {
return fit(elements, aspect(context, layout), 1f, width, height, safe)
}
internal const val STEAM_SHORTCUT_ID = "shortcut:steam"
internal const val QAM_SHORTCUT_ID = "shortcut:qam"
internal fun steamShortcuts(width: Int, height: Int, safe: Rect, density: Float,
pinned: List<InputSurfaceElement> = emptyList()): List<InputSurfaceElement> {
if (width <= 0 || height <= 0) return emptyList()
val size = min(48f * density, (width - safe.left - safe.right - 64f * density) / 2f)
if (size <= 0f || height - safe.bottom - safe.top < size) return emptyList()
val gap = 4f * density
val left = safe.left + 56f * density
val right = width - safe.right - size - gap
val middle = (left + right) / 2f
val pinnedFromBottom = pinned.sortedByDescending { it.y }
fun button(control: InputControl, id: String, leftSide: Boolean): InputSurfaceElement? {
val edge = if (leftSide) left else right
val range = if (leftSide) left..(middle - size / 2f) else (middle + size / 2f)..right
val candidates = listOf(edge) + pinned.map {
if (leftSide) (it.x + it.width) * width + gap else it.x * width - size - gap
}.filter { it in range }.sortedBy { kotlin.math.abs(it - edge) }
for (x in candidates) {
var y = max(safe.top.toFloat(), height - safe.bottom - size - gap)
for (element in pinnedFromBottom) {
if (x >= (element.x + element.width) * width || x + size <= element.x * width) continue
if (y >= (element.y + element.height) * height || y + size <= element.y * height) continue
y = element.y * height - size - gap
}
if (y >= safe.top) return InputSurfaceElement(control, x / width, y / height, size / width, size / height,
id, buttonShape = InputButtonShape.PILL).bounded()
}
return null
}
return listOfNotNull(
button(InputControl.GUIDE, STEAM_SHORTCUT_ID, leftSide = true),
button(InputControl.QAM, QAM_SHORTCUT_ID, leftSide = false),
)
}
fun editorElements(context: Context, layout: SavedInputLayout, width: Int, height: Int, edited: Boolean = false): List<InputSurfaceElement> =
elements(context, if (edited && width > 0 && height > 0) layout.copy(aspect = width.toFloat() / height) else layout, width, height, Rect())