mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
Fix desktop profile selection and simplify default touch layouts
This commit is contained in:
1 parent
08526f8283
commit
c2d7765619
16 files changed
+265
-88
No files matched your search
@@ -1185,6 +1185,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
SessionDrawer(drawerOpen || (docked && drawerPinned), drawerPage, drawerControllerActive, onPageChange = { drawerPage = it }, docked = docked,
|
||||
backRequest = drawerBackRequests, onLayerChange = { drawerLayerOpen = it }, a = DrawerActions(
|
||||
steam = SessionState.mode == SessionService.MODE_STEAM,
|
||||
desktop = SessionState.mode == SessionService.MODE_DESKTOP,
|
||||
systemPowerVr = com.droiddeck.launcher.gpu.SystemVulkanDriver.usesDefault(
|
||||
SessionPrefs.linuxDriver(this@SessionActivity)),
|
||||
direct = noSteamSession(),
|
||||
|
||||
@@ -1,16 +1,49 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Paint
|
||||
import android.graphics.Path
|
||||
import android.graphics.drawable.Drawable
|
||||
import com.droiddeck.launcher.R
|
||||
|
||||
object InputButtonIcons {
|
||||
// Persisted symbol IDs must not depend on Android resource IDs or overlap Linux key codes.
|
||||
const val MENU = 1001
|
||||
const val KEYBOARD = 1002
|
||||
const val STEAM = 1003
|
||||
const val QUICK_ACCESS = 1004
|
||||
|
||||
fun has(code: Int): Boolean = code in codes
|
||||
|
||||
val codes = listOf(28, 14, 15, 57, 42, 54, 29, 97, 125, 103, 108, 105, 106)
|
||||
private val keyCodes = listOf(28, 14, 15, 57, 42, 54, 29, 97, 125, 103, 108, 105, 106)
|
||||
val codes = listOf(MENU, KEYBOARD, STEAM, QUICK_ACCESS) + keyCodes
|
||||
|
||||
fun draw(canvas: Canvas, code: Int, cx: Float, cy: Float, box: Float, paint: Paint): Boolean {
|
||||
if (!has(code)) return false
|
||||
fun label(context: Context, code: Int): String = when (code) {
|
||||
MENU -> context.getString(R.string.touch_droiddeck_menu)
|
||||
KEYBOARD -> context.getString(R.string.drawer_keyboard)
|
||||
STEAM -> context.getString(R.string.drawer_steam_menu)
|
||||
QUICK_ACCESS -> context.getString(R.string.drawer_open_qam)
|
||||
else -> pcKeyLabel(context, code)
|
||||
}
|
||||
|
||||
fun drawable(context: Context, code: Int): Drawable? = when (code) {
|
||||
MENU -> R.drawable.ic_stat_session
|
||||
KEYBOARD -> R.drawable.ic_bottom_keyboard
|
||||
STEAM -> R.drawable.ic_input_steam
|
||||
QUICK_ACCESS -> R.drawable.ic_input_quick_access
|
||||
else -> null
|
||||
}?.let { context.getDrawable(it)?.mutate() }
|
||||
|
||||
fun draw(canvas: Canvas, code: Int, cx: Float, cy: Float, box: Float, paint: Paint, drawable: Drawable? = null): Boolean {
|
||||
if (drawable != null) {
|
||||
drawable.setTint(paint.color)
|
||||
val half = box / 2f
|
||||
drawable.setBounds((cx - half).toInt(), (cy - half).toInt(), (cx + half).toInt(), (cy + half).toInt())
|
||||
drawable.draw(canvas)
|
||||
return true
|
||||
}
|
||||
if (code !in keyCodes) return false
|
||||
val h = box / 2f
|
||||
val stroke = box * 0.085f
|
||||
val path = Path()
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.json.JSONObject
|
||||
import java.util.UUID
|
||||
|
||||
object InputLibraries {
|
||||
private const val VERSION = 6
|
||||
private const val VERSION = 7
|
||||
private const val KEY = "library"
|
||||
private const val RECOVERY = "library-recovery."
|
||||
const val OVERLAY = "builtin.overlay"
|
||||
@@ -76,18 +76,21 @@ object InputLibraries {
|
||||
|
||||
private fun migrate(context: Context): InputLibrary {
|
||||
val profiles = mutableListOf<SavedInputProfile>()
|
||||
val layouts = mutableListOf(
|
||||
SavedInputLayout(OVERLAY, "Built-in gamepad", template = InputLayoutTemplate.OVERLAY),
|
||||
SavedInputLayout(DECK, "Deck grips + trackpads", template = InputLayoutTemplate.DECK),
|
||||
SavedInputLayout(TRACKPAD, "Trackpad + keyboard", template = InputLayoutTemplate.TRACKPAD),
|
||||
)
|
||||
val bindings = mutableListOf<SavedInputBindings>()
|
||||
val stock = InputStockLayouts.layouts()
|
||||
val layouts = (listOf(SavedInputLayout(OVERLAY, "Built-in gamepad", template = InputLayoutTemplate.OVERLAY)) + stock).toMutableList()
|
||||
val bindings = InputStockLayouts.presets(stock).toMutableList()
|
||||
for (id in listOf(InputProfile.GAME, InputProfile.DESKTOP)) {
|
||||
val old = InputProfiles.readLegacy(context, id)
|
||||
val name = if (id == InputProfile.GAME) "Game" else "Desktop"
|
||||
val layout = SavedInputLayout("$id.layout", "$name touch", InputSurfaceLayout.readLegacy(context, id))
|
||||
layouts += layout
|
||||
val legacySurface = InputSurfaceLayout.hasLegacy(context, id) ||
|
||||
old.bindings[InputRole.SECONDARY] != InputProfile.defaults(id).bindings[InputRole.SECONDARY]
|
||||
val layout = if (legacySurface) SavedInputLayout("$id.layout", "$name touch", InputSurfaceLayout.readLegacy(context, id)).also { layouts += it }
|
||||
else stock.first { it.id == if (id == InputProfile.DESKTOP) TRACKPAD else DECK }
|
||||
val parts = InputRole.entries.associateWith { role ->
|
||||
if (role == InputRole.SECONDARY && !legacySurface) {
|
||||
val preset = bindings.first { it.layoutId == layout.id }
|
||||
return@associateWith InputPart(preset.id, layout.id)
|
||||
}
|
||||
val preset = SavedInputBindings("$id.${role.name.lowercase()}", "$name / ${role.name.lowercase()}",
|
||||
role == InputRole.PHYSICAL, if (role == InputRole.SECONDARY) layout.id else null,
|
||||
old.bindings[role].orEmpty(), keys = if (role == InputRole.PHYSICAL) old.keys else emptyList())
|
||||
|
||||
@@ -203,7 +203,7 @@ data class InputLibrary(
|
||||
val preset = SavedInputBindings(if (isPrivate) previous.id else newInputId(),
|
||||
if (isPrivate) previous.name else (p.name + " / " + role.name.lowercase()).take(80), role == InputRole.PHYSICAL,
|
||||
part.layout?.takeIf { layout(id, role)?.editable == true }, defaults.bindings[role].orEmpty(),
|
||||
elements = layout(id, role)?.elements.orEmpty().filter { it.id == "builtin:keyboard" }
|
||||
elements = (layout(id, role)?.let { InputStockLayouts.actions(it) } ?: emptyMap()) + layout(id, role)?.elements.orEmpty().filter { it.id == "builtin:keyboard" }
|
||||
.associate { it.id to InputAction.Command(InputCommand.KEYBOARD) })
|
||||
result = result.withPreset(preset)
|
||||
part.copy(bindings = preset.id)
|
||||
|
||||
@@ -3,14 +3,14 @@ package com.droiddeck.launcher.input
|
||||
internal object InputStockLayouts {
|
||||
const val DECK = "preset.deck"
|
||||
const val TRACKPAD = "preset.trackpad"
|
||||
const val LEFT = "preset.left-pad"
|
||||
const val RIGHT = "preset.right-pad"
|
||||
const val BOTH = "preset.both-pads"
|
||||
const val GRIPS = "preset.grips"
|
||||
const val GAMEPAD = "preset.gamepad"
|
||||
|
||||
private fun commands() = listOf("Menu", "Keyboard", "Steam", "Quick access").mapIndexed { i, name ->
|
||||
InputSurfaceElement(InputControl.A, .02f + i * .245f, .01f, .225f, .11f, "command:$i", name = name)
|
||||
private fun commands(indices: List<Int>): List<InputSurfaceElement> {
|
||||
val names = listOf("DroidDeck menu", "Keyboard", "Steam", "Quick access")
|
||||
val icons = listOf(InputButtonIcons.MENU, InputButtonIcons.KEYBOARD, InputButtonIcons.STEAM, InputButtonIcons.QUICK_ACCESS)
|
||||
val step = .98f / indices.size
|
||||
return indices.mapIndexed { position, i ->
|
||||
InputSurfaceElement(InputControl.A, .02f + position * step, .01f, step - .02f, .11f,
|
||||
"command:$i", name = names[i], icon = icons[i])
|
||||
}
|
||||
}
|
||||
private fun commandActions(): Map<String, InputAction> = listOf(InputCommand.MENU, InputCommand.KEYBOARD, InputCommand.STEAM, InputCommand.QUICK_ACCESS)
|
||||
.mapIndexed { i, command -> "command:$i" to InputAction.Command(command) }.toMap()
|
||||
@@ -19,66 +19,23 @@ internal object InputStockLayouts {
|
||||
}
|
||||
private fun pads() = listOf(InputSurfaceElement(InputControl.LEFT_PAD, .02f, .14f, .47f, .62f),
|
||||
InputSurfaceElement(InputControl.RIGHT_PAD, .51f, .14f, .47f, .62f))
|
||||
private fun single(right: Boolean) = listOf(InputSurfaceElement(if (right) InputControl.RIGHT_PAD else InputControl.LEFT_PAD, .02f, .14f, .96f, .62f),
|
||||
InputSurfaceElement(if (right) InputControl.RIGHT_CLICK else InputControl.LEFT_CLICK, .02f, .78f, .96f, .20f, name = "Click"))
|
||||
|
||||
fun layouts() = listOf(
|
||||
SavedInputLayout(InputLibraries.DECK, "Deck grips + trackpads", commands() + pads() + grips()),
|
||||
SavedInputLayout(InputLibraries.TRACKPAD, "Trackpad + keyboard", commands().take(2).mapIndexed { i, e -> e.copy(x = .02f + i * .49f, width = .47f) } + listOf(
|
||||
InputSurfaceElement(InputControl.RIGHT_PAD, .02f, .14f, .96f, .62f, mouseGestures = true),
|
||||
InputSurfaceElement(InputControl.A, .02f, .78f, .47f, .20f, name = "Left click"),
|
||||
InputSurfaceElement(InputControl.B, .51f, .78f, .47f, .20f, name = "Right click"))),
|
||||
SavedInputLayout("builtin.left-pad", "Left Deck trackpad", commands() + single(false)),
|
||||
SavedInputLayout("builtin.right-pad", "Right Deck trackpad", commands() + single(true)),
|
||||
SavedInputLayout("builtin.both-pads", "Two Deck trackpads", commands() + pads() + listOf(
|
||||
InputSurfaceElement(InputControl.LEFT_CLICK, .02f, .78f, .47f, .20f, name = "Left pad click"),
|
||||
InputSurfaceElement(InputControl.RIGHT_CLICK, .51f, .78f, .47f, .20f, name = "Right pad click"))),
|
||||
SavedInputLayout("builtin.grips", "Deck grips", commands() + listOf(InputControl.L4, InputControl.R4, InputControl.L5, InputControl.R5).mapIndexed { i, c ->
|
||||
InputSurfaceElement(c, .02f + (i % 2) * .49f, .14f + (i / 2) * .43f, .47f, .41f)
|
||||
}),
|
||||
SavedInputLayout("builtin.gamepad", "Compact gamepad", gamepad()),
|
||||
SavedInputLayout(InputLibraries.DECK, "Deck grips + trackpads", commands(listOf(2, 3, 0)) + pads() + grips(), screen = InputLayoutScreen.SECONDARY),
|
||||
SavedInputLayout(InputLibraries.TRACKPAD, "Trackpad + keyboard", commands(listOf(0, 1)) +
|
||||
InputSurfaceElement(InputControl.RIGHT_PAD, .02f, .14f, .96f, .84f, mouseGestures = true), screen = InputLayoutScreen.SECONDARY),
|
||||
)
|
||||
|
||||
private fun gamepad(): List<InputSurfaceElement> {
|
||||
val w = 600f; val h = 500f
|
||||
val boxes = GamepadGeometry.layout(w, h, 1f, portraitDock = true)
|
||||
val result = mutableListOf<InputSurfaceElement>()
|
||||
val controls = mapOf(GamepadGeometry.Slot.LEFT_MAIN to InputControl.LS, GamepadGeometry.Slot.RIGHT_MAIN to InputControl.RS,
|
||||
GamepadGeometry.Slot.LEFT_OUTER_SHOULDER to InputControl.LT, GamepadGeometry.Slot.LEFT_INNER_SHOULDER to InputControl.LB,
|
||||
GamepadGeometry.Slot.RIGHT_INNER_SHOULDER to InputControl.RB, GamepadGeometry.Slot.RIGHT_OUTER_SHOULDER to InputControl.RT,
|
||||
GamepadGeometry.Slot.VIEW to InputControl.SELECT, GamepadGeometry.Slot.MENU to InputControl.START,
|
||||
GamepadGeometry.Slot.STEAM to InputControl.GUIDE, GamepadGeometry.Slot.QAM to InputControl.QAM,
|
||||
GamepadGeometry.Slot.L4 to InputControl.L4, GamepadGeometry.Slot.L5 to InputControl.L5,
|
||||
GamepadGeometry.Slot.R4 to InputControl.R4, GamepadGeometry.Slot.R5 to InputControl.R5)
|
||||
for ((slot, box) in boxes) {
|
||||
fun add(c: InputControl, x: Float = box.left, y: Float = box.top, width: Float = box.width, height: Float = box.height,
|
||||
id: String = "legacy:${c.id}", kind: InputElementKind = InputElementKind.from(c), name: String = c.label) {
|
||||
result += InputSurfaceElement(c, x / w, y / h, width / w, height / h, id, kind, name, floating = false).bounded()
|
||||
}
|
||||
when (slot) {
|
||||
GamepadGeometry.Slot.LEFT_SECOND -> add(InputControl.LS, id = "compact:dpad", kind = InputElementKind.DPAD, name = "D-pad")
|
||||
GamepadGeometry.Slot.RIGHT_SECOND -> {
|
||||
val size = minOf(box.width, box.height) * .32f
|
||||
add(InputControl.Y, box.cx - size / 2, box.top, size, size)
|
||||
add(InputControl.X, box.left, box.cy - size / 2, size, size)
|
||||
add(InputControl.B, box.right - size, box.cy - size / 2, size, size)
|
||||
add(InputControl.A, box.cx - size / 2, box.bottom - size, size, size)
|
||||
}
|
||||
GamepadGeometry.Slot.PANELS -> add(InputControl.A, id = "command:0", name = "Menu")
|
||||
else -> controls[slot]?.let { add(it) }
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
fun actions(layout: SavedInputLayout): Map<String, InputAction> = commandActions().filterKeys { id -> layout.elements.any { it.id == id } } + if (layout.id == InputLibraries.TRACKPAD) mapOf(
|
||||
fun actions(layout: SavedInputLayout): Map<String, InputAction> = (commandActions() + if (layout.id == InputLibraries.TRACKPAD) mapOf(
|
||||
"legacy:right-pad" to InputAction.Pointer(), "legacy:a" to InputAction.MouseButton(272), "legacy:b" to InputAction.MouseButton(273),
|
||||
) else if (layout.id == "builtin.gamepad") mapOf("compact:dpad" to InputAction.Native()) else emptyMap()
|
||||
) else emptyMap()).filterKeys { id -> layout.elements.any { it.id == id } }
|
||||
|
||||
fun clicks(layout: SavedInputLayout): Map<String, InputAction> = if (layout.id == InputLibraries.TRACKPAD)
|
||||
mapOf("legacy:right-pad" to InputAction.MouseButton(272)) else emptyMap()
|
||||
|
||||
fun presets(layouts: List<SavedInputLayout>) = layouts.zip(listOf(DECK, TRACKPAD, LEFT, RIGHT, BOTH, GRIPS, GAMEPAD)) { layout, id ->
|
||||
SavedInputBindings(id, layout.name, false, layout.id, elements = actions(layout), clicks = clicks(layout))
|
||||
fun presets(layouts: List<SavedInputLayout>) = layouts.map { layout ->
|
||||
val desktop = layout.id == InputLibraries.TRACKPAD
|
||||
SavedInputBindings(if (desktop) TRACKPAD else DECK, layout.name, false, layout.id,
|
||||
controls = InputProfile.defaults(if (desktop) InputProfile.DESKTOP else InputProfile.GAME).bindings[InputRole.SECONDARY].orEmpty(),
|
||||
elements = actions(layout), clicks = clicks(layout))
|
||||
}
|
||||
}
|
||||
@@ -58,6 +58,8 @@ object InputSurfaceLayout {
|
||||
fun read(context: Context, profile: String, role: InputRole = InputRole.SECONDARY): List<InputSurfaceElement> =
|
||||
InputLibraries.read(context).layout(profile, role)?.elements.orEmpty()
|
||||
|
||||
internal fun hasLegacy(context: Context, profile: String) = prefs(context).contains(profile)
|
||||
|
||||
internal fun readLegacy(context: Context, profile: String): List<InputSurfaceElement> {
|
||||
val text = prefs(context).getString(profile, null) ?: return defaults()
|
||||
return runCatching {
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.droiddeck.launcher.ui
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.foundation.Canvas
|
||||
@@ -26,14 +27,16 @@ internal fun InputElementProperties(element: InputSurfaceElement, onChange: (Inp
|
||||
val open = host.open == "element-icon"
|
||||
SettingsRow(stringResource(R.string.input_button_symbol), null, highlighted = open) {
|
||||
Box {
|
||||
ValueChip(if (element.image.isNotEmpty()) stringResource(R.string.input_imported_image) else if (element.icon == 0) stringResource(R.string.input_button_text) else pcKeyLabel(context, element.icon), open) { host.open = if (open) null else "element-icon" }
|
||||
ValueChip(if (element.image.isNotEmpty()) stringResource(R.string.input_imported_image) else if (element.icon == 0) stringResource(R.string.input_button_text) else InputButtonIcons.label(context, element.icon), open) { host.open = if (open) null else "element-icon" }
|
||||
AnchoredMenu(open, onDismiss = { host.open = null }, title = stringResource(R.string.input_button_symbol)) { firstItemFocus ->
|
||||
MenuItem(stringResource(R.string.input_button_text), element.icon == 0 && element.image.isEmpty(), focusRequester = firstItemFocus) { onChange(element.copy(icon = 0, image = "")); host.open = null }
|
||||
for (code in InputButtonIcons.codes) MenuItem(pcKeyLabel(context, code), element.icon == code && element.image.isEmpty(), leading = {
|
||||
for (code in InputButtonIcons.codes) MenuItem(InputButtonIcons.label(context, code), element.icon == code && element.image.isEmpty(), leading = {
|
||||
val color = MaterialTheme.colorScheme.onSurface
|
||||
val symbol = remember(context, code) { InputButtonIcons.drawable(context, code) }
|
||||
val paint = remember { android.graphics.Paint(android.graphics.Paint.ANTI_ALIAS_FLAG) }
|
||||
Canvas(Modifier.size(22.dp)) {
|
||||
val paint = android.graphics.Paint(android.graphics.Paint.ANTI_ALIAS_FLAG).apply { this.color = android.graphics.Color.argb((color.alpha * 255).toInt(), (color.red * 255).toInt(), (color.green * 255).toInt(), (color.blue * 255).toInt()) }
|
||||
InputButtonIcons.draw(drawContext.canvas.nativeCanvas, code, size.width / 2, size.height / 2, size.minDimension, paint)
|
||||
paint.color = android.graphics.Color.argb((color.alpha * 255).toInt(), (color.red * 255).toInt(), (color.green * 255).toInt(), (color.blue * 255).toInt())
|
||||
InputButtonIcons.draw(drawContext.canvas.nativeCanvas, code, size.width / 2, size.height / 2, size.minDimension, paint, symbol)
|
||||
}
|
||||
}) { onChange(element.copy(icon = code, image = "")); host.open = null }
|
||||
}
|
||||
|
||||
@@ -197,6 +197,7 @@ class InputSurfaceView(
|
||||
|
||||
private class HoldButton(context: Context, private val element: InputSurfaceElement, private val source: InputSurfaceSource?) : Surface(context) {
|
||||
private var down = false
|
||||
private val symbol = InputButtonIcons.drawable(context, element.icon)
|
||||
private val bitmap = element.image.takeIf { it.matches(Regex("[A-Za-z0-9_.-]{1,128}")) && it != "." && it != ".." }?.let { name ->
|
||||
val file = File(File(context.filesDir, "screenkeys"), name)
|
||||
val size = BitmapFactory.Options().apply { inJustDecodeBounds = true }
|
||||
@@ -221,7 +222,7 @@ class InputSurfaceView(
|
||||
canvas.drawBitmap(it, null, imageRect, labelPaint)
|
||||
return
|
||||
}
|
||||
if (element.icon != 0 && InputButtonIcons.draw(canvas, element.icon, cx, height / 2f, min(width, height) * .68f, labelPaint)) 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.textSize = min(height * .3f, 30 * density)
|
||||
val labelWidth = labelPaint.measureText(element.name)
|
||||
|
||||
@@ -209,6 +209,7 @@ private class DrawerFocus {
|
||||
|
||||
class DrawerActions(
|
||||
val steam: Boolean,
|
||||
val desktop: Boolean,
|
||||
val direct: Boolean = false,
|
||||
val title: String? = null,
|
||||
val isHomeApp: Boolean,
|
||||
@@ -589,7 +590,7 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
|
||||
}
|
||||
SessionDrawerPage.CONTROLLER -> {
|
||||
SettingsGroup(stringResource(R.string.drawer_page_controller)) {
|
||||
InputQuickSettings(host, desktop = !a.steam && !a.direct, onChanged = a.onInputSelection, onEdit = a.onInputSettings) { key -> focus.track(page, key) }
|
||||
InputQuickSettings(host, desktop = a.desktop, onChanged = a.onInputSelection, onEdit = a.onInputSettings) { key -> focus.track(page, key) }
|
||||
}
|
||||
SettingsGroup(stringResource(R.string.input_device_settings)) {
|
||||
a.padType?.let { type ->
|
||||
|
||||
Reference in new issue
Block a user