mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 06:15:58 +00:00
feat(input): restyle Steam Deck buttons (#2966)
* feat(input): restyle Steam Deck buttons * feat(input): add Steam overlay options * fix(input): align floating overlay previews * fix(input): polish floating Steam trackpads * fix(input): restore overlay options on startup * fix(input): restore original Steam Deck artwork * fix(input): restore Steam Deck overlay geometry * fix(input): keep the Steam Deck shortcut row apart on small screens The Steam pill sits right of the keyboard by a density-based margin while Select and Start sit at unit-scaled offsets from the middle, so on a small, dense surface (800x450 at xxxhdpi) the Steam pill covered Select. Lay out Steam, Select, Start and Quick Access left to right with an 8 dp gap. * fix(input): fit the Steam Deck shortcut row inside the safe area Clamping each pill on its own after spacing could move Quick Access back onto Start when a cutout inset narrows the right side. Fit the keyboard, Steam, Select, Start and Quick Access as one row: push each right past its neighbour, pull the row back inside the right edge, and shrink the 8 dp gap only when the row would not fit otherwise. --------- Co-authored-by: K11MCH1 <81425424+K11MCH1@users.noreply.github.com>
This commit is contained in:
1 parent
4349563fd1
commit
64b7339da9
15 files changed
+785
-25
No files matched your search
@@ -0,0 +1,92 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.graphics.Rect
|
||||
import kotlin.math.min
|
||||
|
||||
internal class FloatingSteamOverlay(width: Int, height: Int, safe: Rect, density: Float) {
|
||||
private val w = width.toFloat()
|
||||
private val h = height.toFloat()
|
||||
private val left = safe.left / w
|
||||
private val top = safe.top / h
|
||||
private val right = 1f - safe.right / w
|
||||
private val bottom = 1f - safe.bottom / h
|
||||
private val gap = 3f * density
|
||||
private val bottomPadding = 14f * density
|
||||
private val dp = min(density, min(width, height) / 250f)
|
||||
|
||||
fun place(elements: List<InputSurfaceElement>, lowerShortcuts: Boolean,
|
||||
rearButtons: Boolean?, trackpads: Boolean?): List<InputSurfaceElement> {
|
||||
val visible = elements.filter { element ->
|
||||
when {
|
||||
!isStock(element) -> true
|
||||
element.control in rear -> rearButtons != false
|
||||
element.control.isTrackpad -> trackpads != false
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
val lowered = if (lowerShortcuts) lower(visible) else visible
|
||||
if (rearButtons != true && trackpads != true) return lowered
|
||||
val placed = lowered.toMutableList()
|
||||
fun add(control: InputControl, x: Float, y: List<Float>, widthDp: Int, heightDp: Int, shape: InputButtonShape) {
|
||||
if (placed.any { it.id == "legacy:${control.id}" }) return
|
||||
val element = InputSurfaceElement(control, 0f, 0f, (widthDp * dp / w).coerceAtLeast(.03f),
|
||||
(heightDp * dp / h).coerceAtLeast(.03f), floating = false, buttonShape = shape, showLabel = !control.isTrackpad)
|
||||
findSpace(element, x, y, placed)?.let(placed::add)
|
||||
}
|
||||
if (rearButtons == true) {
|
||||
add(InputControl.L4, .045f, listOf(.48f, .38f, .58f), 28, 46, InputButtonShape.PILL)
|
||||
add(InputControl.L5, .045f, listOf(.62f, .72f, .53f), 28, 46, InputButtonShape.PILL)
|
||||
add(InputControl.R4, .955f, listOf(.48f, .38f, .58f), 28, 46, InputButtonShape.PILL)
|
||||
add(InputControl.R5, .955f, listOf(.62f, .72f, .53f), 28, 46, InputButtonShape.PILL)
|
||||
}
|
||||
if (trackpads == true) {
|
||||
val rows = listOf(.45f, .36f, .54f, .27f, .63f)
|
||||
add(InputControl.LEFT_PAD, .34f, rows, 68, 63, InputButtonShape.ROUNDED)
|
||||
add(InputControl.RIGHT_PAD, .66f, rows, 68, 63, InputButtonShape.ROUNDED)
|
||||
}
|
||||
return placed
|
||||
}
|
||||
|
||||
private fun lower(elements: List<InputSurfaceElement>): List<InputSurfaceElement> {
|
||||
val row = elements.filter { isStock(it) && it.control in shortcuts }
|
||||
val occupied = (elements - row.toSet()).toMutableList()
|
||||
val moved = mutableMapOf<String, InputSurfaceElement>()
|
||||
for (element in row.sortedBy { shortcuts.getValue(it.control) }) {
|
||||
val y = bottom - bottomPadding / h - element.height / 2f
|
||||
val position = findSpace(element, shortcuts.getValue(element.control), listOf(y, y - .07f), occupied)
|
||||
?: return elements
|
||||
occupied += position
|
||||
moved[element.id] = position
|
||||
}
|
||||
return elements.map { moved[it.id] ?: it }
|
||||
}
|
||||
|
||||
private fun findSpace(element: InputSurfaceElement, x: Float, rows: List<Float>,
|
||||
occupied: List<InputSurfaceElement>): InputSurfaceElement? {
|
||||
val maxX = right - element.width
|
||||
val maxY = bottom - element.height
|
||||
if (maxX < left || maxY < top) return null
|
||||
for (y in rows) {
|
||||
for (dx in horizontalOffsets) {
|
||||
val candidate = element.copy(
|
||||
x = (x + dx - element.width / 2f).coerceIn(left, maxX),
|
||||
y = (y - element.height / 2f).coerceIn(top, maxY),
|
||||
)
|
||||
if (occupied.none { overlaps(candidate, it) }) return candidate
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
private fun overlaps(a: InputSurfaceElement, b: InputSurfaceElement): Boolean =
|
||||
a.x < b.x + b.width + gap / w && b.x < a.x + a.width + gap / w &&
|
||||
a.y < b.y + b.height + gap / h && b.y < a.y + a.height + gap / h
|
||||
|
||||
private fun isStock(element: InputSurfaceElement) = element.id == "legacy:${element.control.id}"
|
||||
|
||||
private companion object {
|
||||
val rear = setOf(InputControl.L4, InputControl.L5, InputControl.R4, InputControl.R5)
|
||||
val shortcuts = mapOf(InputControl.GUIDE to .23f, InputControl.SELECT to .41f, InputControl.START to .59f, InputControl.QAM to .77f)
|
||||
val horizontalOffsets = listOf(0f, -.035f, .035f, -.07f, .07f, -.105f, .105f)
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,9 @@ import android.view.View
|
||||
import android.view.WindowInsets
|
||||
import android.widget.FrameLayout
|
||||
import com.droiddeck.launcher.ui.InputSurfaceView
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import com.droiddeck.launcher.session.SessionService
|
||||
import com.droiddeck.launcher.session.SessionState
|
||||
|
||||
class OnScreenControls(context: Context, pad: PadBridge?, val dock: OnScreenLayout.Dock? = null) : FrameLayout(context) {
|
||||
private val surface = InputSurfaceView(context, pad, inputRole = InputRole.PRIMARY, haptics = dock != null)
|
||||
@@ -77,7 +80,10 @@ class OnScreenControls(context: Context, pad: PadBridge?, val dock: OnScreenLayo
|
||||
private fun placed(): List<InputSurfaceElement> {
|
||||
val key = Placement(layout, viewWidth, viewHeight, Rect(safe), isButtonsOnly)
|
||||
return placements.getOrPut(key) {
|
||||
OnScreenLayout.elements(context, layout, viewWidth, viewHeight, safe, isButtonsOnly, dock)
|
||||
val steam = SessionState.mode == SessionService.MODE_STEAM && SessionState.deckPad
|
||||
OnScreenLayout.elements(context, layout, viewWidth, viewHeight, safe, isButtonsOnly, dock,
|
||||
rearButtons = SessionPrefs.oscRearButtons(context).takeIf { steam },
|
||||
trackpads = SessionPrefs.oscTrackpads(context).takeIf { steam })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,11 +94,16 @@ class OnScreenControls(context: Context, pad: PadBridge?, val dock: OnScreenLayo
|
||||
isQuickHidden -> elements.filter { it.id == "builtin:keyboard" || it.alwaysShown }
|
||||
else -> elements
|
||||
})
|
||||
val style = layout?.style ?: InputSurfaceStyle()
|
||||
surface.updateStyle(style)
|
||||
quickToggle.tint = style.tint
|
||||
quickToggle.alpha = style.opacity / 100f
|
||||
quickToggle.visibility = if (isButtonsOnly || isPinnedOnly || layout == null || dock != null) GONE else VISIBLE
|
||||
refreshAppearance()
|
||||
}
|
||||
|
||||
private fun refreshAppearance() {
|
||||
val style = layout?.style ?: InputSurfaceStyle()
|
||||
val deck = dock == null && OnScreenLayout.usesSteamDeckButtons(context, layout)
|
||||
surface.updateStyle(style, steamDeckButtons = deck)
|
||||
quickToggle.tint = style.tint.takeUnless { deck }
|
||||
quickToggle.alpha = style.opacity / 100f
|
||||
quickToggle.invalidate()
|
||||
}
|
||||
|
||||
|
||||
@@ -2,12 +2,20 @@ package com.droiddeck.launcher.input
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Rect
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
object OnScreenLayout {
|
||||
internal fun usesSteamDeckButtons(context: Context, layout: SavedInputLayout?) =
|
||||
layout?.id == InputLibraries.OVERLAY && SessionPrefs.steamController(context) == SessionPrefs.CONTROLLER_DECK
|
||||
|
||||
internal fun supportsFloatingSteamControls(controller: String, layout: SavedInputLayout?) =
|
||||
layout?.id == InputLibraries.OVERLAY &&
|
||||
(controller == SessionPrefs.CONTROLLER_DECK || controller == SessionPrefs.CONTROLLER_STEAM)
|
||||
|
||||
data class Dock(val portrait: Boolean, val grips: Boolean, val left: InputControl = InputControl.LS, val right: InputControl = InputControl.RS) {
|
||||
companion object {
|
||||
fun deck(portrait: Boolean, gamepad: SavedInputLayout?): Dock {
|
||||
@@ -25,7 +33,8 @@ object OnScreenLayout {
|
||||
private const val KEYBOARD_ID = "builtin:keyboard"
|
||||
|
||||
fun elements(context: Context, layout: SavedInputLayout?, width: Int, height: Int, safe: Rect,
|
||||
buttonsOnly: Boolean = false, dock: Dock? = null): List<InputSurfaceElement> {
|
||||
buttonsOnly: Boolean = false, dock: Dock? = null, rearButtons: Boolean? = null,
|
||||
trackpads: Boolean? = null): List<InputSurfaceElement> {
|
||||
val stored = layout?.elements ?: return emptyList()
|
||||
if (width <= 0 || height <= 0) return stored
|
||||
val generator = LegacyGamepadLayout(context, width, height, safe, layout.scale)
|
||||
@@ -39,7 +48,16 @@ object OnScreenLayout {
|
||||
else -> generator.regenerate(gamepad)
|
||||
}
|
||||
val byId = (placed + others).associateBy { it.id }
|
||||
return stored.mapNotNull { byId[it.id] } + placed.filter { p -> stored.none { it.id == p.id } }
|
||||
val ordered = stored.mapNotNull { byId[it.id] } + placed.filter { p -> stored.none { it.id == p.id } }
|
||||
if (dock != null || !supportsFloatingSteamControls(SessionPrefs.steamController(context), layout)) return ordered
|
||||
if (generated && width >= height && usesSteamDeckButtons(context, layout) &&
|
||||
ControllerPrefs.layout(context, reference.first.toInt(), reference.second.toInt()).isEmpty() &&
|
||||
ControllerPrefs.layout(context, width, height).isEmpty()) {
|
||||
return SteamDeckOverlayGeometry(width, height, safe, context.resources.displayMetrics, layout.scale)
|
||||
.place(ordered, rearButtons == true, trackpads == true)
|
||||
}
|
||||
return FloatingSteamOverlay(width, height, safe, context.resources.displayMetrics.density)
|
||||
.place(ordered, lowerShortcuts = generated, rearButtons = rearButtons, trackpads = trackpads)
|
||||
}
|
||||
|
||||
fun editorElements(context: Context, layout: SavedInputLayout, width: Int, height: Int, edited: Boolean = false): List<InputSurfaceElement> =
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.graphics.Rect
|
||||
import android.util.DisplayMetrics
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
||||
internal class SteamDeckOverlayGeometry(
|
||||
width: Int, height: Int, private val safe: Rect, metrics: DisplayMetrics, scale: Float,
|
||||
) {
|
||||
private val w = width.toFloat()
|
||||
private val h = height.toFloat()
|
||||
private val density = metrics.density
|
||||
private val dpi = metrics.ydpi.takeIf { it in metrics.densityDpi * .6f..metrics.densityDpi * 1.6f }
|
||||
?: metrics.densityDpi.toFloat()
|
||||
private val unit = minOf(
|
||||
min(w / 1600f, h / 900f) * min(1f, 80f / max(h / dpi * 25.4f, 1f)) * scale,
|
||||
(w - safe.left - safe.right).coerceAtLeast(1f) / 1200f,
|
||||
(h - safe.top - safe.bottom).coerceAtLeast(1f) / 900f,
|
||||
)
|
||||
|
||||
private fun anchor(value: Float, reference: Float, extent: Float, start: Int, end: Int): Float {
|
||||
val low = start + value * unit
|
||||
val high = extent - end - (reference - value) * unit
|
||||
return when {
|
||||
value < reference / 3f -> low
|
||||
value > reference * 2f / 3f -> high
|
||||
else -> (extent / 2f + (value - reference / 2f) * unit).coerceIn(low, max(low, high))
|
||||
}
|
||||
}
|
||||
|
||||
fun place(elements: List<InputSurfaceElement>, rearButtons: Boolean, trackpads: Boolean): List<InputSurfaceElement> {
|
||||
val x = { ref: Float -> anchor(ref, 1600f, w, safe.left, safe.right) }
|
||||
val y = { ref: Float -> anchor(ref, 900f, h, safe.top, safe.bottom) }
|
||||
val leftEdge = safe.left + 52f * density
|
||||
val middle = (w + safe.left - safe.right) / 2f
|
||||
val keyboard = Box(max(x(136f), leftEdge + 46f * unit), y(848f), 46f).takeIf { elements.any { it.id == KEYBOARD } }
|
||||
val row = fitRow(listOfNotNull(keyboard,
|
||||
Box(max(x(370f), leftEdge + 66f * unit), y(852f), 66f, 30f),
|
||||
Box(middle - 140f * unit, y(850f), 46f, 26f),
|
||||
Box(middle + 140f * unit, y(850f), 46f, 26f),
|
||||
Box(x(1230f), y(852f), 66f, 30f)), leftEdge)
|
||||
val (guide, select, start, qam) = row.takeLast(4)
|
||||
val positions = mapOf(
|
||||
InputControl.LT to Box(x(140f), y(66f), 88f, 34f),
|
||||
InputControl.LB to Box(x(140f), y(148f), 88f, 30f),
|
||||
InputControl.RT to Box(x(1460f), y(66f), 88f, 34f),
|
||||
InputControl.RB to Box(x(1460f), y(148f), 88f, 30f),
|
||||
InputControl.Y to Box(x(1375f), y(345f) - 96f * unit, 58f),
|
||||
InputControl.X to Box(x(1375f) - 96f * unit, y(345f), 58f),
|
||||
InputControl.B to Box(x(1375f) + 96f * unit, y(345f), 58f),
|
||||
InputControl.A to Box(x(1375f), y(345f) + 96f * unit, 58f),
|
||||
InputControl.UP to Box(x(220f), y(345f) - 102.5f * unit, 55.5f, 47.5f),
|
||||
InputControl.RIGHT to Box(x(220f) + 102.5f * unit, y(345f), 47.5f, 55.5f),
|
||||
InputControl.DOWN to Box(x(220f), y(345f) + 102.5f * unit, 55.5f, 47.5f),
|
||||
InputControl.LEFT to Box(x(220f) - 102.5f * unit, y(345f), 47.5f, 55.5f),
|
||||
InputControl.LS to Box(x(290f), y(640f), 96f),
|
||||
InputControl.RS to Box(x(1310f), y(640f), 96f),
|
||||
InputControl.SELECT to select,
|
||||
InputControl.START to start,
|
||||
InputControl.GUIDE to guide,
|
||||
InputControl.QAM to qam,
|
||||
)
|
||||
val rear = mapOf(
|
||||
InputControl.L4 to Box(x(30f), y(470f), 30f, 58f),
|
||||
InputControl.L5 to Box(x(30f), y(590f), 30f, 58f),
|
||||
InputControl.R4 to Box(x(1570f), y(470f), 30f, 58f),
|
||||
InputControl.R5 to Box(x(1570f), y(590f), 30f, 58f),
|
||||
)
|
||||
val pads = mapOf(
|
||||
InputControl.LEFT_PAD to Box(x(470f), y(360f), 88f),
|
||||
InputControl.RIGHT_PAD to Box(x(1130f), y(360f), 88f),
|
||||
)
|
||||
val optional = rear.filterKeys { rearButtons } + pads.filterKeys { trackpads }
|
||||
val placed = elements.mapNotNull { element ->
|
||||
when {
|
||||
element.id == KEYBOARD -> row.first().place(element)
|
||||
element.id != "legacy:${element.control.id}" -> element
|
||||
element.control in rear || element.control in pads -> optional[element.control]?.place(element)
|
||||
else -> positions[element.control]?.place(element) ?: element
|
||||
}
|
||||
}
|
||||
return placed + optional.mapNotNull { (control, box) ->
|
||||
if (placed.any { it.id == "legacy:${control.id}" }) null else box.place(InputSurfaceElement(control,
|
||||
0f, 0f, 0f, 0f, floating = false, buttonShape = InputButtonShape.PILL, showLabel = !control.isTrackpad))
|
||||
}
|
||||
}
|
||||
|
||||
private fun fitRow(row: List<Box>, start: Float): List<Box> {
|
||||
val end = w - safe.right
|
||||
val gap = ((end - start - row.fold(0f) { sum, box -> sum + box.width }) / (row.size - 1)).coerceIn(0f, 8f * density)
|
||||
var edge = start - gap
|
||||
val pushed = row.map { box -> box.at(max(box.cx, edge + gap + box.width / 2f)).also { edge = it.cx + it.width / 2f } }
|
||||
edge = end + gap
|
||||
return pushed.asReversed().map { box -> box.at(min(box.cx, edge - gap - box.width / 2f)).also { edge = it.cx - it.width / 2f } }.asReversed()
|
||||
}
|
||||
|
||||
private inner class Box(val cx: Float, val cy: Float, val hw: Float, val hh: Float = hw) {
|
||||
val width get() = max(hw * 2f * unit, w * .03f)
|
||||
|
||||
fun at(cx: Float) = Box(cx, cy, hw, hh)
|
||||
|
||||
fun place(element: InputSurfaceElement): InputSurfaceElement {
|
||||
val height = max(hh * 2f * unit, h * .03f)
|
||||
return element.copy(
|
||||
x = (cx - width / 2f).coerceIn(safe.left.toFloat(), max(safe.left.toFloat(), w - safe.right - width)) / w,
|
||||
y = (cy - height / 2f).coerceIn(safe.top.toFloat(), max(safe.top.toFloat(), h - safe.bottom - height)) / h,
|
||||
width = width / w, height = height / h,
|
||||
).bounded()
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val KEYBOARD = "builtin:keyboard"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user