mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 13:05:47 +00:00
fix(input): restore portrait controller layouts
This commit is contained in:
1 parent
66a4d28044
commit
97e84184ed
6 files changed
+180
-8
No files matched your search
@@ -1752,6 +1752,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
com.droiddeck.launcher.session.InputSysfsComponent.padTypeChanged(SessionPrefs.padType(id))
|
||||
padType = id
|
||||
onScreenControls?.reload()
|
||||
applyUnfoldedControls()
|
||||
unfoldedPanel?.reload()
|
||||
bottomInputControls?.reload()
|
||||
},
|
||||
backHold = backHold,
|
||||
@@ -4629,7 +4631,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
else "unfolded controls: game full screen")
|
||||
}
|
||||
val portrait = !com.droiddeck.launcher.session.SessionDisplay.foldable(this)
|
||||
val dock = if (SessionState.deckPad) com.droiddeck.launcher.input.OnScreenLayout.Dock.deck(portrait, deckPanelLayouts[com.droiddeck.launcher.input.DeckPanel.GAMEPAD])
|
||||
val kit = com.droiddeck.launcher.input.PadKit.forOverlay(this, primaryInputLayout)
|
||||
val dock = if (SessionState.deckPad && kit?.steam != false)
|
||||
com.droiddeck.launcher.input.OnScreenLayout.Dock.deck(portrait, deckPanelLayouts[com.droiddeck.launcher.input.DeckPanel.GAMEPAD])
|
||||
else com.droiddeck.launcher.input.OnScreenLayout.Dock(portrait, false)
|
||||
var panel = unfoldedPanel
|
||||
if (panel != null && (!wanted || panel.dock != dock)) {
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.graphics.Rect
|
||||
import com.droiddeck.launcher.input.GamepadGeometry.Box
|
||||
import kotlin.math.min
|
||||
|
||||
internal class ControllerPortraitGeometry(
|
||||
private val width: Float,
|
||||
private val height: Float,
|
||||
private val safe: Rect,
|
||||
private val density: Float,
|
||||
) {
|
||||
fun place(
|
||||
elements: List<InputSurfaceElement>, kit: PadKit, docked: Boolean, scale: Float,
|
||||
rearButtons: Boolean, trackpads: Boolean,
|
||||
): List<InputSurfaceElement> {
|
||||
val w = width - safe.left - safe.right
|
||||
val h = height - safe.top - safe.bottom
|
||||
if (w <= 0 || h <= 0) return elements
|
||||
val presented = elements.toMutableList()
|
||||
val buttons = mutableMapOf<String, Box>()
|
||||
val rear = presented.filter { it.control in REAR && isStock(it) }
|
||||
val pads = presented.filter { it.control.isTrackpad && isStock(it) }
|
||||
if (!docked && kit.steam) {
|
||||
if (rearButtons) REAR.forEach { addOptional(presented, it) } else presented.removeAll(rear)
|
||||
if (trackpads) {
|
||||
addOptional(presented, InputControl.LEFT_PAD)
|
||||
addOptional(presented, InputControl.RIGHT_PAD)
|
||||
} else presented.removeAll(pads)
|
||||
}
|
||||
fun put(control: InputControl, box: Box) { buttons["legacy:${control.id}"] = box }
|
||||
val reserve = if (docked) 0f else min(60f * density, h * .15f)
|
||||
val panel = if (docked) h else min(min(h * .60f, w * 1.15f) * scale, h - reserve)
|
||||
val top = height - safe.bottom - reserve - panel
|
||||
val unit = min(density, min(w / 275f, panel / 300f))
|
||||
val pad = 8f * unit
|
||||
val gap = 8f * unit
|
||||
val buttonHeight = 44f * unit
|
||||
val shoulders = if (docked) listOf(InputControl.LT, InputControl.LB, InputControl.SELECT, InputControl.START, InputControl.RB, InputControl.RT)
|
||||
else listOf(InputControl.LT, InputControl.LB, InputControl.RB, InputControl.RT)
|
||||
fun row(controls: List<InputControl>, y: Float, rowHeight: Float, spacing: Float) {
|
||||
val cell = (w - 2f * pad - (controls.size - 1) * spacing) / controls.size
|
||||
controls.forEachIndexed { index, control ->
|
||||
put(control, Box(safe.left + pad + cell / 2f + index * (cell + spacing), y, cell, rowHeight))
|
||||
}
|
||||
}
|
||||
row(shoulders, top + pad + buttonHeight / 2f, buttonHeight, 4f * unit)
|
||||
var bodyTop = top + pad + buttonHeight + gap
|
||||
if (presented.any { it.control in REAR && isStock(it) }) {
|
||||
val rearHeight = min(56f * unit, (panel - bodyTop + top) * .12f).coerceAtLeast(buttonHeight)
|
||||
row(REAR, bodyTop + rearHeight / 2f, rearHeight, gap)
|
||||
bodyTop += rearHeight + gap
|
||||
}
|
||||
val floor = height - safe.bottom - reserve - pad
|
||||
val bodyHeight = floor - bodyTop - gap
|
||||
if (bodyHeight <= 0f) return elements
|
||||
val hasLeftPad = presented.any { it.control == InputControl.LEFT_PAD && isStock(it) }
|
||||
val hasRightPad = presented.any { it.control == InputControl.RIGHT_PAD && isStock(it) }
|
||||
val hasLeftStick = presented.any { it.control == InputControl.LS && isStock(it) }
|
||||
val hasRightStick = presented.any { it.control == InputControl.RS && isStock(it) }
|
||||
val four = hasLeftPad && hasLeftStick || hasRightPad && hasRightStick
|
||||
val main = min(w * .46f, bodyHeight * .53f)
|
||||
val second = min(w * .42f, bodyHeight - main)
|
||||
val mainY = floor - main / 2f
|
||||
val secondY = bodyTop + second / 2f
|
||||
val left = safe.left + w * .25f
|
||||
val right = safe.left + w * .75f
|
||||
if (four) {
|
||||
val col = (w - 2f * pad - 3f * gap) / 4f
|
||||
val stick = min(col, main)
|
||||
put(InputControl.LEFT_PAD, Box(safe.left + pad + col * .5f, mainY, col, main))
|
||||
put(InputControl.LS, Box(safe.left + pad + col * 1.5f + gap, mainY, stick, stick))
|
||||
put(InputControl.RS, Box(safe.left + w - pad - col * 1.5f - gap, mainY, stick, stick))
|
||||
put(InputControl.RIGHT_PAD, Box(safe.left + w - pad - col * .5f, mainY, col, main))
|
||||
} else {
|
||||
put(if (hasLeftPad) InputControl.LEFT_PAD else InputControl.LS, Box(left, mainY, main, main))
|
||||
put(if (hasRightPad) InputControl.RIGHT_PAD else InputControl.RS, Box(right, mainY, main, main))
|
||||
}
|
||||
val radius = second / 2f
|
||||
val armWidth = radius * if (kit.dpad == DpadStyle.CROSS) .37f else .25f
|
||||
val inner = if (kit.dpad == DpadStyle.ARROWS) radius * .14f else armWidth
|
||||
val depth = radius - inner
|
||||
val distance = (radius + inner) / 2f
|
||||
put(InputControl.UP, Box(left, secondY - distance, armWidth * 2f, depth))
|
||||
put(InputControl.RIGHT, Box(left + distance, secondY, depth, armWidth * 2f))
|
||||
put(InputControl.DOWN, Box(left, secondY + distance, armWidth * 2f, depth))
|
||||
put(InputControl.LEFT, Box(left - distance, secondY, depth, armWidth * 2f))
|
||||
val face = second * .34f
|
||||
val spread = second * .30f
|
||||
put(InputControl.Y, Box(right, secondY - spread, face, face))
|
||||
put(InputControl.X, Box(right - spread, secondY, face, face))
|
||||
put(InputControl.B, Box(right + spread, secondY, face, face))
|
||||
put(InputControl.A, Box(right, secondY + spread, face, face))
|
||||
if (!docked) {
|
||||
val ids = listOf(KEYBOARD, "legacy:guide", "legacy:select", "legacy:start", "legacy:qam")
|
||||
.filter { id -> presented.any { it.id == id } }
|
||||
val inset = min(52f * density, w * .17f)
|
||||
val rowWidth = (w - inset - pad - gap * (ids.size - 1)) / ids.size.coerceAtLeast(1)
|
||||
val rowHeight = min(reserve * .8f, 44f * unit)
|
||||
ids.forEachIndexed { i, id ->
|
||||
val center = safe.left + inset + rowWidth / 2f + i * (rowWidth + gap)
|
||||
buttons[id] = Box(center, height - safe.bottom - reserve / 2f, rowWidth, rowHeight)
|
||||
}
|
||||
}
|
||||
return presented.map { element ->
|
||||
val box = buttons[element.id]
|
||||
if (box == null) element else element.copy(
|
||||
x = box.left / width, y = box.top / height, width = box.width / width, height = box.height / height,
|
||||
).bounded()
|
||||
}
|
||||
}
|
||||
|
||||
private fun isStock(element: InputSurfaceElement) = element.id == "legacy:${element.control.id}"
|
||||
|
||||
private fun addOptional(elements: MutableList<InputSurfaceElement>, control: InputControl) {
|
||||
if (elements.none { it.control == control && isStock(it) }) {
|
||||
elements += InputSurfaceElement(control, 0f, 0f, 0f, 0f, floating = false,
|
||||
buttonShape = InputButtonShape.PILL, showLabel = !control.isTrackpad)
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val KEYBOARD = "builtin:keyboard"
|
||||
val REAR = listOf(InputControl.L4, InputControl.L5, InputControl.R5, InputControl.R4)
|
||||
}
|
||||
}
|
||||
@@ -100,7 +100,7 @@ class OnScreenControls(context: Context, pad: PadBridge?, val dock: OnScreenLayo
|
||||
|
||||
private fun refreshAppearance() {
|
||||
val style = layout?.style ?: InputSurfaceStyle()
|
||||
val artwork = if (dock == null) PadKit.forOverlay(context, layout) else null
|
||||
val artwork = PadKit.forOverlay(context, layout)
|
||||
surface.updateStyle(style, artwork)
|
||||
quickToggle.tint = style.tint.takeUnless { artwork != null }
|
||||
quickToggle.alpha = style.opacity / 100f
|
||||
|
||||
@@ -46,15 +46,18 @@ object OnScreenLayout {
|
||||
}
|
||||
val byId = (placed + others).associateBy { it.id }
|
||||
val ordered = stored.mapNotNull { byId[it.id] } + placed.filter { p -> stored.none { it.id == p.id } }
|
||||
if (dock != null) return ordered
|
||||
val kit = PadKit.forOverlay(context, layout) ?: return ordered
|
||||
if (generated && width >= height &&
|
||||
if (generated &&
|
||||
ControllerPrefs.layout(context, reference.first.toInt(), reference.second.toInt()).isEmpty() &&
|
||||
ControllerPrefs.layout(context, width, height).isEmpty()) {
|
||||
if (dock != null || height > width) {
|
||||
return ControllerPortraitGeometry(width.toFloat(), height.toFloat(), safe, context.resources.displayMetrics.density)
|
||||
.place(ordered, kit, dock != null, layout.scale, rearButtons == true, trackpads == true)
|
||||
}
|
||||
return ControllerOverlayGeometry(width, height, safe, context.resources.displayMetrics, layout.scale)
|
||||
.place(ordered, kit, rearButtons == true, trackpads == true)
|
||||
}
|
||||
if (!kit.steam) return ordered
|
||||
if (dock != null || !kit.steam) return ordered
|
||||
return FloatingSteamOverlay(width, height, safe, context.resources.displayMetrics.density)
|
||||
.place(ordered, lowerShortcuts = generated, rearButtons = rearButtons, trackpads = trackpads)
|
||||
}
|
||||
|
||||
@@ -222,7 +222,8 @@ class InputSurfaceView(
|
||||
val source = pad?.let { InputSurfaceSource(it, inputRole, element).also { s -> elementSources += s } }
|
||||
canvas.addView(when (element.kind) {
|
||||
InputElementKind.STICK -> StickView(context, element, source, element.floating, element.hideWhenIdle && pad != null)
|
||||
InputElementKind.TRACKPAD -> TrackpadView(context, element.control == InputControl.RIGHT_PAD, captioned = element.showLabel, source = source)
|
||||
InputElementKind.TRACKPAD -> TrackpadView(context, element.control == InputControl.RIGHT_PAD, captioned = element.showLabel,
|
||||
stock = element.id == "legacy:${element.control.id}", source = source)
|
||||
InputElementKind.DPAD -> DirectionPad(context, element, source)
|
||||
else -> HoldButton(context, element, source)
|
||||
}.apply { tag = element; contentDescription = element.name; styleElement(this); source?.onStateChanged = { postInvalidate() } })
|
||||
@@ -461,7 +462,8 @@ class InputSurfaceView(
|
||||
}
|
||||
}
|
||||
|
||||
private inner class TrackpadView(context: Context, private val right: Boolean, private val captioned: Boolean = true,
|
||||
private inner class TrackpadView(context: Context, private val right: Boolean, private val captioned: Boolean,
|
||||
private val stock: Boolean,
|
||||
private val source: InputSurfaceSource? = null) : Surface(context) {
|
||||
private var gestureX = 0f
|
||||
private var gestureY = 0f
|
||||
@@ -484,7 +486,7 @@ class InputSurfaceView(
|
||||
private val glow = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
if (!captioned) {
|
||||
if (!captioned || stock && artwork?.steam == true) {
|
||||
art.trackpad(canvas, width.toFloat(), height.toFloat(), touching || clicked, fingerX, fingerY)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -277,6 +277,7 @@ class OnScreenLayoutTest {
|
||||
}
|
||||
|
||||
@Test fun theUnfoldedStripUsesTheDockGeometryInLandscapeAndPortrait() {
|
||||
SessionPrefs.setSteamController(context, SessionPrefs.CONTROLLER_NONE)
|
||||
for ((size, portrait) in listOf((2208 to 800) to false, (1080 to 1300) to true)) {
|
||||
val (w, h) = size
|
||||
val placed = OnScreenLayout.elements(context, gamepad(), w, h, Rect(), dock = OnScreenLayout.Dock(portrait, grips = true))
|
||||
@@ -304,6 +305,41 @@ class OnScreenLayoutTest {
|
||||
assertEquals(.1f * 2208f / 1768 / .2f, fitted.width * 2208 / (fitted.height * 800), .01f)
|
||||
}
|
||||
|
||||
@Test fun thePortraitAndBelowGameKitsKeepDirectionalArtClearOfTheSticksAndFaceButtons() {
|
||||
val directions = setOf(InputControl.UP, InputControl.RIGHT, InputControl.DOWN, InputControl.LEFT)
|
||||
val face = setOf(InputControl.A, InputControl.B, InputControl.X, InputControl.Y)
|
||||
val types = listOf(SessionPrefs.CONTROLLER_DECK, SessionPrefs.CONTROLLER_STEAM, SessionPrefs.CONTROLLER_XBOX360,
|
||||
SessionPrefs.CONTROLLER_DS4, SessionPrefs.CONTROLLER_DUALSENSE)
|
||||
val layout = gamepad()
|
||||
val w = 1080
|
||||
for (type in types) {
|
||||
SessionPrefs.setSteamController(context, type)
|
||||
val steam = type == SessionPrefs.CONTROLLER_DECK || type == SessionPrefs.CONTROLLER_STEAM
|
||||
val deckDock = if (steam) OnScreenLayout.Dock.deck(true, null) else OnScreenLayout.Dock(true, false)
|
||||
for ((h, dock) in listOf(1920 to null, 1300 to deckDock, 385 to deckDock)) {
|
||||
val placed = OnScreenLayout.elements(context, layout, w, h, Rect(), dock = dock,
|
||||
rearButtons = true, trackpads = true)
|
||||
assertInside(placed, w, h)
|
||||
val dpad = placed.filter { it.control in directions }
|
||||
assertEquals(4, dpad.size)
|
||||
val rightEdge = dpad.maxOf { it.x + it.width }
|
||||
val bottomEdge = dpad.maxOf { it.y + it.height }
|
||||
assertTrue(type, placed.filter { it.control in face && it.id != "builtin:keyboard" }.all { it.x > rightEdge })
|
||||
assertTrue(type, placed.filter { it.kind == InputElementKind.STICK || it.kind == InputElementKind.TRACKPAD }.all { it.y > bottomEdge })
|
||||
if (dock == null) {
|
||||
val row = placed.filter { it.control in shortcuts || it.id == "builtin:keyboard" }
|
||||
assertEquals(5, row.size)
|
||||
assertTrue(row.all { it.y > bottomEdge })
|
||||
assertEquals(steam, placed.any { it.kind == InputElementKind.TRACKPAD })
|
||||
} else {
|
||||
assertFalse(placed.any { it.control == InputControl.GUIDE || it.control == InputControl.QAM })
|
||||
assertEquals(steam, placed.any { it.kind == InputElementKind.TRACKPAD })
|
||||
assertEquals(!steam, placed.any { it.control == InputControl.RS })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val legacyKeys = "29+33:0.3,0.7,44::Find::0.6:1:1:1"
|
||||
|
||||
private fun importedOn(library: InputLibrary) = library.activeLayout(false, InputRole.PRIMARY)!!.elements.filter { it.id.startsWith("imported:") }
|
||||
@@ -399,6 +435,7 @@ class OnScreenLayoutTest {
|
||||
}
|
||||
|
||||
@Test fun aDeckStripPutsTheDeckGamepadSurfacesInTheStickSlotsAndOtherPadsKeepSticks() {
|
||||
SessionPrefs.setSteamController(context, SessionPrefs.CONTROLLER_NONE)
|
||||
val stock = InputStockLayouts.layouts().first { it.id == DeckPanel.GAMEPAD.layout }
|
||||
val deck = OnScreenLayout.Dock.deck(false, stock)
|
||||
assertEquals(OnScreenLayout.Dock(false, true, InputControl.LS, InputControl.RIGHT_PAD), deck)
|
||||
|
||||
Reference in new issue
Block a user