fix(input): classic on-screen gamepad look, quick hide toggle and adaptive sticks switch (#2215)

* fix(input): bring back the classic on-screen gamepad look, quick hide toggle and adaptive sticks switch

The unified input surfaces (#1439) drew the built-in gamepad as large
rounded boxes labelled with control names, swapped the compact keyboard
button for a wide pill, dropped the bottom-left show/hide toggle and left
the Adaptive sticks setting with no effect once a layout was migrated.

Gamepad elements are round again with shoulder pills, D-pad arrows, the
old glyph labels and the tint-derived fill and outline. The keyboard is a
small round button beside a restored quick show/hide toggle. Stick touch
areas reach 25% further outward while keeping their inner edge, and the
session menu gets an Adaptive sticks switch that writes the active
layout's sticks. Libraries saved by the first unified build are restyled
once without touching user edits or other layouts.

* fix(input): overlay keyboard opens on the main screen and the D-pad matches the face buttons

A keyboard command now carries the role of the surface that sent it, so the
overlay's keyboard button opens the main screen keyboard as before the
unified surfaces, while lower-screen and controller bindings still use a
second screen. The D-pad buttons take the face buttons' size and spacing,
and an untouched saved D-pad is resized around its own centre. Classic
outlines sit where the old ones did and shoulder labels use their old size.

* fix(input): keep edited D-pads and keyboard buttons, harden the quick and adaptive toggles

Resize a saved D-pad only while its four buttons keep their original geometry, and
replace the old keyboard button only while its name and shape are untouched.
The quick toggle needs its own press before a release toggles it, and a cancelled
touch does nothing. A rejected library write no longer crashes the session or
changes the controller preference, and the Adaptive sticks switch shows whenever
the built-in gamepad is the surface in use.

* fix(input): show the adaptive sticks switch while the unfolded controls are up

* fix(input): run the gamepad restyle as library version 10 and draw the quick toggle in Gray

* fix(input): show the adaptive sticks switch whenever the built-in gamepad is the surface in use

---------

Co-authored-by: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com>
This commit is contained in:
MaxsTechReviewandKurt Himebauch authored and GitHub committed 2026-11-07 12:42:45 -05:00
1 parent a123af7c13
commit 98a670fb81
12 files changed
+498 -34

No files matched your search

@@ -159,6 +159,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
private var pipAutoEnter by mutableStateOf(false)
private var unfoldedControls by mutableStateOf(false)
private var unfoldedControlsWithController by mutableStateOf(false)
private var adaptiveSticks by mutableStateOf<Boolean?>(null)
private var picturePosition by mutableStateOf("center")
private fun applyGameAlignment() {
@@ -172,7 +173,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
}
WaylandCompositor.nativeSetScaleMode(SCALE_FIT, alignment)
}
private var unfoldedPanel: com.droiddeck.launcher.ui.InputSurfaceView? = null
private var unfoldedPanel by mutableStateOf<com.droiddeck.launcher.ui.InputSurfaceView?>(null)
private lateinit var sessionRoot: FrameLayout
private var inputRouter: InputRouter? = null
private var physicalInputBindings: com.droiddeck.launcher.input.PhysicalInputBindings? = null
@@ -196,12 +197,13 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
override fun scroll(steps: Int) { sendSceneWheel(steps) }
override fun scrollHorizontal(steps: Int) { sendSceneWheel(steps, horizontal = true) }
override fun requestMotion() { inputMotion.request() }
override fun command(command: InputCommand) {
override fun command(command: InputCommand) = command(command, InputRole.PHYSICAL)
override fun command(command: InputCommand, role: InputRole) {
uiHandler.post {
if (!resumed || isDestroyed || pipUi || SessionState.suspended) return@post
when (command) {
InputCommand.MENU -> { releasePads(); drawerOpen = true }
InputCommand.KEYBOARD -> if (secondScreenPresentation?.showKeyboard() != true) togglePcKeyboard()
InputCommand.KEYBOARD -> if (role == InputRole.PRIMARY || secondScreenPresentation?.showKeyboard() != true) togglePcKeyboard()
InputCommand.STEAM -> tapSteamButton()
InputCommand.QUICK_ACCESS -> tapQam()
}
@@ -244,6 +246,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
private var secondaryInputLayout by mutableStateOf<com.droiddeck.launcher.input.SavedInputLayout?>(null)
private var steamTouchControls: com.droiddeck.launcher.input.SteamTouchControls? = null
private var steamTouchAvailable by mutableStateOf(false)
private var steamTouchInUse by mutableStateOf(false)
private val steamTouchRetry = Runnable { updateOnScreenControls() }
private var steamTouchOptions: com.droiddeck.launcher.input.SteamTouchConfig.Options? = null
private var routedTouchMode = SessionPrefs.TOUCH_AUTO
@@ -1404,6 +1407,13 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
},
unfoldedControls = unfoldedControls,
onUnfoldedControls = ::chooseUnfoldedControls,
adaptiveSticks = adaptiveSticks.takeIf {
unfoldedPanel != null || oscMode != SessionPrefs.OSC_NEVER && oscMode != SessionPrefs.OSC_STEAM_QAM && !steamTouchInUse
},
onAdaptiveSticks = { on ->
primaryInputLayout?.let { com.droiddeck.launcher.input.InputLibraries.setAdaptiveSticks(this@SessionActivity, it.id, on) }
refreshInputProfile()
},
unfoldedControlsWithController = unfoldedControlsWithController,
onUnfoldedControlsWithController = ::chooseUnfoldedControlsWithController,
onBackground = { drawerOpen = false; pip.background(); moveTaskToBack(true) },
@@ -3498,6 +3508,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
val desktop = loadingMode() == SessionService.MODE_DESKTOP
inputProfile = library.compileActive(desktop)
primaryInputLayout = library.activeLayout(desktop, InputRole.PRIMARY)
adaptiveSticks = primaryInputLayout?.adaptiveSticks
secondaryInputLayout = library.activeLayout(desktop, InputRole.SECONDARY)
inputUsesLocalActions = InputControl.padControls.any { inputProfile.action(InputRole.PHYSICAL, it) !is InputAction.Native }
inputUsesPointer = inputProfile.bindings.values.any { bindings ->
@@ -4212,6 +4223,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
val buttonsOnly = forced == SessionPrefs.OSC_STEAM_QAM
val wantsSteam = forced == SessionPrefs.OSC_STEAM_TOUCH && SessionState.mode == SessionService.MODE_STEAM
val steam = if (wantsSteam) steamTouch() else null
steamTouchInUse = steam != null
if (wantsSteam && steam == null && !isFinishing && !isDestroyed) {
uiHandler.removeCallbacks(steamTouchRetry)
uiHandler.postDelayed(steamTouchRetry, 1000)
@@ -9,7 +9,7 @@ import org.json.JSONObject
import java.util.UUID
object InputLibraries {
private const val VERSION = 9
private const val VERSION = 10
private const val KEY = "library"
private const val RECOVERY = "library-recovery."
const val OVERLAY = "builtin.overlay"
@@ -28,6 +28,7 @@ object InputLibraries {
val version = raw?.let { JSONObject(it).getInt("version") } ?: 0
if (version < 5) library = scopeLayouts(upgradeStockLayouts(upgradeOverlay(context, library)))
if (version < 9) library = neutralStockLayouts(library)
if (version < 10) library = restyleGamepads(context, library)
if (version < 6 || !p.contains(LegacyScreenKeyMigration.BACKUP)) {
val legacy = LegacyScreenKeyMigration.snapshot(context)
if (legacy != null) {
@@ -105,12 +106,39 @@ 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
@Suppress("DEPRECATION")
private fun upgradeOverlay(context: Context, library: InputLibrary): InputLibrary {
if (library.layouts.none { it.template == InputLayoutTemplate.OVERLAY }) return library
private fun primaryDisplay(context: Context): Pair<Context, DisplayMetrics> {
val display = context.getSystemService(DisplayManager::class.java)?.getDisplay(Display.DEFAULT_DISPLAY)
val surfaceContext = display?.let(context::createDisplayContext) ?: context
val metrics = DisplayMetrics().also { if (display != null) display.getRealMetrics(it) else it.setTo(context.resources.displayMetrics) }
return surfaceContext to DisplayMetrics().also { if (display != null) display.getRealMetrics(it) else it.setTo(context.resources.displayMetrics) }
}
private fun restyleGamepads(context: Context, library: InputLibrary): InputLibrary {
if (library.layouts.none { it.id == OVERLAY || it.id.startsWith("migrated.layout.") }) return library
val (surfaceContext, metrics) = primaryDisplay(context)
return library.copy(layouts = library.layouts.map { layout ->
val size = when {
layout.id == OVERLAY -> listOf(metrics.widthPixels, metrics.heightPixels)
layout.id.startsWith("migrated.layout.") -> layout.id.removePrefix("migrated.layout.").split('x').mapNotNull { it.toIntOrNull() }
else -> emptyList()
}
if (size.size != 2 || size.any { it <= 0 }) layout
else layout.copy(elements = LegacyGamepadLayout(surfaceContext, size[0], size[1]).restyle(layout.elements))
})
}
private fun upgradeOverlay(context: Context, library: InputLibrary): InputLibrary {
if (library.layouts.none { it.template == InputLayoutTemplate.OVERLAY }) return library
val (surfaceContext, metrics) = primaryDisplay(context)
val settings = ControllerPrefs.read(context)
val elements = LegacyGamepadLayout(surfaceContext, metrics.widthPixels.coerceAtLeast(1), metrics.heightPixels.coerceAtLeast(1)).elements()
val style = InputSurfaceStyle(settings.tint, settings.opacity)
@@ -18,6 +18,7 @@ data class SavedInputLayout(
val screen: InputLayoutScreen = InputLayoutScreen.BOTH,
) {
val editable get() = template == InputLayoutTemplate.CUSTOM
val adaptiveSticks get() = elements.filter { it.kind == InputElementKind.STICK }.takeIf { editable && it.isNotEmpty() }?.all { it.floating && it.hideWhenIdle }
fun supports(role: InputRole) = screen.supports(role) && when (template) {
InputLayoutTemplate.OVERLAY -> role == InputRole.PRIMARY
InputLayoutTemplate.DECK, InputLayoutTemplate.TRACKPAD -> role == InputRole.SECONDARY
@@ -9,6 +9,7 @@ interface InputOutput {
fun scroll(steps: Int)
fun scrollHorizontal(steps: Int) {}
fun command(command: InputCommand)
fun command(command: InputCommand, role: InputRole) = command(command)
fun requestMotion()
}
@@ -233,7 +234,7 @@ class InputRouter(private val output: InputOutput) {
when (a) {
is InputAction.Keys -> if (down) a.codes.forEach { key(it, true) } else a.codes.asReversed().forEach { key(it, false) }
is InputAction.MouseButton -> button(a.code, down)
is InputAction.Command -> if (down) output.command(a.command)
is InputAction.Command -> if (down) output.command(a.command, role)
else -> Unit
}
}
@@ -17,10 +17,10 @@ internal class LegacyGamepadLayout(private val context: Context, private val wid
val halfH get() = if (id in shoulderIds) radius * SHOULDER_HEIGHT else radius
}
private val controls = listOf(
Control("up", "dpad", -1, 26f, 0f, -52f),
Control("right", "dpad", -1, 26f, 52f, 0f),
Control("down", "dpad", -1, 26f, 0f, 52f),
Control("left", "dpad", -1, 26f, -52f, 0f),
Control("up", "dpad", -1, 30f, 0f, -50f),
Control("right", "dpad", -1, 30f, 50f, 0f),
Control("down", "dpad", -1, 30f, 0f, 50f),
Control("left", "dpad", -1, 30f, -50f, 0f),
Control("ls", "ls", 0, 48f, 0f, 0f),
Control("rs", "rs", 1, 48f, 0f, 0f),
Control("a", "face", -1, 30f, 0f, 50f),
@@ -188,12 +188,69 @@ internal class LegacyGamepadLayout(private val context: Context, private val wid
settings.mapping[it.id] != ControllerPrefs.OFF && (it.id != "guide" || settings.steamButton) && (it.id != "qam" || settings.qamButton)
}.map { c ->
InputSurfaceElement(requireNotNull(InputControl.fromId(c.id)), (c.cx - c.halfW) / width, (c.cy - c.halfH) / height,
2 * c.halfW / width, 2 * c.halfH / height, floating = settings.adaptiveSticks, hideWhenIdle = c.stick >= 0 && settings.adaptiveSticks).bounded()
2 * c.halfW / width, 2 * c.halfH / height, floating = settings.adaptiveSticks, hideWhenIdle = c.stick >= 0 && settings.adaptiveSticks,
buttonShape = if (c.id in shoulderIds) InputButtonShape.PILL else InputButtonShape.CIRCLE).let(::widenStick).bounded()
}.toMutableList()
if (settings.keyboardButton) result += InputSurfaceElement(InputControl.A, .02f, .9f, .12f, .08f,
"builtin:keyboard", name = "Keyboard")
if (settings.keyboardButton) result += keyboard()
return result
}
private fun keyboard(): InputSurfaceElement {
val radius = dp(KEYBOARD_RADIUS_DP)
val cx = safe.left + dp(KEYBOARD_X_DP)
val cy = height - safe.bottom - dp(KEYBOARD_Y_DP)
return InputSurfaceElement(InputControl.A, (cx - radius) / width, (cy - radius) / height, 2 * radius / width, 2 * radius / height,
KEYBOARD_ID, name = "Keyboard", icon = InputButtonIcons.KEYBOARD, buttonShape = InputButtonShape.CIRCLE).bounded()
}
fun restyle(elements: List<InputSurfaceElement>): List<InputSurfaceElement> {
val dpad = elements.filter { it.id == "legacy:${it.control.id}" && it.control in DPAD && it.buttonShape == InputButtonShape.ROUNDED }
val centreX = dpad.map { (it.x + it.width / 2f) * width }.average().toFloat()
val centreY = dpad.map { (it.y + it.height / 2f) * height }.average().toFloat()
val resize = untouchedDpad(dpad, centreX, centreY)
return elements.map { e ->
when {
e.id == KEYBOARD_ID && e.icon == 0 && e.name == "Keyboard" && e.buttonShape == InputButtonShape.ROUNDED &&
e.x == .02f && e.y == .9f && e.width == .12f && e.height == .08f -> keyboard()
e.id == "legacy:${e.control.id}" && e.buttonShape == InputButtonShape.ROUNDED -> {
val round = e.copy(buttonShape = if (e.control.id in shoulderIds) InputButtonShape.PILL else InputButtonShape.CIRCLE)
(if (resize && e.control in DPAD) resizeDpad(round, centreX, centreY) else widenStick(round)).bounded()
}
else -> e
}
}
}
private fun untouchedDpad(dpad: List<InputSurfaceElement>, centreX: Float, centreY: Float): Boolean {
if (dpad.size != DPAD.size) return false
val radius = dpad[0].width * width / 2f
val tolerance = 1.5f
val offset = radius * LEGACY_DPAD_OFFSET_DP / LEGACY_DPAD_RADIUS_DP
return dpad.all { e ->
val old = controls.first { it.id == e.control.id }
val dx = (e.x + e.width / 2f) * width - centreX
val dy = (e.y + e.height / 2f) * height - centreY
abs(e.width * width / 2f - radius) <= tolerance && abs(e.height * height / 2f - radius) <= tolerance &&
abs(dx - offset * sign(old.offsetXDp)) <= tolerance && abs(dy - offset * sign(old.offsetYDp)) <= tolerance
}
}
private fun resizeDpad(e: InputSurfaceElement, centreX: Float, centreY: Float): InputSurfaceElement {
val old = controls.first { it.id == e.control.id }
val radius = e.width * width / 2f * old.radiusDp / LEGACY_DPAD_RADIUS_DP
val cx = centreX + ((e.x + e.width / 2f) * width - centreX) * abs(old.offsetXDp + old.offsetYDp) / LEGACY_DPAD_OFFSET_DP
val cy = centreY + ((e.y + e.height / 2f) * height - centreY) * abs(old.offsetXDp + old.offsetYDp) / LEGACY_DPAD_OFFSET_DP
return e.copy(x = (cx - radius) / width, y = (cy - radius) / height, width = 2 * radius / width, height = 2 * radius / height)
}
private fun widenStick(e: InputSurfaceElement): InputSurfaceElement {
val extra = e.width * (STICK_REACH - 1f)
return when (e.control) {
InputControl.LS -> (e.x - extra).coerceAtLeast(0f).let { x -> e.copy(x = x, width = e.x + e.width - x) }
InputControl.RS -> e.copy(width = (e.width + extra).coerceAtMost(1f - e.x))
else -> e
}
}
private companion object {
const val MIN_FACE_MM = 9.5f
const val FULL_SIZE_HEIGHT_MM = 85f
@@ -203,5 +260,13 @@ internal class LegacyGamepadLayout(private val context: Context, private val wid
const val SHOULDER_WIDTH = 1.45f
const val SHOULDER_HEIGHT = 0.8f
val shoulderIds = setOf("lb", "rb", "lt", "rt")
const val STICK_REACH = 1.25f
const val LEGACY_DPAD_RADIUS_DP = 26f
const val LEGACY_DPAD_OFFSET_DP = 52f
val DPAD = setOf(InputControl.UP, InputControl.RIGHT, InputControl.DOWN, InputControl.LEFT)
const val KEYBOARD_ID = "builtin:keyboard"
const val KEYBOARD_RADIUS_DP = 18f
const val KEYBOARD_X_DP = 90f
const val KEYBOARD_Y_DP = 34f
}
}
@@ -1,20 +1,36 @@
package com.droiddeck.launcher.input
import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Typeface
import android.os.Build
import android.view.Gravity
import android.view.HapticFeedbackConstants
import android.view.MotionEvent
import android.view.View
import android.view.WindowInsets
import android.widget.FrameLayout
import com.droiddeck.launcher.ui.InputSurfaceView
class OnScreenControls(context: Context, pad: PadBridge?) : FrameLayout(context) {
private val surface = InputSurfaceView(context, pad, inputRole = InputRole.PRIMARY)
private var layout: SavedInputLayout? = null
private val quickToggle = QuickToggle(context)
var isButtonsOnly = false
private set
var isQuickHidden = false
private set
var onTouchMiss: ((MotionEvent) -> Unit)?
get() = surface.onTouchMiss
set(value) { surface.onTouchMiss = value }
init { addView(surface, LayoutParams(-1, -1)) }
init {
addView(surface, LayoutParams(-1, -1))
val size = (QUICK_HIT_DP * 2 * resources.displayMetrics.density).toInt()
addView(quickToggle, LayoutParams(size, size, Gravity.START or Gravity.BOTTOM))
}
fun updateLayout(value: SavedInputLayout?) {
if (layout == value) return
@@ -27,18 +43,98 @@ class OnScreenControls(context: Context, pad: PadBridge?) : FrameLayout(context)
if (isButtonsOnly == enabled) return
releaseAll()
isButtonsOnly = enabled
isQuickHidden = false
render()
}
fun setQuickHidden(hidden: Boolean) {
if (isButtonsOnly || isQuickHidden == hidden) return
releaseAll()
isQuickHidden = hidden
render()
}
private fun render() {
val elements = layout?.elements.orEmpty()
surface.updateCustomLayout(if (isButtonsOnly) elements.filter { it.control == InputControl.GUIDE || it.control == InputControl.QAM || it.id == "builtin:keyboard" } else elements)
surface.updateStyle(layout?.style ?: InputSurfaceStyle())
surface.updateCustomLayout(when {
isButtonsOnly -> elements.filter { it.control == InputControl.GUIDE || it.control == InputControl.QAM || it.id == "builtin:keyboard" }
isQuickHidden -> elements.filter { it.id == "builtin:keyboard" }
else -> elements
})
val style = layout?.style ?: InputSurfaceStyle()
surface.updateStyle(style)
quickToggle.tint = style.tint
quickToggle.alpha = style.opacity / 100f
quickToggle.visibility = if (isButtonsOnly || layout == null) GONE else VISIBLE
quickToggle.invalidate()
}
fun takesTouchAt(x: Float, y: Float) = surface.takesTouchAt(x, y)
fun takesTouchAt(x: Float, y: Float) = surface.takesTouchAt(x, y) ||
quickToggle.visibility == VISIBLE && x >= quickToggle.left && x < quickToggle.right && y >= quickToggle.top && y < quickToggle.bottom
fun releaseAll() = surface.releaseInputs()
fun reload() { releaseAll(); render() }
override fun onDetachedFromWindow() { releaseAll(); super.onDetachedFromWindow() }
override fun onApplyWindowInsets(insets: WindowInsets): WindowInsets {
val cutout = if (Build.VERSION.SDK_INT >= 28) insets.displayCutout else null
val offset = ((QUICK_CENTER_DP - QUICK_HIT_DP) * resources.displayMetrics.density).toInt()
val params = quickToggle.layoutParams as LayoutParams
val left = (cutout?.safeInsetLeft ?: 0) + offset
val bottom = (cutout?.safeInsetBottom ?: 0) + offset
if (params.leftMargin != left || params.bottomMargin != bottom) {
params.leftMargin = left
params.bottomMargin = bottom
quickToggle.layoutParams = params
}
return super.onApplyWindowInsets(insets)
}
private inner class QuickToggle(context: Context) : View(context) {
var tint: Int? = ControllerPrefs.STEAM_BLUE
private val density = resources.displayMetrics.density
private var armed = false
private val fill = Paint(Paint.ANTI_ALIAS_FLAG)
private val stroke = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.STROKE; strokeWidth = 1.5f * density }
private val text = Paint(Paint.ANTI_ALIAS_FLAG).apply {
textAlign = Paint.Align.CENTER
typeface = Typeface.create(Typeface.DEFAULT, Typeface.BOLD)
textSize = 22 * density
}
override fun onDraw(canvas: Canvas) {
val x = width / 2f
val y = height / 2f
val radius = QUICK_RADIUS_DP * density
val color = tint
fill.color = if (color != null) InputSurfaceView.shade(color, 190, 0.12f) else (InputSurfaceView.SURFACE and 0x00ffffff) or (190 shl 24)
canvas.drawCircle(x, y, radius, fill)
stroke.color = if (color != null) InputSurfaceView.light(color, 150, 0.25f) else InputSurfaceView.LINE
canvas.drawCircle(x, y, radius, stroke)
text.color = if (color != null) InputSurfaceView.light(color, 210, 0.75f) else InputSurfaceView.TEXT
canvas.drawText(if (isQuickHidden) "+" else "−", x, y + text.textSize * 0.35f, text)
}
@SuppressLint("ClickableViewAccessibility")
override fun onTouchEvent(event: MotionEvent): Boolean {
when (event.actionMasked) {
MotionEvent.ACTION_DOWN -> armed = true
MotionEvent.ACTION_CANCEL -> armed = false
MotionEvent.ACTION_UP -> {
if (armed && event.x in 0f..width.toFloat() && event.y in 0f..height.toFloat()) {
performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY)
setQuickHidden(!isQuickHidden)
}
armed = false
}
}
return true
}
}
private companion object {
const val QUICK_CENTER_DP = 34f
const val QUICK_HIT_DP = 26f
const val QUICK_RADIUS_DP = 18f
}
}
@@ -8,6 +8,7 @@ import android.graphics.BitmapFactory
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Path
import android.graphics.RadialGradient
import android.graphics.RectF
import android.graphics.Shader
@@ -128,10 +129,11 @@ class InputSurfaceView(
}
}
}
canvas.clipChildren = customLayout.none { it.kind == InputElementKind.STICK && classic(it) }
for (element in customLayout) {
val source = pad?.let { InputSurfaceSource(it, inputRole, element).also { s -> elementSources += s } }
canvas.addView(when (element.kind) {
InputElementKind.STICK -> StickView(context, source, element.floating, element.hideWhenIdle && pad != null)
InputElementKind.STICK -> StickView(context, element, source, element.floating, element.hideWhenIdle && pad != null)
InputElementKind.TRACKPAD -> TrackpadView(context, element.control == InputControl.RIGHT_PAD, source = source)
InputElementKind.DPAD -> DirectionPad(context, source)
else -> HoldButton(context, element, source)
@@ -183,16 +185,50 @@ class InputSurfaceView(
color = TEXT_DIM
}
protected fun drawSurface(canvas: Canvas, lit: Boolean, shape: InputButtonShape = InputButtonShape.ROUNDED) {
val inset = density
protected fun drawSurface(canvas: Canvas, lit: Boolean, shape: InputButtonShape = InputButtonShape.ROUNDED, classic: Boolean = false) {
val inset = if (classic && tint != null) 0.75f * density else density
rect.set(inset, inset, width - inset, height - inset)
val radius = when (shape) { InputButtonShape.CIRCLE, InputButtonShape.PILL -> min(width, height) / 2f; InputButtonShape.RECTANGLE -> 2 * density; else -> CORNER * density }
val color = tint
if (classic && color != null) {
val corner = if (shape == InputButtonShape.PILL) radius * 0.55f else radius
fill.color = if (lit) shade(color, 160, 1f) else shade(color, 80, 0.12f)
canvas.drawRoundRect(rect, corner, corner, fill)
stroke.color = if (lit) light(color, 230, 0.7f) else light(color, 150, 0.25f)
stroke.strokeWidth = 1.5f * density
canvas.drawRoundRect(rect, corner, corner, stroke)
return
}
fill.color = tint?.let { color -> (color and 0x00ffffff) or ((if (lit) 140 else 48) shl 24) } ?: if (lit) ACCENT_WASH else SURFACE
canvas.drawRoundRect(rect, radius, radius, fill)
stroke.color = tint?.let { color -> (color and 0x00ffffff) or ((if (lit) 255 else 160) shl 24) } ?: if (lit) ACCENT else LINE
stroke.strokeWidth = (if (lit) 2f else 1f) * density
canvas.drawRoundRect(rect, radius, radius, stroke)
}
protected fun drawCircle(canvas: Canvas, x: Float, y: Float, radius: Float, fillColor: Int, strokeColor: Int) {
fill.color = fillColor
canvas.drawCircle(x, y, radius, fill)
stroke.color = strokeColor
stroke.strokeWidth = 1.5f * density
canvas.drawCircle(x, y, radius, stroke)
}
protected fun drawKeyboard(canvas: Canvas, x: Float, y: Float, lit: Boolean) {
val color = tint ?: return
stroke.color = if (lit) light(color, 230, 0.7f) else light(color, 150, 0.25f)
stroke.strokeWidth = 1.5f * density
rect.set(x - 10 * density, y - 7 * density, x + 10 * density, y + 7 * density)
canvas.drawRoundRect(rect, 2 * density, 2 * density, stroke)
for (row in 0..1) for (col in 0..2) {
val kx = x + (-6f + col * 5f) * density
val ky = y + (-3f + row * 4f) * density
canvas.drawLine(kx, ky, kx + 2 * density, ky, stroke)
}
canvas.drawLine(x - 5 * density, y + 4 * density, x + 5 * density, y + 4 * density, stroke)
}
protected fun textColor(lit: Boolean) = if (lit) Color.WHITE else tint?.let { light(it, 210, 0.75f) } ?: TEXT
}
private class HoldButton(context: Context, private val element: InputSurfaceElement, private val source: InputSurfaceSource?) : Surface(context) {
@@ -212,9 +248,10 @@ class InputSurfaceView(
override fun onDraw(canvas: Canvas) {
val lit = if (element.toggle) source?.latched == true else down
drawSurface(canvas, lit, element.buttonShape)
val classic = classic(element)
drawSurface(canvas, lit, element.buttonShape, classic)
val cx = width / 2f
labelPaint.color = if (lit) ACCENT else TEXT
labelPaint.color = if (classic && tint != null) textColor(lit) else if (lit) ACCENT else TEXT
bitmap?.let {
val scale = min(width * .84f / it.width, height * .84f / it.height)
imageRect.set(cx - it.width * scale / 2, (height - it.height * scale) / 2,
@@ -222,8 +259,23 @@ class InputSurfaceView(
canvas.drawBitmap(it, null, imageRect, labelPaint)
return
}
if (classic && element.id == "builtin:keyboard" && element.icon == InputButtonIcons.KEYBOARD) { drawKeyboard(canvas, cx, height / 2f, lit); return }
if (element.icon != 0 && InputButtonIcons.draw(canvas, element.icon, cx, height / 2f, min(width, height) * .68f, labelPaint, symbol)) return
if (!element.showLabel) return
labelPaint.style = Paint.Style.FILL
if (classic && element.name == element.control.label) {
val radius = min(width, height) / 2f
val direction = DIRECTIONS.indexOf(element.control)
if (direction >= 0) { drawArrow(canvas, cx, height / 2f, radius * 0.34f, direction, labelPaint); return }
val glyph = glyph(element.control)
labelPaint.textSize = when {
element.buttonShape == InputButtonShape.PILL -> height / 2f * 0.8f
glyph.length > 2 -> 11 * density
else -> radius * if (glyph.length == 2) 0.62f else 0.85f
}
canvas.drawText(glyph, cx, height / 2f + labelPaint.textSize * .35f, labelPaint)
return
}
labelPaint.textSize = min(height * .3f, 30 * density)
val labelWidth = labelPaint.measureText(element.name)
if (labelWidth > width * .84f) labelPaint.textSize *= width * .84f / labelWidth
@@ -350,7 +402,7 @@ class InputSurfaceView(
}
}
private inner class StickView(context: Context, private val source: InputSurfaceSource? = null, private val floating: Boolean = true, private val hideWhenIdle: Boolean = false) : Surface(context) {
private inner class StickView(context: Context, private val element: InputSurfaceElement, private val source: InputSurfaceSource? = null, private val floating: Boolean = true, private val hideWhenIdle: Boolean = false) : Surface(context) {
private var touching = false
private var clicking = false
private var lastUp = 0L
@@ -368,11 +420,32 @@ class InputSurfaceView(
private fun reach() = min(width, height) * 0.30f
private fun centreX() = when {
!classic(element) || width <= height -> width / 2f
element.control == InputControl.LS -> width - height / 2f
else -> height / 2f
}
override fun onDraw(canvas: Canvas) {
if (hideWhenIdle && !touching) return
drawSurface(canvas, clicking)
val cx = if (touching) originX else width / 2f
val cx = if (touching) originX else centreX()
val cy = if (touching) originY else height / 2f
val color = tint
if (classic(element) && color != null) {
val radius = min(width, height) / 2f - 0.75f * density
drawCircle(canvas, cx, cy, radius,
if (touching) shade(color, 160, 1f) else shade(color, 60, 0.12f), if (touching) light(color, 230, 0.7f) else light(color, 150, 0.25f))
val knobRadius = radius * 0.46f
drawCircle(canvas, cx + knobX, cy + knobY, knobRadius,
if (touching || clicking) shade(color, 160, 1f) else shade(color, 120, 0.35f), if (touching) light(color, 230, 0.7f) else light(color, 150, 0.25f))
if (!element.showLabel) return
labelPaint.color = textColor(touching)
labelPaint.textSize = knobRadius * 0.8f
val label = if (element.name == element.control.label) glyph(element.control) else element.name
canvas.drawText(label, cx + knobX, cy + knobY + labelPaint.textSize * 0.35f, labelPaint)
return
}
drawSurface(canvas, clicking)
ring.strokeWidth = 2 * density
ring.color = if (touching) ACCENT else LINE
canvas.drawCircle(cx, cy, reach(), ring)
@@ -389,7 +462,7 @@ class InputSurfaceView(
downX = event.x
downY = event.y
travel = 0f
originX = if (floating) event.x else width / 2f
originX = if (floating) event.x else centreX()
originY = if (floating) event.y else height / 2f
touching = true
performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY)
@@ -508,13 +581,44 @@ class InputSurfaceView(
private val ACCENT_WASH = Color.argb(0x2E, 0x1A, 0x9F, 0xFF)
private val ACCENT_GLOW = Color.argb(0x66, 0x1A, 0x9F, 0xFF)
private val ON_ACCENT = Color.rgb(0x03, 0x11, 0x1F)
private val SURFACE = Color.rgb(0x0A, 0x0B, 0x0D)
private val LINE = Color.rgb(0x26, 0x29, 0x2E)
internal val SURFACE = Color.rgb(0x0A, 0x0B, 0x0D)
internal val LINE = Color.rgb(0x26, 0x29, 0x2E)
private val GUIDE = Color.rgb(0x16, 0x18, 0x1B)
private val TEXT = Color.rgb(0xF2, 0xF4, 0xF7)
internal val TEXT = Color.rgb(0xF2, 0xF4, 0xF7)
private val TEXT_DIM = Color.rgb(0x7A, 0x80, 0x8A)
private val KNOB = Color.rgb(0x2A, 0x2D, 0x33)
private fun classic(element: InputSurfaceElement) = (element.id == "legacy:${element.control.id}" || element.id == "builtin:keyboard") &&
(element.buttonShape == InputButtonShape.CIRCLE || element.buttonShape == InputButtonShape.PILL)
private val DIRECTIONS = listOf(InputControl.UP, InputControl.RIGHT, InputControl.DOWN, InputControl.LEFT)
internal fun shade(tint: Int, alpha: Int, f: Float) =
Color.argb(alpha, (Color.red(tint) * f).toInt(), (Color.green(tint) * f).toInt(), (Color.blue(tint) * f).toInt())
internal fun light(tint: Int, alpha: Int, f: Float) = Color.argb(alpha, (Color.red(tint) + (255 - Color.red(tint)) * f).toInt(),
(Color.green(tint) + (255 - Color.green(tint)) * f).toInt(), (Color.blue(tint) + (255 - Color.blue(tint)) * f).toInt())
private fun glyph(control: InputControl) = when (control) {
InputControl.LS -> "L"
InputControl.RS -> "R"
InputControl.SELECT -> "⧉"
InputControl.START -> "☰"
InputControl.GUIDE -> "◉"
InputControl.QAM -> "⋯"
else -> control.id.uppercase()
}
private fun drawArrow(canvas: Canvas, x: Float, y: Float, size: Float, direction: Int, paint: Paint) {
val (fx, fy) = when (direction) { 0 -> 0f to -1f; 1 -> 1f to 0f; 2 -> 0f to 1f; else -> -1f to 0f }
val path = Path()
path.moveTo(x + fx * size, y + fy * size)
path.lineTo(x - fx * size * 0.7f - fy * size, y - fy * size * 0.7f + fx * size)
path.lineTo(x - fx * size * 0.7f + fy * size, y - fy * size * 0.7f - fx * size)
path.close()
canvas.drawPath(path, paint)
}
internal fun dp(context: Context, value: Int): Int = (value * context.resources.displayMetrics.density + 0.5f).toInt()
internal fun outline(context: Context, radius: Float, fill: Int) = GradientDrawable().apply {
@@ -314,6 +314,8 @@ class DrawerActions(
val onPause: () -> Unit = {},
val onPipAutoEnter: (Boolean) -> Unit = {},
val unfoldedControls: Boolean? = null,
val adaptiveSticks: Boolean? = null,
val onAdaptiveSticks: (Boolean) -> Unit = {},
val onUnfoldedControls: (Boolean) -> Unit = {},
val unfoldedControlsWithController: Boolean = false,
val onUnfoldedControlsWithController: (Boolean) -> Unit = {},
@@ -636,6 +638,10 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
else 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)),
if (!a.steam && a.oscMode == SessionPrefs.OSC_STEAM_TOUCH) SessionPrefs.OSC_AUTO else a.oscMode,
chipModifier = focus.track(page, "osc"), onPick = a.onOsc)
a.adaptiveSticks?.let { on ->
ToggleRow(host, "adaptive-sticks", stringResource(R.string.ctrl_adaptive), null, on,
chipModifier = focus.track(page, "adaptive-sticks"), onChange = a.onAdaptiveSticks)
}
a.onEditSteamTouch?.let { edit ->
ActionRow(stringResource(R.string.osc_steam_layout), stringResource(R.string.osc_steam_layout_hint), stringResource(R.string.ctrl_edit), edit)
}