From d5c83eae155e74578665c22b3f5085ebb5e80be5 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Fri, 20 Nov 2026 11:54:59 -0500 Subject: [PATCH] feat(input): describe on-screen layout choices, scope per-game layouts and delete unused ones (#2939) * feat(input): describe on-screen layout choices, scope per-game layouts and delete unused ones - The layout menu says what each choice is: "DroidDeck controls" work in every game and are edited here; "Steam touch controls" are each game's controls from Steam, for Steam games only. - Layouts made with "+ New for " (or "Just this game") are listed only for that game, marked "Just for ". Older ones are recognised by carrying the name of the game that draws them. - Saved layouts nothing uses get a delete button in the menu. Deleting one also removes a profile that still uses it but can no longer be chosen, such as copies made by the old profile screen. - A game set to Steam touch controls that runs without Steam shows a note under Layout instead of silently using the default. * fix(input): a layout the built-in profile still lists can be deleted once another is chosen Applying a layout used to write it into the Game profile; choosing another now goes on top, so the profile's part is no longer drawn. Only parts a mode actually draws count as in use, and deleting points the built-in profile back at the stock layout. --- .../com/droiddeck/launcher/SessionActivity.kt | 16 +++- .../launcher/input/ControlsChoice.kt | 88 +++++++++++++++-- .../droiddeck/launcher/input/GameControls.kt | 10 ++ .../launcher/ui/InputSettingsPage.kt | 4 +- .../droiddeck/launcher/ui/LayoutChoiceRow.kt | 87 +++++++++++++++++ .../droiddeck/launcher/ui/SessionOverlay.kt | 8 +- app/src/main/res/values/strings.xml | 9 +- .../launcher/input/ControlsChoiceTest.kt | 94 +++++++++++++++++-- .../launcher/ui/InputSettingsTest.kt | 14 +++ 9 files changed, 304 insertions(+), 26 deletions(-) create mode 100644 app/src/main/java/com/droiddeck/launcher/ui/LayoutChoiceRow.kt diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index b5020ed92..19dedc52b 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -646,8 +646,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde private var oscRearButtons by mutableStateOf(false) private var oscTrackpads by mutableStateOf(false) private var onScreenButtonsVisible by mutableStateOf(false) - private var layoutOptions by mutableStateOf>>(emptyList()) + private var layoutOptions by mutableStateOf>(emptyList()) private var layoutChoice by mutableStateOf("") + private var layoutHint by mutableStateOf(null) private var layoutEditor by mutableStateOf?>(null) private var layoutEditorScope: String? = null private var layoutEditorSplit: com.droiddeck.launcher.ui.InputEditorSplit? = null @@ -1746,7 +1747,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde layoutGame = controlsGameName(), layoutOptions = layoutOptions, layoutChoice = layoutChoice, + layoutHint = layoutHint, onLayout = ::chooseLayout, + onDeleteLayout = ::deleteLayout, oscRearButtons = oscRearButtons.takeIf { unfoldedPanel == null && !usesSteamTouchLayout() && com.droiddeck.launcher.input.PadKit.current(this).steam && primaryInputLayout?.let(com.droiddeck.launcher.input.OnScreenLayout::hasBuiltInKit) == true @@ -4432,8 +4435,15 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde private fun refreshLayoutOptions() { val steam = SessionState.mode == SessionService.MODE_STEAM val game = controlsGameId() - layoutOptions = com.droiddeck.launcher.input.ControlsChoice.options(this, game, steam, controlsGameName()) - layoutChoice = com.droiddeck.launcher.input.ControlsChoice.current(this, game, steam, loadingMode() == SessionService.MODE_DESKTOP) + val desktop = loadingMode() == SessionService.MODE_DESKTOP + layoutOptions = com.droiddeck.launcher.input.ControlsChoice.options(this, game, steam, controlsGameName(), desktop) + layoutChoice = com.droiddeck.launcher.input.ControlsChoice.current(this, game, steam, desktop) + layoutHint = if (com.droiddeck.launcher.input.ControlsChoice.steamUnavailable(this, game, steam)) getString(R.string.osc_layout_steam_unavailable) else null + } + + private fun deleteLayout(id: String) { + runCatching { com.droiddeck.launcher.input.ControlsChoice.delete(this, id) }.onFailure { Log.w(TAG, "could not delete layout $id", it) } + refreshLayoutOptions() } private fun chooseLayout(id: String) { diff --git a/app/src/main/java/com/droiddeck/launcher/input/ControlsChoice.kt b/app/src/main/java/com/droiddeck/launcher/input/ControlsChoice.kt index 2e4952b97..1fe9bd1f3 100644 --- a/app/src/main/java/com/droiddeck/launcher/input/ControlsChoice.kt +++ b/app/src/main/java/com/droiddeck/launcher/input/ControlsChoice.kt @@ -24,14 +24,84 @@ object ControlsChoice { return if (chosen == null) library else library.selectPart(desktop, InputRole.PRIMARY, chosen) } - fun options(context: Context, game: Long?, steamMode: Boolean, gameName: String? = null): List> { + data class Option(val id: String, val name: String, val detail: String? = null, val deletable: Boolean = false) + + /** Layouts made for one game, so they're listed only for that game. Layouts made before that was recorded are recognised by carrying the name of the game that draws them. */ + private fun owners(context: Context, library: InputLibrary): Map> { + val named = GameControls.games(context).mapNotNull { game -> + val layout = own(library, GameControls.bindings(context, game))?.let { library.preset(it).layoutId } ?: return@mapNotNull null + val name = GameControls.name(context, game) ?: return@mapNotNull null + (layout to game).takeIf { library.layouts.any { it.id == layout && it.name == name } } + } + return (named + GameControls.madeFor(context).toList()).groupBy({ it.first }, { it.second }).mapValues { it.value.toSet() } + } + + private fun defaults(library: InputLibrary) = + listOf(false, true).mapNotNull { library.activeLayout(it, InputRole.PRIMARY)?.id }.toSet() + + private fun deletable(context: Context, library: InputLibrary, layout: SavedInputLayout): Boolean { + if (!layout.editable || layout.id == InputLibraries.OVERLAY || layout.id in defaults(library)) return false + if (GameControls.games(context).any { game -> own(library, GameControls.bindings(context, game))?.let { library.preset(it).layoutId } == layout.id }) return false + return library.profiles.none { p -> p.parts.any { (role, part) -> part.layout == layout.id && drawn(library, p.id, role) } } && + library.bindings.none { it.layoutId == layout.id && library.selectedBindings(it.id) } + } + + /** Whether [profile]'s [role] part is what a mode shows, rather than one a choice made since covers. */ + private fun drawn(library: InputLibrary, profile: String, role: InputRole) = + listOf(false, true).any { desktop -> library.activeId(desktop) == profile && library.selection(desktop).parts[role] == null } + + private fun keeps(library: InputLibrary, profile: String) = + profile == InputProfile.GAME || profile == InputProfile.DESKTOP || listOf(false, true).any { library.activeId(it) == profile } + + fun options(context: Context, game: Long?, steamMode: Boolean, gameName: String? = null, desktop: Boolean = false): List