feat(input): portrait pad under the game, kit-aware editor reset and leaner controller settings

This commit is contained in:
Kurt Himebauch committed 2026-11-18 19:06:54 -05:00
1 parent 0fba656ee2
commit 40665bbb1a
140 files changed
+1059 -2321

No files matched your search

@@ -1453,7 +1453,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
micAvailable = SessionState.micAvailable && !SessionState.suspended,
micEnabled = SessionState.micEnabled,
onMicEnabled = { SessionService.setMicEnabled(this@SessionActivity, it) },
touchAuto = getString(if (usingTouchpad()) R.string.session_touch_auto_touchpad else R.string.session_touch_auto_direct),
touchAuto = getString(if (usingTouchpad()) R.string.mode_touch_touchpad else R.string.mode_touch_mouse),
pen = penSettings.takeIf { penSeen },
onPen = { key, value -> SessionPrefs.setPenSetting(this@SessionActivity, key, value); readPrefs() },
fexPreset = fexPreset,
@@ -1720,7 +1720,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
layoutGame = controlsGameName(),
layoutOptions = layoutOptions,
layoutChoice = layoutChoice,
layoutHint = getString(if (controlsGameId() != null) R.string.osc_layout_this_game else R.string.osc_layout_default),
onLayout = ::chooseLayout,
onEditLayout = when {
layoutChoice == com.droiddeck.launcher.input.GameControls.STEAM -> if (steamTouchAvailable && onScreenButtonsVisible) ({
@@ -4494,7 +4493,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
val tabRow = unfoldedColumn?.getChildAt(0)?.height?.let {
it - (com.droiddeck.launcher.ui.BAR_HEIGHT.value * resources.displayMetrics.density + 0.5f).toInt()
} ?: 0
val gameHeight = if (wanted) com.droiddeck.launcher.session.SessionDisplay.unfoldedGameHeight(width, height, tabRow)
val aspect = if (SessionState.followScreen) 16f / 9f else outputSize().let { (w, h) -> w.toFloat() / h.coerceAtLeast(1) }
val gameHeight = if (wanted) com.droiddeck.launcher.session.SessionDisplay.unfoldedGameHeight(width, height, tabRow, aspect)
else FrameLayout.LayoutParams.MATCH_PARENT
val params = surfaceView.layoutParams as FrameLayout.LayoutParams
if (params.height != gameHeight) {
@@ -4557,7 +4557,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
if (layout == null) { panel.visibility = View.VISIBLE; return }
panel.releaseAll()
panel.visibility = View.GONE
unfoldedDeckSurface = com.droiddeck.launcher.ui.InputSurfaceView(this, padBridge, layout.elements, InputRole.PRIMARY, layout.style, haptics = true).also {
unfoldedDeckSurface = com.droiddeck.launcher.ui.InputSurfaceView(this, padBridge, inputRole = InputRole.PRIMARY, haptics = true).also {
it.showLayout(layout)
it.tag = layout
column.addView(it, android.widget.LinearLayout.LayoutParams(android.widget.LinearLayout.LayoutParams.MATCH_PARENT, 0, 1f))
}
@@ -5380,7 +5381,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
mode = SessionPrefs.oscMode(this),
desktop = SessionState.mode == SessionService.MODE_DESKTOP,
virtualPad = !steam || SessionPrefs.builtinPad(this),
covered = pipUi || unfoldedPanel != null || pcKeyboardOpen || inputSettingsOpen || keyboardCoversPad(),
covered = controlsCovered(),
controllerInUse = controllerInUse && (PadBridge.anyControllerConnected() || SteamControllerBle.connected),
hiddenByTap = controlsHiddenByTap,
steamLayout = steam && com.droiddeck.launcher.input.GameControls.steamLayout(this, controlsGameId()),
@@ -5388,12 +5389,16 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
))
}
private fun controlsCovered() = pipUi || unfoldedPanel != null || pcKeyboardOpen || inputSettingsOpen || keyboardCoversPad()
private fun updateOnScreenPad() {
val controls = onScreenControls ?: return
fun hideBottomControls() { bottomInputControls?.takeIf { it.visibility == View.VISIBLE }?.let { it.releaseAll(); it.visibility = View.GONE } }
fun hideSteam() {
steamTouchControls?.let { it.cancelEditing(); it.releaseAll(); it.visibility = View.GONE }
com.droiddeck.launcher.input.SteamTouchDevice.current?.plugged = false
val keyboardOver = SessionState.mode == SessionService.MODE_STEAM && controlsCovered() &&
com.droiddeck.launcher.input.GameControls.steamLayout(this, controlsGameId())
if (!keyboardOver) com.droiddeck.launcher.input.SteamTouchDevice.current?.plugged = false
}
val plan = controlsPlan()
onScreenButtonsVisible = plan.shown
@@ -6338,8 +6343,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
}
androidx.compose.runtime.key(profileLayout) {
androidx.compose.ui.viewinterop.AndroidView(
factory = { context -> com.droiddeck.launcher.ui.InputSurfaceView(context, padBridge, profileLayout?.elements.orEmpty(),
surfaceStyle = profileLayout?.style ?: com.droiddeck.launcher.input.InputSurfaceStyle()).also { swappedInputSurface = it } },
factory = { context -> com.droiddeck.launcher.ui.InputSurfaceView(context, padBridge).also { it.showLayout(profileLayout); swappedInputSurface = it } },
modifier = Modifier.fillMaxWidth().weight(1f),
onRelease = { if (swappedInputSurface === it) swappedInputSurface = null },
)
@@ -7,21 +7,6 @@ object ControllerPrefs {
const val STEAM_BLUE = 0xFF1A9FFF.toInt()
const val OFF = "off"
val tints = listOf(
STEAM_BLUE to R.string.ctrl_tint_steam_blue,
0xFF66C0F4.toInt() to R.string.ctrl_tint_sky,
0xFFE8EEF4.toInt() to R.string.ctrl_tint_white,
0xFFC77DFF.toInt() to R.string.ctrl_tint_violet,
0xFF3DDC84.toInt() to R.string.ctrl_tint_green,
0xFFFFA726.toInt() to R.string.ctrl_tint_amber,
0xFFFF5252.toInt() to R.string.ctrl_tint_red,
0xFFFF6FB5.toInt() to R.string.ctrl_tint_pink,
)
val opacities = listOf(40, 60, 80, 100)
val sizes = listOf(80, 90, 100, 110, 125)
val deadZones = listOf(0, 5, 8, 12, 15, 20, 25)
const val DEFAULT_DEAD_ZONE_PERCENT = 12
@@ -39,20 +24,15 @@ object ControllerPrefs {
OFF to R.string.ctrl_target_hidden,
)
/** Settings still read: the rest only seed the one-time library and layout migrations. */
class Settings(
val tint: Int,
val opacity: Int,
val size: Int,
val stickClick: Boolean,
val adaptiveSticks: Boolean,
val rumble: Boolean,
val steamButton: Boolean,
val qamButton: Boolean,
val keyboardButton: Boolean,
val selectSteam: Boolean,
val joyConVr: Boolean,
val snap: Boolean,
val customLayout: Boolean,
val mapping: Map<String, String>,
val deadZone: Int,
)
@@ -63,50 +43,17 @@ object ControllerPrefs {
val p = prefs(context)
return Settings(
tint = p.getInt("tint", STEAM_BLUE),
opacity = p.getInt("opacity", 100).takeIf { it in opacities } ?: 100,
size = p.getInt("size", 100).takeIf { it in sizes } ?: 100,
opacity = p.getInt("opacity", 100).coerceIn(1, 100),
stickClick = p.getBoolean("stickClick", true),
adaptiveSticks = p.getBoolean("adaptiveSticks", true),
rumble = rumbleEnabled(context),
steamButton = p.getBoolean("steamButton", true),
qamButton = p.getBoolean("qamButton", true),
keyboardButton = p.getBoolean("keyboardButton", true),
selectSteam = p.getBoolean("selectSteam", false),
joyConVr = joyConVr(context),
snap = snap(context),
customLayout = p.all.keys.any { it.startsWith("layout.") },
mapping = mappable.associate { (id, _) -> id to target(context, id) },
mapping = mappable.associate { (id, _) -> id to (p.getString("map.$id", id)?.takeIf { t -> targets.any { it.first == t } } ?: id) },
deadZone = deadZone(context),
)
}
fun target(context: Context, id: String): String =
prefs(context).getString("map.$id", id)?.takeIf { t -> targets.any { it.first == t } } ?: id
fun setTarget(context: Context, id: String, target: String) {
prefs(context).edit().putString("map.$id", target).apply()
}
fun setTint(context: Context, tint: Int) {
prefs(context).edit().putInt("tint", tint).apply()
}
fun setOpacity(context: Context, percent: Int) {
prefs(context).edit().putInt("opacity", percent).apply()
}
fun setSize(context: Context, percent: Int) {
prefs(context).edit().putInt("size", percent).apply()
}
fun setStickClick(context: Context, on: Boolean) {
prefs(context).edit().putBoolean("stickClick", on).apply()
}
fun setAdaptiveSticks(context: Context, on: Boolean) {
prefs(context).edit().putBoolean("adaptiveSticks", on).apply()
}
fun rumbleEnabled(context: Context): Boolean = prefs(context).getBoolean("rumble", true)
fun deadZone(context: Context): Int =
@@ -120,18 +67,6 @@ object ControllerPrefs {
prefs(context).edit().putBoolean("rumble", on).apply()
}
fun setSteamButton(context: Context, on: Boolean) {
prefs(context).edit().putBoolean("steamButton", on).apply()
}
fun setKeyboardButton(context: Context, on: Boolean) {
prefs(context).edit().putBoolean("keyboardButton", on).apply()
}
fun setSelectSteam(context: Context, on: Boolean) {
prefs(context).edit().putBoolean("selectSteam", on).apply()
}
fun joyConVr(context: Context): Boolean = prefs(context).getBoolean("joyConVr", true)
fun setJoyConVr(context: Context, on: Boolean) {
@@ -144,24 +79,6 @@ object ControllerPrefs {
prefs(context).edit().putBoolean("snap", on).apply()
}
fun layout(context: Context, width: Int, height: Int): Map<String, Pair<Float, Float>> {
val raw = prefs(context).getString("layout.${width}x$height", null) ?: return emptyMap()
return raw.split(';').mapNotNull { entry ->
val (group, pos) = entry.split(':').takeIf { it.size == 2 } ?: return@mapNotNull null
val (x, y) = pos.split(',').mapNotNull { it.toFloatOrNull() }.takeIf { it.size == 2 } ?: return@mapNotNull null
group to (x to y)
}.toMap()
}
fun setLayout(context: Context, width: Int, height: Int, positions: Map<String, Pair<Float, Float>>) {
val raw = positions.entries.joinToString(";") { (group, pos) -> "$group:${pos.first},${pos.second}" }
prefs(context).edit().putString("layout.${width}x$height", raw).apply()
}
fun resetLayout(context: Context, width: Int, height: Int) {
prefs(context).edit().remove("layout.${width}x$height").apply()
}
fun resetAll(context: Context) {
prefs(context).edit().clear().putBoolean("rumble", true).apply()
}
@@ -125,19 +125,6 @@ object InputLibraries {
return InputLibrary(profiles, layouts, bindings, selected).validate()
}
fun setAdaptiveSticks(context: Context, layoutId: String, on: Boolean): Boolean = runCatching {
update(context) { library ->
library.copy(layouts = library.layouts.map { layout ->
if (layout.id != layoutId || !layout.editable) layout
else layout.copy(elements = layout.elements.map { if (it.kind == InputElementKind.STICK) it.copy(floating = on, hideWhenIdle = on) else it })
})
}
}.onSuccess { ControllerPrefs.setAdaptiveSticks(context, on) }.isSuccess
fun setQuickButton(context: Context, layoutId: String, button: InputCommand, shown: Boolean): Boolean = runCatching {
update(context) { library -> library.layouts.firstOrNull { it.id == layoutId && it.editable }?.let { library.withLayout(it.withQuickButton(button, shown)) } ?: library }
}.isSuccess
fun defaultPositions(context: Context, library: InputLibrary, layout: SavedInputLayout): Pair<List<InputSurfaceElement>, Float>? {
val origin = layout.origin ?: layout.id
InputStockLayouts.layouts().firstOrNull { it.id == origin }?.let { return it.elements to it.aspect }
@@ -252,13 +239,12 @@ object InputLibraries {
/** Gamepads saved by the old editor follow the virtual controller's kit again; their positions don't map onto the new controls. */
private fun kitGamepads(library: InputLibrary): InputLibrary {
var result = library
for (layout in library.layouts) {
return library.copy(layouts = library.layouts.map { layout ->
val origin = layout.origin ?: layout.id
if (origin != OVERLAY && !origin.startsWith("migrated.layout.")) continue
result = result.withLayout(layout.copy(elements = emptyList(), origin = if (layout.id == OVERLAY) null else OVERLAY, aspect = 0f, scale = 1f))
}
return result.validate()
if (origin != OVERLAY && !origin.startsWith("migrated.layout.")) return@map layout
val extras = layout.elements.filterNot { KitLayout.isKit(it.id) }
layout.copy(elements = extras, origin = if (layout.id == OVERLAY) null else OVERLAY, aspect = if (extras.isEmpty()) 0f else layout.aspect, scale = 1f)
}).validate()
}
private fun migrationBindingId(library: InputLibrary, binding: String, layout: String): String {
@@ -38,8 +38,13 @@ data class InputSurfaceElement(
) {
val hasClick get() = kind == InputElementKind.STICK || kind == InputElementKind.TRACKPAD
fun bounded() = copy(x = x.coerceIn(0f, 0.97f), y = y.coerceIn(0f, 0.97f),
width = width.coerceIn(0.03f, (1f - x.coerceIn(0f, 0.97f)).coerceAtLeast(0.03f)), height = height.coerceIn(0.03f, (1f - y.coerceIn(0f, 0.97f)).coerceAtLeast(0.03f)))
fun bounded() = copy(x = x.coerceIn(0f, 1f - MIN_SIZE), y = y.coerceIn(0f, 1f - MIN_SIZE),
width = width.coerceIn(MIN_SIZE, (1f - x.coerceIn(0f, 1f - MIN_SIZE)).coerceAtLeast(MIN_SIZE)),
height = height.coerceIn(MIN_SIZE, (1f - y.coerceIn(0f, 1f - MIN_SIZE)).coerceAtLeast(MIN_SIZE)))
companion object {
const val MIN_SIZE = .01f
}
}
internal val QUICK_BUTTONS = listOf(InputCommand.STEAM, InputCommand.QUICK_ACCESS, InputCommand.KEYBOARD)
@@ -51,15 +56,31 @@ val InputSurfaceElement.quickButton: InputCommand? get() = when {
else -> null
}
internal fun List<InputSurfaceElement>.scaled(factor: Float): List<InputSurfaceElement> = map { e ->
/** Controls whose boxes touch, grown by 15%, scale around one shared anchor so a cluster such as the face buttons keeps its shape. */
internal fun List<InputSurfaceElement>.scaled(factor: Float): List<InputSurfaceElement> {
fun anchor(centre: Float) = when { centre < 1f / 3f -> 0f; centre > 2f / 3f -> 1f; else -> .5f }
val w = (e.width * factor).coerceIn(.03f, 1f)
val h = (e.height * factor).coerceIn(.03f, 1f)
val group = IntArray(size) { it }
fun root(i: Int): Int = if (group[i] == i) i else root(group[i]).also { group[i] = it }
for (i in indices) for (j in i + 1 until size) {
val a = this[i]; val b = this[j]
val near = kotlin.math.abs(a.x + a.width / 2 - b.x - b.width / 2) < (a.width + b.width) / 2 * 1.15f &&
kotlin.math.abs(a.y + a.height / 2 - b.y - b.height / 2) < (a.height + b.height) / 2 * 1.15f
if (near) group[root(i)] = root(j)
}
val anchors = indices.groupBy(::root).mapValues { (_, members) ->
anchor(members.map { this[it].x + this[it].width / 2 }.average().toFloat()) to anchor(members.map { this[it].y + this[it].height / 2 }.average().toFloat())
}
return mapIndexed { i, e -> e.scaledAround(factor, anchors.getValue(root(i))) }
}
private fun InputSurfaceElement.scaledAround(factor: Float, anchor: Pair<Float, Float>): InputSurfaceElement {
val e = this
val w = (e.width * factor).coerceIn(InputSurfaceElement.MIN_SIZE, 1f)
val h = (e.height * factor).coerceIn(InputSurfaceElement.MIN_SIZE, 1f)
val cx = e.x + e.width / 2
val cy = e.y + e.height / 2
val ax = anchor(cx)
val ay = anchor(cy)
e.copy(x = (ax + (cx - ax) * factor - w / 2).coerceIn(0f, 1f - w), y = (ay + (cy - ay) * factor - h / 2).coerceIn(0f, 1f - h),
val (ax, ay) = anchor
return e.copy(x = (ax + (cx - ax) * factor - w / 2).coerceIn(0f, 1f - w), y = (ay + (cy - ay) * factor - h / 2).coerceIn(0f, 1f - h),
width = w, height = h).bounded()
}
@@ -7,24 +7,36 @@ import kotlin.math.min
/**
* Places a virtual controller's default on-screen controls. Each kit is drawn on a 1600 × 900 reference screen; controls keep
* their distance from the nearest edge, so wider screens spread them apart instead of stretching them.
* their distance from the nearest edge, so wider screens spread them apart instead of stretching them. Clusters such as the face
* buttons are placed by their centre so they move as one. In portrait the whole pad sits along the bottom edge, and the row left of
* the bottom edge always starts after DroidDeck's corner button.
*/
object KitLayout {
const val DPAD_ID = "kit:dpad"
const val KEYBOARD_ID = "builtin:keyboard"
/** Whether [id] names one of a kit's own controls rather than a key or control the player added. */
fun isKit(id: String) = id.startsWith("legacy:") || id == DPAD_ID || id == KEYBOARD_ID
private const val REF_W = 1600f
private const val REF_H = 900f
private const val PORTRAIT_W = 1200f
/** The widest pair of side controls on any kit: a larger size never pushes the two halves, or the rows, into each other. */
private const val MIN_SPAN = 1200f
private const val MAX_HEIGHT_MM = 80f
private const val CORNER_DP = 52f
private const val GAP_DP = 8f
private class Spec(val control: InputControl, val cx: Float, val cy: Float, val hw: Float, val hh: Float = hw, val id: String = "legacy:${control.id}",
val kind: InputElementKind = InputElementKind.from(control), val shape: InputButtonShape = InputButtonShape.CIRCLE, val icon: Int = 0, val name: String = control.label)
val kind: InputElementKind = InputElementKind.from(control), val shape: InputButtonShape = InputButtonShape.CIRCLE, val icon: Int = 0, val name: String = control.label,
val ax: Float = cx, val ay: Float = cy)
private fun shoulders() = listOf(
Spec(InputControl.LT, 140f, 66f, 88f, 34f, shape = InputButtonShape.PILL), Spec(InputControl.LB, 140f, 148f, 88f, 28f, shape = InputButtonShape.PILL),
Spec(InputControl.RT, 1460f, 66f, 88f, 34f, shape = InputButtonShape.PILL), Spec(InputControl.RB, 1460f, 148f, 88f, 28f, shape = InputButtonShape.PILL))
private fun face(cx: Float, cy: Float, r: Float, off: Float) = listOf(
Spec(InputControl.Y, cx, cy - off, r), Spec(InputControl.X, cx - off, cy, r), Spec(InputControl.B, cx + off, cy, r), Spec(InputControl.A, cx, cy + off, r))
Spec(InputControl.Y, cx, cy - off, r, ax = cx, ay = cy), Spec(InputControl.X, cx - off, cy, r, ax = cx, ay = cy),
Spec(InputControl.B, cx + off, cy, r, ax = cx, ay = cy), Spec(InputControl.A, cx, cy + off, r, ax = cx, ay = cy))
private fun dpad(cx: Float, cy: Float, half: Float) =
Spec(InputControl.LS, cx, cy, half, id = DPAD_ID, kind = InputElementKind.DPAD, shape = InputButtonShape.ROUNDED, name = "D-pad")
@@ -33,8 +45,8 @@ object KitLayout {
private fun specs(kit: PadKit): List<Spec> = when {
kit.steam -> shoulders() + listOf(
Spec(InputControl.L4, 30f, 470f, 30f, 62f, shape = InputButtonShape.ROUNDED), Spec(InputControl.L5, 30f, 590f, 30f, 62f, shape = InputButtonShape.ROUNDED),
Spec(InputControl.R4, 1570f, 470f, 30f, 62f, shape = InputButtonShape.ROUNDED), Spec(InputControl.R5, 1570f, 590f, 30f, 62f, shape = InputButtonShape.ROUNDED),
Spec(InputControl.L4, 30f, 470f, 30f, 58f, shape = InputButtonShape.ROUNDED), Spec(InputControl.L5, 30f, 590f, 30f, 58f, shape = InputButtonShape.ROUNDED),
Spec(InputControl.R4, 1570f, 470f, 30f, 58f, shape = InputButtonShape.ROUNDED), Spec(InputControl.R5, 1570f, 590f, 30f, 58f, shape = InputButtonShape.ROUNDED),
dpad(215f, 330f, 100f)) + face(1385f, 330f, 50f, 82f) + listOf(
Spec(InputControl.LS, 290f, 610f, 96f), Spec(InputControl.RS, 1310f, 610f, 96f),
Spec(InputControl.LEFT_PAD, 480f, 345f, 95f, shape = InputButtonShape.ROUNDED), Spec(InputControl.RIGHT_PAD, 1120f, 345f, 95f, shape = InputButtonShape.ROUNDED),
@@ -43,11 +55,11 @@ object KitLayout {
keyboard(136f))
kit.playStation -> shoulders() + listOf(dpad(250f, 395f, 125f)) + face(1350f, 395f, 56f, 92f) + listOf(
Spec(InputControl.LS, 565f, 690f, 100f), Spec(InputControl.RS, 1035f, 690f, 100f),
Spec(InputControl.L3, 420f, 790f, 42f), Spec(InputControl.R3, 1180f, 790f, 42f),
Spec(InputControl.L3, 430f, 590f, 42f, ax = 565f, ay = 690f), Spec(InputControl.R3, 1170f, 590f, 42f, ax = 1035f, ay = 690f),
Spec(InputControl.SELECT, 640f, 150f, 50f, 30f, shape = InputButtonShape.PILL), Spec(InputControl.START, 960f, 150f, 50f, 30f, shape = InputButtonShape.PILL),
Spec(InputControl.GUIDE, 800f, 250f, 46f), Spec(InputControl.QAM, 220f, 848f, 46f), keyboard(136f))
else -> shoulders() + listOf(Spec(InputControl.LS, 235f, 400f, 104f), dpad(470f, 690f, 118f)) + face(1375f, 400f, 58f, 94f) + listOf(
Spec(InputControl.RS, 1130f, 690f, 104f), Spec(InputControl.L3, 385f, 290f, 42f), Spec(InputControl.R3, 1290f, 790f, 42f),
else -> shoulders() + listOf(Spec(InputControl.LS, 235f, 400f, 104f), dpad(470f, 675f, 118f)) + face(1375f, 400f, 58f, 94f) + listOf(
Spec(InputControl.RS, 1130f, 690f, 104f), Spec(InputControl.L3, 385f, 290f, 42f, ax = 235f, ay = 400f), Spec(InputControl.R3, 1290f, 790f, 42f, ax = 1130f, ay = 690f),
Spec(InputControl.SELECT, 690f, 162f, 38f), Spec(InputControl.GUIDE, 800f, 162f, 54f), Spec(InputControl.START, 910f, 162f, 38f),
Spec(InputControl.QAM, 220f, 848f, 46f), keyboard(136f))
}
@@ -56,20 +68,29 @@ object KitLayout {
fun elements(context: Context, kit: PadKit, width: Int, height: Int, safe: Rect = Rect(), scale: Float = 1f): List<InputSurfaceElement> {
if (width <= 0 || height <= 0) return emptyList()
val w = width.toFloat(); val h = height.toFloat()
val unit = min(w / REF_W, h / REF_H) * cap(context, min(width, height)) * scale
val portrait = height > width
val unit = (min(w / if (portrait) PORTRAIT_W else REF_W, h / REF_H) * cap(context, min(width, height)) * scale).coerceAtMost(min(w / MIN_SPAN, h / REF_H))
fun x(ref: Float) = when {
ref < REF_W / 3f -> safe.left + ref * unit
ref > REF_W * 2f / 3f -> w - safe.right - (REF_W - ref) * unit
else -> w / 2f + (ref - REF_W / 2f) * unit
}
fun y(ref: Float) = when {
portrait -> h - safe.bottom - (REF_H - ref) * unit
ref < REF_H / 3f -> safe.top + ref * unit
ref > REF_H * 2f / 3f -> h - safe.bottom - (REF_H - ref) * unit
else -> h / 2f + (ref - REF_H / 2f) * unit
}
return specs(kit).map { s ->
val cx = x(s.cx); val cy = y(s.cy); val hw = s.hw * unit; val hh = s.hh * unit
InputSurfaceElement(s.control, (cx - hw) / w, (cy - hh) / h, 2 * hw / w, 2 * hh / h, s.id, s.kind, s.name,
val density = context.resources.displayMetrics.density
var edge = safe.left + CORNER_DP * density
val specs = specs(kit)
val row = specs.filter { it.cy > REF_H * .88f && it.cx < REF_W / 3f }.sortedBy { it.cx }.associateWith { s ->
val hw = s.hw * unit
max(x(s.cx), edge + hw).also { edge = it + hw + GAP_DP * density }
}
return specs.map { s ->
val cx = row[s] ?: (x(s.ax) + (s.cx - s.ax) * unit); val cy = y(s.ay) + (s.cy - s.ay) * unit; val hw = s.hw * unit; val hh = s.hh * unit
InputSurfaceElement(s.control, (cx - hw) / w, (cy - hh) / h, 2 * hw / w, 2 * hh / h, s.id, s.kind, if (s.name == s.control.label) kit.name(s.control) else s.name,
floating = s.kind == InputElementKind.STICK, buttonShape = s.shape, icon = s.icon).bounded()
}
}
@@ -80,7 +101,7 @@ object KitLayout {
val boxes = GamepadGeometry.layout(w, h, context.resources.displayMetrics.density, portrait)
val placed = mutableListOf<InputSurfaceElement>()
fun put(control: InputControl, box: GamepadGeometry.Box?, shape: InputButtonShape, id: String = "legacy:${control.id}",
kind: InputElementKind = InputElementKind.from(control), name: String = control.label) {
kind: InputElementKind = InputElementKind.from(control), name: String = kit.name(control)) {
val b = box ?: return
placed += InputSurfaceElement(control, b.left / w, b.top / h, b.width / w, b.height / h, id, kind, name, floating = false, buttonShape = shape).bounded()
}
@@ -62,7 +62,8 @@ class OnScreenControls(context: Context, pad: PadBridge?, val dock: OnScreenLayo
}
private fun render() {
surface.updateCustomLayout(if (hidden != null) emptyList() else OnScreenLayout.elements(context, layout, viewWidth, viewHeight, safe, dock))
val placed = OnScreenLayout.elements(context, layout, viewWidth, viewHeight, safe, dock)
surface.updateCustomLayout(if (hidden != null) placed.filter { it.alwaysShown } else placed)
surface.updateStyle(layout?.style ?: InputSurfaceStyle())
corner.visibility = if (layout == null || dock != null) GONE else VISIBLE
corner.alpha = (layout?.style?.opacity ?: 100) / 100f
@@ -19,16 +19,21 @@ object OnScreenLayout {
}
}
/** The built-in gamepad keeps no positions until it is edited; until then it follows the virtual controller's kit. */
fun generated(layout: SavedInputLayout) = layout.elements.isEmpty() && (layout.id == InputLibraries.OVERLAY || layout.origin == InputLibraries.OVERLAY)
/**
* The built-in gamepad keeps no kit positions until its kit is edited; until then the kit follows the virtual controller and
* the layout stores only the keys and controls the player added on top.
*/
fun generated(layout: SavedInputLayout) = (layout.id == InputLibraries.OVERLAY || layout.origin == InputLibraries.OVERLAY) &&
layout.elements.none { KitLayout.isKit(it.id) }
fun elements(context: Context, layout: SavedInputLayout?, width: Int, height: Int, safe: Rect, dock: Dock? = null): List<InputSurfaceElement> {
layout ?: return emptyList()
if (width <= 0 || height <= 0) return layout.elements
if (generated(layout)) {
val kit = PadKit.current(context)
return if (dock != null) KitLayout.dock(context, kit, width, height, dock.portrait, dock.left, dock.right)
else KitLayout.elements(context, kit, width, height, safe, layout.scale)
val extras = if (layout.elements.isEmpty()) emptyList() else fit(layout.elements, aspect(context, layout), 1f, width, height, safe)
return (if (dock != null) KitLayout.dock(context, kit, width, height, dock.portrait, dock.left, dock.right)
else KitLayout.elements(context, kit, width, height, safe, layout.scale)) + extras
}
return fit(layout.elements, aspect(context, layout), 1f, width, height, safe)
}
@@ -25,6 +25,15 @@ enum class PadKit(val face: FaceGlyphs, val dpad: DpadStyle, val stick: StickCap
else -> control.label
}
/** What the player calls [control] on this controller. */
fun name(control: InputControl): String = if (!playStation) label(control) else when (control) {
InputControl.A -> "Cross"
InputControl.B -> "Circle"
InputControl.X -> "Square"
InputControl.Y -> "Triangle"
else -> label(control)
}
companion object {
fun of(type: String) = when (type) {
SessionPrefs.CONTROLLER_STEAM -> STEAM_CONTROLLER
@@ -379,15 +379,6 @@ class SteamTouchControls(
for (i in -1..1) canvas.drawCircle(x + i * r * 0.3f, y + r * 0.22f, r * 0.08f, p)
}
private fun drawKeyboardGlyph(canvas: Canvas, x: Float, y: Float, r: Float, color: Int) {
val p = Paint(Paint.ANTI_ALIAS_FLAG).apply { this.color = color; style = Paint.Style.STROKE; strokeWidth = lineWidth() * 0.8f }
val body = RectF(x - r * 0.6f, y - r * 0.34f, x + r * 0.6f, y + r * 0.34f)
canvas.drawRoundRect(body, r * 0.08f, r * 0.08f, p)
val dot = Paint(Paint.ANTI_ALIAS_FLAG).apply { this.color = color }
for (row in 0..1) for (i in 0..5) canvas.drawCircle(body.left + r * 0.15f + i * r * 0.18f, body.top + r * 0.18f + row * r * 0.17f, r * 0.035f, dot)
canvas.drawLine(x - r * 0.3f, body.bottom - r * 0.14f, x + r * 0.3f, body.bottom - r * 0.14f, p)
}
private val iconsLoading = HashSet<String>()
private val inkedIcons = android.util.LruCache<String, android.graphics.Bitmap>(48)
@@ -1494,11 +1485,5 @@ class SteamTouchControls(
put(SteamTouchConfig.PASTE, 0L)
}
private val LABEL_COLORS = mapOf(
SteamTouchConfig.A to Color.rgb(72, 133, 48),
SteamTouchConfig.B to Color.rgb(211, 68, 37),
SteamTouchConfig.X to Color.rgb(23, 60, 184),
SteamTouchConfig.Y to Color.rgb(235, 200, 70),
)
}
}
@@ -69,8 +69,18 @@ object SessionDisplay {
const val UNFOLDED_MIN_DP = 600
fun unfoldedGameHeight(width: Int, height: Int, tabRow: Int = 0): Int =
(minOf(width * 9 / 16, (height * UNFOLDED_MAX_GAME_SHARE).toInt()) - tabRow.coerceAtLeast(0)).coerceAtLeast(0) and 1.inv()
/**
* The game's share of a screen with the controls below it, at the game's [aspect] across the full width. A tab row under the bar
* comes out of the controls while they keep [UNFOLDED_MIN_CONTROLS_SHARE] of the screen, and out of the game otherwise.
*/
fun unfoldedGameHeight(width: Int, height: Int, tabRow: Int = 0, aspect: Float = 16f / 9f): Int {
val game = minOf((width / aspect.coerceAtLeast(.5f)).toInt(), (height * UNFOLDED_MAX_GAME_SHARE).toInt())
val tabs = tabRow.coerceAtLeast(0)
val roomy = height - game - tabs >= height * UNFOLDED_MIN_CONTROLS_SHARE
return (if (roomy) game else game - tabs).coerceAtLeast(0) and 1.inv()
}
const val UNFOLDED_MIN_CONTROLS_SHARE = .45f
fun unfoldedControlsWanted(
enabled: Boolean,
@@ -1916,7 +1916,7 @@ object SessionPrefs {
prefs(context).edit().putBoolean("pipAutoEnter", enabled).apply()
}
fun unfoldedControls(context: Context): Boolean = prefs(context).getBoolean("unfoldedControls", false)
fun unfoldedControls(context: Context): Boolean = prefs(context).getBoolean("unfoldedControls", true)
fun controlsBelowWanted(context: Context, mode: String, width: Int, height: Int, pip: Boolean = false): Boolean =
SessionDisplay.unfoldedControlsWanted(
@@ -38,7 +38,7 @@ internal fun InputElementProperties(element: InputSurfaceElement, action: InputA
withContext(Dispatchers.IO) { InputButtonImages.import(context.applicationContext, uri) }?.let { change(current.copy(icon = 0, image = it)) }
}
}
ToggleRow(host, "element-toggle", stringResource(R.string.input_toggle_button), stringResource(R.string.input_toggle_button_hint), element.toggle) { onChange(element.copy(toggle = it)) }
ToggleRow(host, "element-toggle", stringResource(R.string.input_toggle_button), null, element.toggle) { onChange(element.copy(toggle = it)) }
ChoiceRow(host, "element-shape", stringResource(R.string.input_button_shape), null,
InputButtonShape.entries.map { it to stringResource(when (it) { InputButtonShape.ROUNDED -> R.string.input_shape_rounded; InputButtonShape.PILL -> R.string.input_shape_pill; InputButtonShape.CIRCLE -> R.string.input_shape_circle; InputButtonShape.RECTANGLE -> R.string.input_shape_rectangle }) },
element.buttonShape) { onChange(element.copy(buttonShape = it)) }
@@ -63,7 +63,7 @@ internal fun InputElementProperties(element: InputSurfaceElement, action: InputA
}
}
if (element.kind == InputElementKind.TRACKPAD) {
ToggleRow(rememberMenuHost(), "element-mouse-gestures", stringResource(R.string.input_mouse_gestures), stringResource(R.string.input_mouse_gestures_hint), element.mouseGestures) { onChange(element.copy(mouseGestures = it)) }
ToggleRow(rememberMenuHost(), "element-mouse-gestures", stringResource(R.string.input_mouse_gestures), null, element.mouseGestures) { onChange(element.copy(mouseGestures = it)) }
}
if (element.kind == InputElementKind.STICK) {
val host = rememberMenuHost()
@@ -46,8 +46,9 @@ internal class InputLayoutPreviewView(context: Context) : View(context) {
private var sourceHeight = 563
fun update(layout: SavedInputLayout, role: InputRole) {
sourceHeight = if (role == InputRole.PRIMARY) 563 else 870
renderer.updateCustomLayout(layout.elements)
renderer.updateStyle(layout.style.copy(opacity = 100))
renderer.measure(MeasureSpec.makeMeasureSpec(1000, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(sourceHeight, MeasureSpec.EXACTLY))
renderer.layout(0, 0, 1000, sourceHeight)
renderer.showLayout(layout.copy(style = layout.style.copy(opacity = 100)))
renderer.measure(MeasureSpec.makeMeasureSpec(1000, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(sourceHeight, MeasureSpec.EXACTLY))
renderer.layout(0, 0, 1000, sourceHeight)
contentDescription = layout.name
@@ -65,28 +66,4 @@ internal class InputLayoutPreviewView(context: Context) : View(context) {
}
}
@Composable
internal fun InputColorRow(host: MenuHost, value: Int?, onPick: (Int?) -> Unit) {
val open = host.open == "layout-color"
val tints = listOf<Pair<Int?, Int>>(null to R.string.ctrl_tint_gray) + ControllerPrefs.tints
SettingsRow(stringResource(R.string.ctrl_color), null, highlighted = open) {
Box {
ValueChip(tints.firstOrNull { it.first == value }?.second?.let { stringResource(it) }
?: stringResource(R.string.ctrl_custom), open, modifier = Modifier.testTag("setting-layout-color")) {
host.open = if (open) null else "layout-color"
}
AnchoredMenu(open, onDismiss = { if (host.open == "layout-color") host.open = null }, title = stringResource(R.string.ctrl_color)) { firstItemFocus ->
tints.forEachIndexed { index, (color, name) ->
MenuItem(stringResource(name), checked = value == color, leading = {
Box(Modifier.size(14.dp).background(Color(color ?: GRAY_SWATCH), CircleShape).border(1.dp, Color.White.copy(alpha = .35f), CircleShape))
}, focusRequester = if (index == 0) firstItemFocus else null) {
onPick(color)
host.open = null
}
}
}
}
}
}
private const val GRAY_SWATCH = 0xFF26292E.toInt()
@@ -1,81 +0,0 @@
package com.droiddeck.launcher.ui
import android.content.Context
import android.content.SharedPreferences
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.ui.Alignment
import androidx.compose.ui.unit.dp
import androidx.compose.ui.platform.testTag
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import com.droiddeck.launcher.R
import com.droiddeck.launcher.input.*
@Composable
internal fun InputQuickSettings(host: MenuHost, desktop: Boolean, onChanged: (InputRole?) -> Unit = {}, onEdit: () -> Unit = {}, track: (String) -> Modifier = { Modifier }) {
val context = LocalContext.current
var library by remember { mutableStateOf(InputLibraries.read(context)) }
var expanded by remember { mutableStateOf(false) }
var naming by remember { mutableStateOf(false) }
var failure by remember { mutableStateOf<String?>(null) }
DisposableEffect(context) {
val preferences = context.getSharedPreferences("input-profiles", Context.MODE_PRIVATE)
val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, key -> if (key == "library") library = InputLibraries.read(context) }
preferences.registerOnSharedPreferenceChangeListener(listener)
onDispose { preferences.unregisterOnSharedPreferenceChangeListener(listener) }
}
fun update(role: InputRole?, change: (InputLibrary) -> InputLibrary) {
runCatching { InputLibraries.update(context, change) }.onSuccess { library = it; onChanged(role) }
.onFailure { failure = it.message ?: context.getString(R.string.input_save_failed) }
}
val selection = library.selection(desktop)
val mixed = selection.parts.isNotEmpty()
val active = library.profile(library.activeId(desktop))
val profiles = listOf(InputProfiles.AUTO to stringResource(R.string.input_quick_auto, if (desktop) library.profile(library.desktop).name else library.profile(library.steam).name)) +
library.profiles.map { it.id to it.name } + if (mixed) listOf("mixed" to stringResource(R.string.input_quick_mixed, active.name)) else emptyList()
Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
Row(Modifier.weight(1f).focusRow { expanded = !expanded }.padding(14.dp).testTag("input-profile-expand"),
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) {
Text(if (expanded) "▾" else "▸", color = MaterialTheme.colorScheme.onSurface)
Text(stringResource(R.string.input_profile), style = MaterialTheme.typography.titleMedium, color = MaterialTheme.colorScheme.onSurface)
}
Box(Modifier.padding(end = 14.dp).widthIn(max = 280.dp)) {
ChoiceChip(host, "input-profile", stringResource(R.string.input_profile), profiles, if (mixed) "mixed" else selection.profile,
modifier = track("input-profile")) { id -> if (id != "mixed") update(null) { it.selectProfile(desktop, id) } }
}
}
if (expanded) Surface(
modifier = Modifier.fillMaxWidth().padding(start = 18.dp, end = 12.dp, bottom = 14.dp).testTag("input-profile-parts"),
shape = RoundedCornerShape(12.dp),
color = MaterialTheme.colorScheme.primary.copy(alpha = .08f),
border = BorderStroke(1.dp, MaterialTheme.colorScheme.primary.copy(alpha = .35f)),
) {
Column(Modifier.padding(vertical = 6.dp)) {
for (role in InputRole.entries) {
val options = library.bindings.filter { binding ->
if (role == InputRole.PHYSICAL) binding.physical
else !binding.physical && library.layouts.any { it.id == binding.layoutId && it.supports(role) }
}.map { it.id to it.name }
ChoiceRow(host, "input-part-${role.name}", roleLabel(role), null, options, library.activePart(desktop, role).bindings,
chipModifier = track("input-part-${role.name}")) { id -> update(role) { it.selectPart(desktop, role, id) } }
}
if (mixed) SecondaryButton(stringResource(R.string.input_save_combination)) { naming = true }
ActionRow(stringResource(R.string.input_settings), null, stringResource(R.string.ctrl_edit), onEdit,
modifier = track("input-settings").testTag("input-profile-edit"))
}
}
if (naming) {
var name by remember { mutableStateOf("") }
AlertDialog(onDismissRequest = { naming = false }, title = { Text(stringResource(R.string.input_save_combination)) },
text = { OutlinedTextField(name, { name = it.take(80) }, singleLine = true, label = { Text(stringResource(R.string.input_name)) }) },
confirmButton = { PadTextButton(enabled = name.isNotBlank(), onClick = { update(null) { it.saveSelection(desktop, name) }; naming = false }) { Text(stringResource(R.string.gesture_save_changes)) } },
dismissButton = { PadTextButton(onClick = { naming = false }) { Text(stringResource(R.string.common_cancel)) } })
}
failure?.let { message -> AlertDialog(onDismissRequest = { failure = null }, title = { Text(stringResource(R.string.input_save_failed)) },
text = { Text(message) }, confirmButton = { PadTextButton(onClick = { failure = null }) { Text(stringResource(R.string.common_ok)) } }) }
}
@@ -278,18 +278,17 @@ private fun InputSettingsContent(onBack: () -> Unit, onChanged: () -> Unit, embe
else InputHint(layout.name)
InputNavigationRow(stringResource(R.string.input_saved_layouts), stringResource(R.string.input_saved_layouts_hint)) { go(InputPage.LAYOUTS) }
if (layout.editable) {
InputColorRow(host, layout.style.tint) { color -> update { it.withLayout(layout.copy(style = layout.style.copy(tint = color))) } }
SliderRow(stringResource(R.string.ctrl_opacity), null, layout.style.opacity, 1..100, step = 1,
format = { "$it%" }) { opacity -> update { it.withLayout(layout.copy(style = layout.style.copy(opacity = opacity))) } }
for (button in layout.quickButtons) ToggleRow(host, "quick-${button.name.lowercase()}", stringResource(quickButtonLabel(button)), null,
button !in layout.style.hidden) { on -> update { it.withLayout(layout.withQuickButton(button, on)) } }
}
if (role == InputRole.SECONDARY) InputHint(stringResource(R.string.input_second_screen_enable))
}
SettingsGroup(stringResource(R.string.input_assign_actions)) {
val users = library.usersOfBindings(preset.id)
if (users.size > 1) InputHint(stringResource(R.string.input_shared_with, users.filterNot { it.id == profileId }.joinToString { it.name }))
val elements = layout?.takeIf { it.editable }?.elements
val elements = layout?.takeIf { it.editable }?.let { l ->
if (OnScreenLayout.generated(l)) InputLibraries.defaultPositions(context, library, l)?.first.orEmpty() + l.elements else l.elements
}
if (elements != null) {
if (elements.isEmpty()) InputHint(stringResource(R.string.input_empty_elements))
for (e in elements) {
@@ -461,12 +460,6 @@ private fun InputNavigationRow(title: String, detail: String?, modifier: Modifie
}
}
internal fun quickButtonLabel(button: InputCommand) = when (button) {
InputCommand.STEAM -> R.string.ctrl_steam_button
InputCommand.QUICK_ACCESS -> R.string.ctrl_qam_button
else -> R.string.ctrl_keyboard_button
}
@Suppress("DEPRECATION")
internal fun inputDisplayMetrics(context: Context, role: InputRole): DisplayMetrics = DisplayMetrics().also { metrics ->
(context.findActivity() as? com.droiddeck.launcher.SessionActivity)?.inputEditorDisplay(role)?.getRealMetrics(metrics)
@@ -101,13 +101,26 @@ private class SurfaceDraft(val layout: SavedInputLayout, val preset: SavedInputB
scaleValue = percent; scaleBase = base.first to elements
}
fun resetPositions() { positioned?.let { checkpoint(); elements = it } }
private val restored get() = defaults?.let { refit(it, defaultsFrame) }
private fun matches(defaults: List<InputSurfaceElement>, placed: List<InputSurfaceElement>) = defaults.size == placed.size && defaults.all { a ->
placed.any { e -> e.copy(x = a.x, y = a.y, width = a.width, height = a.height) == a &&
abs(e.x - a.x) < .002f && abs(e.y - a.y) < .002f && abs(e.width - a.width) < .002f && abs(e.height - a.height) < .002f }
}
val atDefaults get() = restored?.let { matches(it, elements) } == true
/** The kit's own controls are where the kit puts them, so only the added ones need saving. */
val kitAtDefaults get() = restored?.let { matches(it, elements.filter { e -> KitLayout.isKit(e.id) }) } == true
fun reset() {
val d = restored?.takeIf { !atDefaults } ?: return
checkpoint(); elements = d; selected = null
actions = actions.filterKeys { id -> d.any { it.id == id } }; clicks = clicks.filterKeys { id -> d.any { it.id == id } }
}
fun hiddenDefaults(): List<InputSurfaceElement> = defaults?.let { refit(it, defaultsFrame) }?.filter { d -> elements.none { it.id == d.id } }.orEmpty()
fun add(element: InputSurfaceElement) { checkpoint(); elements = elements + element; selected = element.id; popover = null }
fun remove(id: String) { checkpoint(); elements = elements.filterNot { it.id == id }; actions = actions - id; clicks = clicks - id; selected = null }
fun resizeSelected(factor: Float) {
val e = element ?: return
checkpoint()
val w = (e.width * factor).coerceIn(.03f, 1f); val h = (e.height * factor).coerceIn(.03f, 1f)
val w = (e.width * factor).coerceIn(InputSurfaceElement.MIN_SIZE, 1f); val h = (e.height * factor).coerceIn(InputSurfaceElement.MIN_SIZE, 1f)
val cx = e.x + e.width / 2; val cy = e.y + e.height / 2
elements = elements.map { if (it.id == e.id) e.copy(x = (cx - w / 2).coerceIn(0f, 1f - w), y = (cy - h / 2).coerceIn(0f, 1f - h), width = w, height = h).bounded() else it }
}
@@ -127,7 +140,9 @@ fun InputSurfaceDialog(profile: String, onDismiss: () -> Unit, onChanged: () ->
val bindingUsers = library.usersOfBindings(savedBindings.id).size
val draft = remember {
val defaults = InputLibraries.defaultPositions(context, library, savedLayout)
val start = if (OnScreenLayout.generated(savedLayout) && defaults != null) savedLayout.copy(elements = defaults.first, aspect = defaults.second) else savedLayout
val start = if (OnScreenLayout.generated(savedLayout) && defaults != null) savedLayout.copy(elements = defaults.first +
OnScreenLayout.fit(savedLayout.elements, savedLayout.aspect.takeIf { it > 0f } ?: defaults.second, 1f, (defaults.second * 1000).roundToInt(), 1000, Rect()),
aspect = defaults.second) else savedLayout
SurfaceDraft(start, savedBindings, defaults?.first, defaults?.second ?: 0f, ControllerPrefs.snap(context))
}
val manager = remember { context.getSystemService(DisplayManager::class.java) }
@@ -148,7 +163,10 @@ fun InputSurfaceDialog(profile: String, onDismiss: () -> Unit, onChanged: () ->
InputLibraries.update(context) { latest ->
val l = latest.layouts.first { it.id == savedLayout.id }
val p = latest.preset(savedBindings.id)
latest.withLayout(l.copy(elements = draft.elements, aspect = draft.aspect, scale = draft.layoutScale)).withPreset(p.copy(elements = draft.actions.filterKeys { id -> draft.elements.any { it.id == id } },
val generated = draft.kitAtDefaults && OnScreenLayout.generated(l.copy(elements = emptyList()))
val extras = draft.elements.filterNot { KitLayout.isKit(it.id) }
latest.withLayout(if (generated) l.copy(elements = extras, aspect = if (extras.isEmpty()) 0f else draft.aspect, scale = draft.layoutScale)
else l.copy(elements = draft.elements, aspect = draft.aspect, scale = draft.layoutScale)).withPreset(p.copy(elements = draft.actions.filterKeys { id -> draft.elements.any { it.id == id } },
clicks = draft.clicks.filterKeys { id -> draft.elements.any { it.id == id && it.hasClick } }))
}
}.onSuccess { onChanged(); onDismiss() }.onFailure { failure = it.message ?: context.getString(R.string.input_save_failed) }
@@ -192,7 +210,27 @@ fun InputSurfaceDialog(profile: String, onDismiss: () -> Unit, onChanged: () ->
val element = draft.element
BackHandler { if (draft.properties) draft.properties = false else leave() }
val editorScope = scope ?: if (layoutUsers > 1) stringResource(R.string.input_editor_shared, layoutUsers) else savedLayout.name
val propertiesEditor: @Composable (InputSurfaceElement) -> Unit = { element ->
var properties by remember(element.id) { mutableStateOf(element) }
InputActionEditor(if (draft.clickProperties) InputControl.A else element.control,
if (draft.clickProperties) draft.clickAction(element) else draft.action(element),
if (draft.clickProperties) stringResource(R.string.input_click_name, element.name) else element.name,
onBack = { draft.properties = false }, element = element, click = draft.clickProperties,
properties = { action ->
if (!draft.clickProperties) InputElementProperties(properties, action) { properties = it }
if (layoutUsers > 1) Text(stringResource(R.string.input_editor_shared, layoutUsers),
style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier.padding(bottom = 12.dp))
}, detail = if (bindingUsers > 1) stringResource(R.string.input_shared_detail, savedBindings.name, bindingUsers)
else "${library.profile(profile).name} · ${roleLabel(role)}", onSave = { action ->
draft.checkpoint()
if (draft.clickProperties) draft.clicks = draft.clicks + (element.id to action) else draft.actions = draft.actions + (element.id to action)
draft.elements = draft.elements.map { if (it.id == element.id) properties.copy(name = properties.name.trim().ifBlank { element.name }) else it }
draft.properties = false
})
}
when {
(remote || target == null) && draft.properties && element != null -> propertiesEditor(element)
target == null -> SettingsPage(rememberMenuHost(), savedLayout.name, ::leave) {
Text(stringResource(R.string.input_display_unavailable))
PrimaryButton(stringResource(R.string.input_editor_done)) { save() }
@@ -208,24 +246,8 @@ fun InputSurfaceDialog(profile: String, onDismiss: () -> Unit, onChanged: () ->
EditorChrome(draft, editorScope, failure, ::save, ::leave, onDismiss)
if (draft.properties && element != null) Surface(Modifier.align(Alignment.CenterEnd).fillMaxHeight().fillMaxWidth(.44f),
color = MaterialTheme.colorScheme.surface, shadowElevation = 12.dp) {
var properties by remember(element.id) { mutableStateOf(element) }
InputActionEditor(if (draft.clickProperties) InputControl.A else element.control,
if (draft.clickProperties) draft.clickAction(element) else draft.action(element),
if (draft.clickProperties) stringResource(R.string.input_click_name, element.name) else element.name,
onBack = { draft.properties = false }, element = element, click = draft.clickProperties,
properties = { action ->
if (!draft.clickProperties) InputElementProperties(properties, action) { properties = it }
if (layoutUsers > 1) Text(stringResource(R.string.input_editor_shared, layoutUsers),
style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier.padding(bottom = 12.dp))
}, detail = if (bindingUsers > 1) stringResource(R.string.input_shared_detail, savedBindings.name, bindingUsers)
else "${library.profile(profile).name} · ${roleLabel(role)}", onSave = { action ->
draft.checkpoint()
if (draft.clickProperties) draft.clicks = draft.clicks + (element.id to action) else draft.actions = draft.actions + (element.id to action)
draft.elements = draft.elements.map { if (it.id == element.id) properties.copy(name = properties.name.trim().ifBlank { element.name }) else it }
draft.properties = false
})
}
propertiesEditor(element)
}
}
}
}
@@ -278,7 +300,7 @@ private fun EditorChrome(draft: SurfaceDraft, scope: String, failure: String?, o
if (draft.defaults != null) SecondaryButton(stringResource(R.string.input_hidden_count, draft.hiddenDefaults().size), compact = true) {
draft.popover = if (draft.popover == EditorPopover.HIDDEN) null else EditorPopover.HIDDEN
}
if (draft.defaults != null) SecondaryButton(stringResource(R.string.input_reset_positions), enabled = draft.positioned != null, compact = true) { draft.resetPositions() }
if (draft.defaults != null) SecondaryButton(stringResource(R.string.hud_reset_button), enabled = !draft.atDefaults, compact = true) { draft.reset() }
Row(verticalAlignment = Alignment.CenterVertically) {
Checkbox(draft.snap, { draft.snap = it; ControllerPrefs.setSnap(context, it) })
Text(stringResource(R.string.ctrl_editor_snap))
@@ -32,6 +32,8 @@ import com.droiddeck.launcher.input.InputButtonIcons
import com.droiddeck.launcher.input.InputButtonShape
import com.droiddeck.launcher.input.InputButtonImages
import com.droiddeck.launcher.input.KitLayout
import com.droiddeck.launcher.input.OnScreenLayout
import com.droiddeck.launcher.input.SavedInputLayout
import com.droiddeck.launcher.input.PadBridge
import com.droiddeck.launcher.input.PadKit
import com.droiddeck.launcher.input.pcKeyLabel
@@ -148,6 +150,21 @@ class InputSurfaceView(
view.invalidate()
}
private var generated: SavedInputLayout? = null
/** Shows [layout]; a layout that has no elements of its own gets the virtual controller's defaults at this view's size. */
fun showLayout(layout: SavedInputLayout?) {
generated = layout?.takeIf(OnScreenLayout::generated)
updateStyle(layout?.style ?: InputSurfaceStyle())
updateCustomLayout(generated?.let { OnScreenLayout.elements(context, it, width, height, android.graphics.Rect(), null) } ?: layout?.elements.orEmpty())
}
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
super.onSizeChanged(w, h, oldw, oldh)
val layout = generated ?: return
post { if (generated === layout) updateCustomLayout(OnScreenLayout.elements(context, layout, width, height, android.graphics.Rect(), null)) }
}
fun updateCustomLayout(requested: List<InputSurfaceElement>) {
requestedLayout = requested
val layout = surfaceStyle.shown(requested)
@@ -286,7 +286,9 @@ fun ModeSheetRows(s: ModeSettings, a: ModeSettingsActions, tab: String, extras:
extras.drivers(s.gpuDrivers)
}
if (tab == SheetTab.CONTROLS) {
InputQuickSettings(host, desktop = s.mode == SessionService.MODE_DESKTOP, onEdit = a.onInputSettings)
SettingsGroup(stringResource(R.string.drawer_page_controller)) {
ActionRow(stringResource(R.string.input_remap_buttons), null, stringResource(R.string.ctrl_edit), a.onInputSettings)
}
SettingsGroup(if (steam) stringResource(R.string.mode_touch_controls) else stringResource(R.string.mode_touch)) {
ChoiceRow(
host, "touch", stringResource(R.string.mode_touch), null,
@@ -244,8 +244,7 @@ class SecondScreenPresentation(
if (!created || !currentMode.controls) return
val controls = controlsView ?: return
val layout = panelLayout(currentMode)
controls.updateCustomLayout(layout?.elements.orEmpty())
controls.updateStyle(layout?.style ?: com.droiddeck.launcher.input.InputSurfaceStyle())
controls.showLayout(layout)
}
fun showKeyboard(): Boolean {
@@ -292,8 +291,7 @@ class SecondScreenPresentation(
if (mode == SecondScreenMode.DECK_CONTROLS) deckPanel.value = SessionPrefs.deckPanel(context)
bar(mode)
val layout = panelLayout(mode)
val controls = InputSurfaceView(context, pad, layout?.elements.orEmpty(),
surfaceStyle = layout?.style ?: com.droiddeck.launcher.input.InputSurfaceStyle())
val controls = InputSurfaceView(context, pad).also { it.showLayout(layout) }
controlsView = controls
root.addView(controls, weightParams())
attachKeyboard()
@@ -296,7 +296,6 @@ class DrawerActions(
val layoutGame: String? = null,
val layoutOptions: List<Pair<String, String>> = emptyList(),
val layoutChoice: String = "",
val layoutHint: String? = null,
val onLayout: (String) -> Unit = {},
val onEditLayout: (() -> Unit)? = null,
val controller: com.droiddeck.launcher.input.ControllerPrefs.Settings? = null,
@@ -660,18 +659,18 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
}
SessionDrawerPage.CONTROLLER -> {
SettingsGroup(a.layoutGame?.let { stringResource(R.string.osc_group_for, it) } ?: stringResource(R.string.mode_osc)) {
if (a.layoutOptions.isNotEmpty()) ChoiceRow(host, "osc-layout", stringResource(R.string.osc_layout), a.layoutHint,
if (a.layoutOptions.isNotEmpty()) ChoiceRow(host, "osc-layout", stringResource(R.string.osc_layout), null,
a.layoutOptions, a.layoutChoice, chipModifier = focus.track(page, "osc-layout"), onPick = a.onLayout)
a.onEditLayout?.let { edit ->
ActionRow(stringResource(R.string.osc_edit_layout), null, stringResource(R.string.ctrl_edit), { host.open = null; edit() },
modifier = focus.track(page, "osc-edit"))
}
SettingsRow(stringResource(R.string.osc_show), stringResource(R.string.osc_show_hint), stacked = true) {
SettingsRow(stringResource(R.string.osc_show), null) {
SegmentedTabs(listOf(SessionPrefs.OSC_AUTO to stringResource(R.string.common_auto), SessionPrefs.OSC_ALWAYS to stringResource(R.string.common_always),
SessionPrefs.OSC_NEVER to stringResource(R.string.common_never)), a.oscMode,
tabModifier = { focus.track(page, "osc-$it") }, onPick = a.onOsc)
}
ChoiceRow(host, "touch", stringResource(R.string.input_touches), stringResource(R.string.input_touches_hint),
ChoiceRow(host, "touch", stringResource(R.string.input_touches), null,
listOf(SessionPrefs.TOUCH_AUTO to stringResource(R.string.drawer_touch_auto, a.touchAuto), SessionPrefs.TOUCH_DIRECT to stringResource(R.string.mode_touch_mouse),
SessionPrefs.TOUCH_PAD to stringResource(R.string.mode_touch_touchpad), SessionPrefs.TOUCH_GESTURES to stringResource(R.string.mode_touch_gestures),
SessionPrefs.TOUCH_OFF to stringResource(R.string.widgets_off)),
@@ -680,13 +679,13 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
RelativeMouseRow(host, a, focus.track(page, "relative-mouse"))
if (a.touchActive == SessionPrefs.TOUCH_DIRECT)
ToggleRow(host, "direct-cursor", stringResource(R.string.input_touch_cursor),
stringResource(R.string.input_touch_cursor_hint), a.directCursor,
null, a.directCursor,
chipModifier = focus.track(page, "direct-cursor"), onChange = a.onDirectCursor)
when (a.touchActive) {
SessionPrefs.TOUCH_GESTURES -> ActionRow(stringResource(R.string.gesture_settings), null,
stringResource(R.string.ctrl_edit), a.onGestureSettings,
modifier = focus.track(page, "gesture-settings"))
SessionPrefs.TOUCH_DIRECT -> ChoiceRow(host, "long-press", stringResource(R.string.input_touch_hold), stringResource(R.string.input_touch_hold_hint),
SessionPrefs.TOUCH_DIRECT -> ChoiceRow(host, "long-press", stringResource(R.string.input_touch_hold), null,
listOf(MOUSE_BEHAVIOR_NONE to stringResource(R.string.gesture_hold_left),
MOUSE_BEHAVIOR_CLICK to stringResource(R.string.gesture_right_click),
MOUSE_BEHAVIOR_HOLD to stringResource(R.string.gesture_hold_right)),
@@ -694,17 +693,17 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
onPick = a.onDirectHoldBehavior)
}
if (a.steam && a.unfoldedControls != null) ToggleRow(host, "unfolded-controls", stringResource(R.string.unfolded_controls),
stringResource(R.string.unfolded_controls_hint), a.unfoldedControls,
null, a.unfoldedControls,
chipModifier = focus.track(page, "unfolded-controls"), onChange = a.onUnfoldedControls)
if (a.steam && a.unfoldedControls == true) ToggleRow(host, "unfolded-controls-with-controller",
stringResource(R.string.unfolded_controls_with_controller),
stringResource(R.string.unfolded_controls_with_controller_hint), a.unfoldedControlsWithController,
null, a.unfoldedControlsWithController,
chipModifier = focus.track(page, "unfolded-controls-with-controller"),
onChange = a.onUnfoldedControlsWithController)
}
SettingsGroup(stringResource(R.string.drawer_page_controller)) {
a.padType?.let { type ->
ChoiceRow(host, "pad-type", stringResource(R.string.input_virtual_controller), stringResource(R.string.input_virtual_controller_hint),
ChoiceRow(host, "pad-type", stringResource(R.string.input_virtual_controller), null,
listOf(SessionPrefs.CONTROLLER_DECK to stringResource(R.string.mode_controller_deck),
SessionPrefs.CONTROLLER_STEAM to stringResource(R.string.mode_controller_steam),
SessionPrefs.CONTROLLER_DS4 to stringResource(R.string.mode_controller_ds4),
@@ -716,7 +715,7 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
ToggleRow(host, "rumble", stringResource(R.string.ctrl_rumble), null, c.rumble,
chipModifier = focus.track(page, "rumble"), onChange = a.onRumble)
}
ActionRow(stringResource(R.string.input_remap_buttons), stringResource(R.string.input_physical_hint), stringResource(R.string.ctrl_edit),
ActionRow(stringResource(R.string.input_remap_buttons), null, stringResource(R.string.ctrl_edit),
a.onInputSettings, modifier = focus.track(page, "remap"))
}
SettingsGroup(stringResource(R.string.drawer_keyboard)) {
@@ -745,9 +744,9 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
{ moreControls = !moreControls }, modifier = focus.track(page, "more-controls"))
if (moreControls) {
if (a.steam) ToggleRow(host, "back-hold", stringResource(R.string.back_hold),
stringResource(R.string.back_hold_hint), a.backHold,
null, a.backHold,
chipModifier = focus.track(page, "back-hold"), onChange = a.onBackHold)
if (a.steam) ChoiceRow(host, "back-actions", stringResource(R.string.input_back_taps), stringResource(R.string.input_back_taps_hint),
if (a.steam) ChoiceRow(host, "back-actions", stringResource(R.string.input_back_taps), null,
listOf(false to stringResource(SessionPrefs.BACK_MENU_THEN_QAM), true to stringResource(SessionPrefs.BACK_QAM_THEN_MENU)),
a.backActionsInverted, chipModifier = focus.track(page, "back-actions"), onPick = a.onBackActionsInverted)
if (a.steam) ChoiceRow(host, "back-double-tap", stringResource(R.string.back_double_tap_window), null,
@@ -758,7 +757,7 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
stringResource(R.string.drawer_corner_tap_hint), a.cornerTap,
chipModifier = focus.track(page, "corner-tap"), onChange = a.onCornerTap)
ToggleRow(host, "low-latency", stringResource(R.string.drawer_low_latency),
stringResource(R.string.drawer_low_latency_hint), a.lowLatency,
null, a.lowLatency,
chipModifier = focus.track(page, "low-latency"), onChange = a.onLowLatency)
ToggleRow(host, "evdev-mouse", stringResource(R.string.drawer_evdev_mouse),
null, a.evdevMouse,
@@ -768,18 +767,18 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
val keyboardContext = LocalContext.current
remember { PcKeyboardPrefs.load(keyboardContext) }
SliderRow(
stringResource(R.string.pckb_size), stringResource(R.string.pckb_size_hint),
stringResource(R.string.pckb_size), null,
PcKeyboardPrefs.size, SessionPrefs.PC_KEYBOARD_SIZE_RANGE, step = 1,
format = { "$it%" }, modifier = focus.track(page, "pckb-size"),
onChange = { PcKeyboardPrefs.setSize(keyboardContext, it) })
SliderRow(
stringResource(R.string.pckb_opacity), stringResource(R.string.pckb_opacity_hint),
stringResource(R.string.pckb_opacity), null,
PcKeyboardPrefs.opacity, SessionPrefs.PC_KEYBOARD_OPACITY_RANGE, step = 5,
format = { "$it%" }, modifier = focus.track(page, "pckb-opacity"),
onChange = { PcKeyboardPrefs.setOpacity(keyboardContext, it) })
MultiRow(
host, "pckb-hidden", stringResource(R.string.pckb_hidden_keys),
stringResource(R.string.pckb_hidden_keys_hint),
null,
listOf(
0 to stringResource(R.string.pckb_group_function),
1 to stringResource(R.string.pckb_group_nav),
@@ -830,7 +829,7 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
SessionDrawerPage.AGENT -> Unit
SessionDrawerPage.SESSION -> {
SettingsGroup(stringResource(R.string.drawer_support)) {
SettingsRow(stringResource(R.string.report_problem), stringResource(R.string.report_problem_hint)) {
SettingsRow(stringResource(R.string.report_problem), null) {
DrawerOutlineButton(stringResource(R.string.drawer_share_logs), modifier = focus.track(page, "share-logs"),
progress = com.droiddeck.launcher.session.SessionLogShare.progress) {
host.open = null
@@ -868,7 +867,7 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
}
SettingsGroup(stringResource(R.string.drawer_session_behavior)) {
if (a.micAvailable) ToggleRow(host, "microphone", stringResource(R.string.mode_mic),
stringResource(R.string.drawer_mic_hint), a.micEnabled,
null, a.micEnabled,
chipModifier = focus.track(page, "microphone"), onChange = a.onMicEnabled)
ChoiceRow(
host, "suspend", stringResource(R.string.mode_suspend),
@@ -887,7 +886,7 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
)
if (a.steam && a.suspendPolicy != SessionPrefs.SUSPEND_NEVER) ToggleRow(
host, "background-downloads", stringResource(R.string.mode_background_downloads),
stringResource(R.string.mode_background_downloads_hint),
null,
a.steamDownloadsInBackground,
onChange = a.onSteamDownloadsInBackground,
)
@@ -1104,20 +1103,20 @@ private fun ScreenEffectsGroup(
SettingsGroup(stringResource(R.string.drawer_effects)) {
ChoiceRow(
host, "effects-profile", stringResource(R.string.screen_effects_target),
stringResource(R.string.screen_effects_target_hint), a.screenEffectsTargets,
null, a.screenEffectsTargets,
a.screenEffectsTarget, chipModifier = track("effects-profile"),
onPick = a.onScreenEffectsTarget,
)
ActionRow(
stringResource(R.string.screen_effects_reset),
stringResource(R.string.screen_effects_reset_hint),
null,
stringResource(R.string.hud_reset_button),
a.onScreenEffectsReset,
modifier = track("effects-reset"),
)
if (a.screenEffectsCanDelete) ActionRow(
stringResource(R.string.screen_effects_delete),
stringResource(R.string.screen_effects_delete_hint),
null,
stringResource(R.string.common_delete),
a.onScreenEffectsDelete,
modifier = track("effects-delete"),
@@ -1200,7 +1199,7 @@ private fun ScreenEffectsGroup(
private fun CardboardGroup(host: MenuHost, a: DrawerActions, track: (String) -> Modifier) {
val c = a.cardboard
SettingsGroup(stringResource(R.string.cardboard_title)) {
ToggleRow(host, "cardboard", stringResource(R.string.cardboard_mode), stringResource(R.string.cardboard_mode_hint),
ToggleRow(host, "cardboard", stringResource(R.string.cardboard_mode), null,
c.enabled, chipModifier = track("cardboard")) { a.onCardboard(c.copy(enabled = it)) }
if (!c.enabled) return@SettingsGroup
ChoiceRow(host, "cardboard-source", stringResource(R.string.cardboard_source), null,
@@ -1282,8 +1281,6 @@ private fun SecondScreenGroup(host: MenuHost, a: DrawerActions, track: (String)
val pal = LocalPalette.current
val modes = secondScreenModes(a.secondScreenNone, com.droiddeck.launcher.session.SessionState.deckPad, a.dashboardAvailable, a.desktopAvailable)
SettingsGroup(stringResource(R.string.drawer_second_screen_mode)) {
Text(stringResource(R.string.input_second_mode_hint), Modifier.padding(14.dp),
style = MaterialTheme.typography.bodySmall, color = colors.onSurfaceVariant)
Column(Modifier.fillMaxWidth().selectableGroup()) {
modes.forEach { mode ->
val selected = a.secondScreenMode == mode
@@ -1700,8 +1697,6 @@ internal fun ComponentDownloadsDrawerGroup(
val installed = packages.map { it.file }.toSet()
val nightlyPicked = remember { mutableStateMapOf<String, Boolean>() }
SettingsGroup(stringResource(R.string.drawer_component_downloads)) {
Text(stringResource(R.string.drawer_component_downloads_hint), fontSize = 12.sp,
color = colors.onSurfaceVariant, modifier = Modifier.padding(horizontal = 14.dp, vertical = 8.dp))
SettingsRow(stringResource(R.string.comp_nightlies_checked,
if (catalogAt > 0) java.text.DateFormat.getTimeInstance(java.text.DateFormat.SHORT)
.format(java.util.Date(catalogAt * 1000)) else stringResource(R.string.comp_never)), null, stacked = true) {