mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 23:36:04 +00:00
revert(input): restore pre-overhaul controls (#2958)
This commit is contained in:
1 parent
33761c30ab
commit
9925873764
170 files changed
+3980
-4927
No files matched your search
@@ -1,232 +0,0 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.content.Context
|
||||
import androidx.compose.runtime.MutableState
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.SessionActivity
|
||||
import com.droiddeck.launcher.session.SessionService
|
||||
import com.droiddeck.launcher.session.SessionState
|
||||
import org.junit.After
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.Robolectric
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.util.ReflectionHelpers
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [34], shadows = [JoyConPadTest.RecordingWriter::class])
|
||||
class ControlsChoiceTest {
|
||||
private val context: Context get() = RuntimeEnvironment.getApplication()
|
||||
|
||||
@Before fun reset() {
|
||||
for (name in listOf("session", "game-controls", "input-profiles", "input-surfaces", "controller")) context.getSharedPreferences(name, Context.MODE_PRIVATE).edit().clear().commit()
|
||||
}
|
||||
|
||||
@After fun mode() { SessionState.mode = SessionService.MODE_STEAM }
|
||||
|
||||
private fun bigSticks(): String {
|
||||
val id = "big-sticks"
|
||||
InputLibraries.update(context) { library ->
|
||||
val stick = InputSurfaceElement(InputControl.A, .4f, .4f, .1f, .1f, "jump", InputElementKind.BUTTON, "Jump")
|
||||
library.withLayout(SavedInputLayout(id, "Big sticks", listOf(stick), screen = InputLayoutScreen.MAIN))
|
||||
.withPreset(SavedInputBindings("big-sticks.actions", "Big sticks", false, id, elements = mapOf("jump" to InputAction.Keys(listOf(57)))))
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
@Test fun aNewLayoutForOneGameCopiesTheLayoutAndItsActionsForThatGameOnly() {
|
||||
val source = bigSticks()
|
||||
ControlsChoice.choose(context, null, source, desktop = false)
|
||||
val (layoutId, bindingsId) = ControlsChoice.newForGame(context, 7, "Castle Crashers", desktop = false)
|
||||
val library = InputLibraries.read(context)
|
||||
val copy = library.layouts.first { it.id == layoutId }
|
||||
assertEquals("Castle Crashers", copy.name)
|
||||
assertEquals(library.layouts.first { it.id == source }.elements, copy.elements)
|
||||
assertEquals(InputAction.Keys(listOf(57)), library.preset(bindingsId).elements["jump"])
|
||||
assertEquals(layoutId, library.preset(bindingsId).layoutId)
|
||||
assertEquals(bindingsId, GameControls.bindings(context, 7))
|
||||
assertEquals(layoutId, ControlsChoice.current(context, 7, steamMode = true))
|
||||
assertEquals(source, ControlsChoice.current(context, 8, steamMode = true))
|
||||
assertEquals(source, ControlsChoice.current(context, null, steamMode = true))
|
||||
assertEquals(Triple(InputProfile.GAME, layoutId, bindingsId), ControlsChoice.editTarget(context, 7, desktop = false))
|
||||
}
|
||||
|
||||
@Test fun aCopyOfTheBuiltInGamepadKeepsFollowingTheKit() {
|
||||
val extra = InputSurfaceElement(InputControl.A, .45f, .1f, .08f, .1f, "extra", InputElementKind.BUTTON, "Extra")
|
||||
InputLibraries.update(context) { it.withLayout(it.layouts.first { l -> l.id == InputLibraries.OVERLAY }.copy(elements = listOf(extra), aspect = 2f)) }
|
||||
val (layoutId, _) = ControlsChoice.newForGame(context, 7, "Castle Crashers", desktop = false)
|
||||
val copy = InputLibraries.read(context).layouts.first { it.id == layoutId }
|
||||
assertEquals(InputLibraries.OVERLAY, copy.origin)
|
||||
assertTrue(OnScreenLayout.generated(copy))
|
||||
assertEquals(listOf(extra), copy.elements)
|
||||
assertEquals(InputLibraries.OVERLAY, ControlsChoice.current(context, null, steamMode = false))
|
||||
}
|
||||
|
||||
@Test fun onlyAGameWithItsOwnUnsharedLayoutEditsWithoutChangingOthers() {
|
||||
assertFalse(ControlsChoice.shared(context, null))
|
||||
assertTrue(ControlsChoice.shared(context, 7))
|
||||
ControlsChoice.choose(context, 7, InputLibraries.OVERLAY, desktop = false)
|
||||
assertTrue(ControlsChoice.shared(context, 7))
|
||||
ControlsChoice.newForGame(context, 7, "Castle Crashers", desktop = false)
|
||||
assertFalse(ControlsChoice.shared(context, 7))
|
||||
ControlsChoice.choose(context, 8, ControlsChoice.current(context, 7, steamMode = false), desktop = false)
|
||||
assertTrue(ControlsChoice.shared(context, 7))
|
||||
}
|
||||
|
||||
@Test fun useDefaultForgetsTheGamesChoice() {
|
||||
ControlsChoice.newForGame(context, 7, "Castle Crashers", desktop = false)
|
||||
ControlsChoice.choose(context, 9, GameControls.STEAM, desktop = false, gameName = "Portal")
|
||||
assertEquals(listOf("Castle Crashers" to "Castle Crashers", "Portal" to context.getString(R.string.osc_layout_steam)),
|
||||
ControlsChoice.games(context).map { it.name to it.layout })
|
||||
ControlsChoice.useDefault(context, 7)
|
||||
assertNull(GameControls.bindings(context, 7))
|
||||
assertEquals(InputLibraries.OVERLAY, ControlsChoice.current(context, 7, steamMode = true))
|
||||
assertEquals(listOf(9L), ControlsChoice.games(context).map { it.id })
|
||||
}
|
||||
|
||||
@Test fun newIsOfferedOnlyForAGame() {
|
||||
assertTrue(ControlsChoice.options(context, null, steamMode = true).none { it.id == ControlsChoice.NEW })
|
||||
val last = ControlsChoice.options(context, 7, steamMode = true, gameName = "Castle Crashers").last()
|
||||
assertEquals(ControlsChoice.NEW to context.getString(R.string.osc_layout_new_for, "Castle Crashers"), last.id to last.name)
|
||||
assertEquals(listOf(InputLibraries.OVERLAY, GameControls.STEAM), ControlsChoice.options(context, null, steamMode = true).map { it.id })
|
||||
}
|
||||
|
||||
@Test fun newForTheGameInTheControllerPageCopiesTheLayoutAndOpensTheEditorOnIt() {
|
||||
SessionState.mode = SessionService.MODE_STEAM
|
||||
val activity = Robolectric.buildActivity(SessionActivity::class.java).get()
|
||||
ReflectionHelpers.getField<MutableState<Long?>>(activity, "frameGenActiveGameId\$delegate").value = 77L
|
||||
ReflectionHelpers.getField<MutableState<String?>>(activity, "frameGenActiveGameName\$delegate").value = "Castle Crashers"
|
||||
ReflectionHelpers.callInstanceMethod<Any?>(activity, "refreshInputProfile")
|
||||
val options = ReflectionHelpers.getField<MutableState<List<ControlsChoice.Option>>>(activity, "layoutOptions\$delegate").value
|
||||
assertEquals(ControlsChoice.NEW to "+ New for Castle Crashers", options.last().let { it.id to it.name })
|
||||
ReflectionHelpers.callInstanceMethod<Any?>(activity, "chooseLayout", ReflectionHelpers.ClassParameter.from(String::class.java, ControlsChoice.NEW))
|
||||
val editor = ReflectionHelpers.getField<MutableState<Triple<String, String, String>?>>(activity, "layoutEditor\$delegate").value!!
|
||||
assertEquals(GameControls.bindings(activity, 77), editor.third)
|
||||
assertEquals("Castle Crashers", InputLibraries.read(activity).layouts.first { it.id == editor.second }.name)
|
||||
assertEquals(editor.second, ReflectionHelpers.getField<MutableState<String>>(activity, "layoutChoice\$delegate").value)
|
||||
assertEquals("Saved for Castle Crashers", ReflectionHelpers.getField<String>(activity, "layoutEditorScope"))
|
||||
assertNull(ReflectionHelpers.getField<Any?>(activity, "layoutEditorSplit"))
|
||||
assertNull(GameControls.bindings(activity, 78))
|
||||
assertEquals(InputLibraries.OVERLAY, ControlsChoice.current(activity, null, steamMode = true))
|
||||
}
|
||||
|
||||
@Test fun aGameWithItsOwnLayoutCanGoBackToTheDefault() {
|
||||
assertTrue(ControlsChoice.options(context, 42L, steamMode = true, gameName = "Game").none { it.id == ControlsChoice.DEFAULT })
|
||||
ControlsChoice.newForGame(context, 42L, "Game", desktop = false)
|
||||
assertTrue(ControlsChoice.options(context, 42L, steamMode = true, gameName = "Game").first().id == ControlsChoice.DEFAULT)
|
||||
ControlsChoice.choose(context, 42L, ControlsChoice.DEFAULT, desktop = false)
|
||||
assertFalse(ControlsChoice.hasOwn(context, 42L))
|
||||
assertTrue(ControlsChoice.options(context, 42L, steamMode = true, gameName = "Game").none { it.id == ControlsChoice.DEFAULT })
|
||||
}
|
||||
|
||||
@Test fun aLayoutMadeForOneGameIsListedOnlyForThatGame() {
|
||||
val (layoutId, _) = ControlsChoice.newForGame(context, 7, "Castle Crashers", desktop = false)
|
||||
val mine = ControlsChoice.options(context, 7, steamMode = true, gameName = "Castle Crashers").first { it.id == layoutId }
|
||||
assertEquals(context.getString(R.string.osc_layout_detail_game, "Castle Crashers"), mine.detail)
|
||||
assertFalse(mine.deletable)
|
||||
assertTrue(ControlsChoice.options(context, 8, steamMode = true, gameName = "Portal").none { it.id == layoutId })
|
||||
assertTrue(ControlsChoice.options(context, null, steamMode = true).none { it.id == layoutId })
|
||||
ControlsChoice.useDefault(context, 7)
|
||||
assertTrue(ControlsChoice.options(context, 8, steamMode = true, gameName = "Portal").none { it.id == layoutId })
|
||||
assertTrue(ControlsChoice.options(context, 7, steamMode = true, gameName = "Castle Crashers").first { it.id == layoutId }.deletable)
|
||||
}
|
||||
|
||||
@Test fun anUnusedLayoutCanBeDeletedButNotOneInUse() {
|
||||
val source = bigSticks()
|
||||
assertTrue(ControlsChoice.options(context, null, steamMode = true).first { it.id == source }.deletable)
|
||||
ControlsChoice.choose(context, null, source, desktop = false)
|
||||
assertFalse(ControlsChoice.options(context, null, steamMode = true).first { it.id == source }.deletable)
|
||||
ControlsChoice.choose(context, null, InputLibraries.OVERLAY, desktop = false)
|
||||
ControlsChoice.choose(context, 7, source, desktop = false, gameName = "Castle Crashers")
|
||||
assertFalse(ControlsChoice.options(context, null, steamMode = true).first { it.id == source }.deletable)
|
||||
assertNull(ControlsChoice.options(context, 8, steamMode = true, gameName = "Portal").first { it.id == source }.detail)
|
||||
ControlsChoice.useDefault(context, 7)
|
||||
ControlsChoice.delete(context, source)
|
||||
val library = InputLibraries.read(context)
|
||||
assertTrue(library.layouts.none { it.id == source })
|
||||
assertTrue(library.bindings.none { it.layoutId == source })
|
||||
assertTrue(ControlsChoice.options(context, null, steamMode = true).none { it.id == source })
|
||||
}
|
||||
|
||||
@Test fun deletingALayoutAlsoRemovesAProfileThatCanNoLongerBeChosen() {
|
||||
InputLibraries.update(context) { it.duplicateProfile(InputProfile.GAME, "Game2") }
|
||||
val profile = InputLibraries.read(context).profiles.first { it.name == "Game2" }
|
||||
val layout = InputLibraries.read(context).layout(profile.id, InputRole.PRIMARY)!!
|
||||
assertEquals("Game2 / primary", layout.name)
|
||||
assertTrue(ControlsChoice.options(context, null, steamMode = true).first { it.id == layout.id }.deletable)
|
||||
ControlsChoice.delete(context, layout.id)
|
||||
val library = InputLibraries.read(context)
|
||||
assertTrue(library.profiles.none { it.id == profile.id })
|
||||
assertTrue(library.layouts.none { it.id == layout.id })
|
||||
assertTrue(profile.parts.values.none { part -> library.bindings.any { it.id == part.bindings } })
|
||||
assertEquals(InputLibraries.OVERLAY, ControlsChoice.current(context, null, steamMode = true))
|
||||
}
|
||||
|
||||
@Test fun steamTouchSavedForAGameFallsBackOutsideSteamWithANote() {
|
||||
ControlsChoice.choose(context, 7, GameControls.STEAM, desktop = false, gameName = "Portal")
|
||||
assertEquals(GameControls.STEAM, ControlsChoice.current(context, 7, steamMode = true))
|
||||
assertFalse(ControlsChoice.steamUnavailable(context, 7, steamMode = true))
|
||||
assertEquals(InputLibraries.OVERLAY, ControlsChoice.current(context, 7, steamMode = false))
|
||||
assertTrue(ControlsChoice.steamUnavailable(context, 7, steamMode = false))
|
||||
assertFalse(ControlsChoice.steamUnavailable(context, 8, steamMode = false))
|
||||
assertTrue(ControlsChoice.options(context, 7, steamMode = false, gameName = "Portal").none { it.id == GameControls.STEAM })
|
||||
}
|
||||
|
||||
@Test fun aLayoutNamedAfterTheGameThatDrawsItCountsAsThatGamesOwn() {
|
||||
val source = bigSticks()
|
||||
InputLibraries.update(context) { it.withLayout(it.layouts.first { l -> l.id == source }.copy(name = "ARMSX1")) }
|
||||
ControlsChoice.choose(context, 7, source, desktop = false, gameName = "ARMSX1")
|
||||
assertTrue(ControlsChoice.options(context, 8, steamMode = true, gameName = "Portal").none { it.id == source })
|
||||
assertEquals(context.getString(R.string.osc_layout_detail_game, "ARMSX1"),
|
||||
ControlsChoice.options(context, 7, steamMode = true, gameName = "ARMSX1").first { it.id == source }.detail)
|
||||
}
|
||||
|
||||
@Test fun aLayoutTheGameProfileStillListsCanBeDeletedOnceAnotherIsChosen() {
|
||||
val source = bigSticks()
|
||||
InputLibraries.update(context) { it.chooseLayout(InputProfile.GAME, InputRole.PRIMARY, source) }
|
||||
assertEquals(source, ControlsChoice.current(context, null, steamMode = true))
|
||||
assertFalse(ControlsChoice.options(context, null, steamMode = true).first { it.id == source }.deletable)
|
||||
ControlsChoice.choose(context, null, InputLibraries.OVERLAY, desktop = false)
|
||||
assertTrue(ControlsChoice.options(context, null, steamMode = true).first { it.id == source }.deletable)
|
||||
ControlsChoice.delete(context, source)
|
||||
val library = InputLibraries.read(context)
|
||||
assertTrue(library.layouts.none { it.id == source })
|
||||
assertEquals(InputLibraries.OVERLAY, library.profile(InputProfile.GAME).parts.getValue(InputRole.PRIMARY).layout)
|
||||
assertEquals(InputLibraries.OVERLAY, ControlsChoice.current(context, null, steamMode = true))
|
||||
}
|
||||
|
||||
private fun desktopMouseFirst(): String {
|
||||
val mouse = SavedInputBindings("desktop.mouse", "Desktop / primary", false, InputLibraries.OVERLAY,
|
||||
controls = mapOf(InputControl.A to InputAction.MouseButton(272), InputControl.LS to InputAction.Pointer()))
|
||||
InputLibraries.update(context) { it.copy(bindings = listOf(mouse) + it.bindings).chooseBindings(InputProfile.DESKTOP, InputRole.PRIMARY, mouse.id) }
|
||||
return mouse.id
|
||||
}
|
||||
|
||||
@Test fun choosingTheGamepadKeepsEachModesOwnActions() {
|
||||
val mouse = desktopMouseFirst()
|
||||
val game = InputLibraries.read(context).profile(InputProfile.GAME).parts.getValue(InputRole.PRIMARY).bindings
|
||||
ControlsChoice.choose(context, null, InputLibraries.OVERLAY, desktop = false)
|
||||
ControlsChoice.choose(context, null, InputLibraries.OVERLAY, desktop = true)
|
||||
val library = InputLibraries.read(context)
|
||||
assertNotEquals(mouse, library.activePart(false, InputRole.PRIMARY).bindings)
|
||||
assertEquals(game, library.activePart(false, InputRole.PRIMARY).bindings)
|
||||
assertEquals(mouse, library.activePart(true, InputRole.PRIMARY).bindings)
|
||||
ControlsChoice.choose(context, 7, InputLibraries.OVERLAY, desktop = false)
|
||||
assertNotEquals(mouse, GameControls.bindings(context, 7))
|
||||
}
|
||||
|
||||
@Test fun aGameSelectionHoldingDesktopActionsIsDroppedOnUpgrade() {
|
||||
val mouse = desktopMouseFirst()
|
||||
val broken = InputLibraries.read(context).selectPart(false, InputRole.PRIMARY, mouse)
|
||||
val raw = org.json.JSONObject(InputLibraries.encode(broken)).put("version", 15).toString()
|
||||
context.getSharedPreferences("input-profiles", Context.MODE_PRIVATE).edit().putString("library", raw).commit()
|
||||
val library = InputLibraries.read(context)
|
||||
assertNull(library.selection(false).parts[InputRole.PRIMARY])
|
||||
assertEquals(mouse, library.activePart(true, InputRole.PRIMARY).bindings)
|
||||
assertEquals(InputLibraries.OVERLAY, ControlsChoice.current(context, null, steamMode = true))
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import com.droiddeck.launcher.input.ControlsPresenter.Place
|
||||
import com.droiddeck.launcher.input.ControlsPresenter.State
|
||||
import com.droiddeck.launcher.input.OnScreenControls.Hidden
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
|
||||
class ControlsPresenterTest {
|
||||
private val modes = listOf(SessionPrefs.OSC_AUTO, SessionPrefs.OSC_ALWAYS, SessionPrefs.OSC_NEVER)
|
||||
|
||||
private fun states() = sequence {
|
||||
for (mode in modes) for (bits in 0 until 128) {
|
||||
fun bit(i: Int) = bits and (1 shl i) != 0
|
||||
yield(State(mode, desktop = bit(0), virtualPad = bit(1), covered = bit(2), controllerInUse = bit(3), hiddenByTap = bit(4),
|
||||
steamLayout = bit(5), bottomScreen = bit(6)))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun everyStateGetsThePlanTheRulesDescribe() {
|
||||
for (state in states()) {
|
||||
val plan = ControlsPresenter.plan(state)
|
||||
val off = state.covered || !state.virtualPad || state.mode == SessionPrefs.OSC_NEVER || state.mode == SessionPrefs.OSC_AUTO && state.desktop
|
||||
if (off) {
|
||||
assertEquals(state.toString(), ControlsPresenter.Plan(Place.NONE), plan)
|
||||
assertFalse(plan.shown)
|
||||
continue
|
||||
}
|
||||
val place = if (state.bottomScreen) Place.BOTTOM else if (state.steamLayout) Place.STEAM else Place.MAIN
|
||||
val hidden = if (state.hiddenByTap) Hidden.BY_TAP else if (state.mode == SessionPrefs.OSC_AUTO && state.controllerInUse) Hidden.BY_CONTROLLER else null
|
||||
assertEquals(state.toString(), ControlsPresenter.Plan(place, hidden), plan)
|
||||
assertEquals(state.toString(), hidden == null, plan.shown)
|
||||
}
|
||||
}
|
||||
|
||||
private val playing = State(SessionPrefs.OSC_AUTO, desktop = false, virtualPad = true, covered = false, controllerInUse = false,
|
||||
hiddenByTap = false, steamLayout = false, bottomScreen = false)
|
||||
|
||||
@Test fun autoHidesForAControllerButAlwaysKeepsTheControls() {
|
||||
assertEquals(ControlsPresenter.Plan(Place.MAIN), ControlsPresenter.plan(playing))
|
||||
assertEquals(Hidden.BY_CONTROLLER, ControlsPresenter.plan(playing.copy(controllerInUse = true)).hidden)
|
||||
assertNull(ControlsPresenter.plan(playing.copy(mode = SessionPrefs.OSC_ALWAYS, controllerInUse = true)).hidden)
|
||||
}
|
||||
|
||||
@Test fun aTapHideWinsOverAControllerHide() {
|
||||
assertEquals(Hidden.BY_TAP, ControlsPresenter.plan(playing.copy(controllerInUse = true, hiddenByTap = true)).hidden)
|
||||
assertEquals(Hidden.BY_TAP, ControlsPresenter.plan(playing.copy(mode = SessionPrefs.OSC_ALWAYS, hiddenByTap = true)).hidden)
|
||||
}
|
||||
|
||||
@Test fun theSteamLayoutWinsOverTheBottomScreen() {
|
||||
assertEquals(Place.BOTTOM, ControlsPresenter.plan(playing.copy(steamLayout = true, bottomScreen = true)).place)
|
||||
assertEquals(Place.BOTTOM, ControlsPresenter.plan(playing.copy(bottomScreen = true)).place)
|
||||
}
|
||||
|
||||
@Test fun theDesktopShowsControlsOnlyWhenAlwaysIsChosen() {
|
||||
assertEquals(Place.NONE, ControlsPresenter.plan(playing.copy(desktop = true)).place)
|
||||
assertEquals(Place.MAIN, ControlsPresenter.plan(playing.copy(desktop = true, mode = SessionPrefs.OSC_ALWAYS)).place)
|
||||
}
|
||||
|
||||
@Test fun steamShortcutsOverrideTheSteamLayoutAndFollowTheGameDisplay() {
|
||||
val state = playing.copy(mode = SessionPrefs.OSC_STEAM_QAM, steamLayout = true, controllerInUse = true)
|
||||
assertEquals(ControlsPresenter.Plan(Place.MAIN, shortcutsOnly = true), ControlsPresenter.plan(state))
|
||||
assertEquals(ControlsPresenter.Plan(Place.BOTTOM, shortcutsOnly = true), ControlsPresenter.plan(state.copy(bottomScreen = true)))
|
||||
assertEquals(ControlsPresenter.Plan(Place.MAIN, Hidden.BY_TAP, shortcutsOnly = true),
|
||||
ControlsPresenter.plan(state.copy(hiddenByTap = true)))
|
||||
assertEquals(ControlsPresenter.Plan(Place.NONE), ControlsPresenter.plan(state.copy(covered = true)))
|
||||
}
|
||||
|
||||
@Test fun aCoveringPanelOrNoVirtualPadRemovesTheControls() {
|
||||
assertEquals(Place.NONE, ControlsPresenter.plan(playing.copy(covered = true)).place)
|
||||
assertEquals(Place.NONE, ControlsPresenter.plan(playing.copy(virtualPad = false, mode = SessionPrefs.OSC_ALWAYS)).place)
|
||||
assertEquals(Place.NONE, ControlsPresenter.plan(playing.copy(mode = SessionPrefs.OSC_NEVER, steamLayout = true)).place)
|
||||
}
|
||||
}
|
||||
@@ -58,19 +58,25 @@ class InputLayoutToolsTest {
|
||||
@Test fun builtInGamepadDefaultsComeFromTheGamepadGenerator() {
|
||||
val library = InputLibraries.read(context)
|
||||
val gamepad = library.layouts.first { it.id == InputLibraries.OVERLAY }
|
||||
val (defaults, aspect) = InputLibraries.defaultPositions(context, library, gamepad)!!
|
||||
assertTrue(gamepad.elements.isEmpty())
|
||||
val (display, metrics) = InputLibraries.primaryDisplay(context)
|
||||
val w = metrics.widthPixels; val h = metrics.heightPixels
|
||||
assertEquals(KitLayout.elements(display, PadKit.current(context), w, h), defaults)
|
||||
assertEquals(w.toFloat() / h, aspect, .0001f)
|
||||
val copy = SavedInputLayout("mine", "Mine", origin = InputLibraries.OVERLAY)
|
||||
assertEquals(defaults, InputLibraries.defaultPositions(context, library, copy)!!.first)
|
||||
assertEquals(KitLayout.elements(display, PadKit.current(context), w, h, scale = 1.2f),
|
||||
InputLibraries.defaultPositions(context, library, gamepad.copy(scale = 1.2f))!!.first)
|
||||
val defaults = InputLibraries.defaultPositions(context, library, gamepad)!!.first
|
||||
assertEquals(gamepad.elements.map { it.id }.toSet(), defaults.map { it.id }.toSet())
|
||||
assertNull(InputLibraries.defaultPositions(context, library, SavedInputLayout("new", "New")))
|
||||
}
|
||||
|
||||
@Test fun quickButtonsHideWithoutRemovingElementsAndPersist() {
|
||||
val library = InputLibraries.read(context)
|
||||
val gamepad = library.layouts.first { it.id == InputLibraries.OVERLAY }
|
||||
assertTrue(InputCommand.KEYBOARD in gamepad.quickButtons)
|
||||
assertTrue(InputLibraries.setQuickButton(context, gamepad.id, InputCommand.KEYBOARD, false))
|
||||
val hidden = InputLibraries.read(context).layouts.first { it.id == gamepad.id }
|
||||
assertEquals(gamepad.elements, hidden.elements)
|
||||
assertEquals(setOf(InputCommand.KEYBOARD), hidden.style.hidden)
|
||||
val shown = hidden.style.shown(hidden.elements)
|
||||
assertEquals(gamepad.elements.filterNot { it.id == "builtin:keyboard" }, shown)
|
||||
assertTrue(InputLibraries.setQuickButton(context, gamepad.id, InputCommand.KEYBOARD, true))
|
||||
assertEquals(gamepad, InputLibraries.read(context).layouts.first { it.id == gamepad.id })
|
||||
}
|
||||
|
||||
@Test fun onlySteamQuickAccessAndKeyboardCanBeHidden() {
|
||||
val library = InputLibraries.read(context)
|
||||
val gamepad = library.layouts.first { it.id == InputLibraries.OVERLAY }
|
||||
@@ -81,6 +87,35 @@ class InputLayoutToolsTest {
|
||||
assertFalse(InputSurfaceStyle(hidden = QUICK_BUTTONS.toSet()).hides(custom))
|
||||
}
|
||||
|
||||
private fun overlapping(elements: List<InputSurfaceElement>, width: Int, height: Int): List<Pair<String, String>> {
|
||||
fun round(e: InputSurfaceElement) = e.buttonShape == InputButtonShape.CIRCLE && e.kind != InputElementKind.STICK
|
||||
val result = mutableListOf<Pair<String, String>>()
|
||||
for ((i, a) in elements.withIndex()) for (b in elements.drop(i + 1)) {
|
||||
val ax = (a.x + a.width / 2) * width; val ay = (a.y + a.height / 2) * height
|
||||
val bx = (b.x + b.width / 2) * width; val by = (b.y + b.height / 2) * height
|
||||
val hit = if (round(a) && round(b)) {
|
||||
val ra = minOf(a.width * width, a.height * height) / 2; val rb = minOf(b.width * width, b.height * height) / 2
|
||||
kotlin.math.hypot(ax - bx, ay - by) < ra + rb - .5f
|
||||
} else kotlin.math.abs(ax - bx) < (a.width + b.width) * width / 2 - .5f && kotlin.math.abs(ay - by) < (a.height + b.height) * height / 2 - .5f
|
||||
if (hit) result += a.id to b.id
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@Test fun generatedGamepadSpacingFollowsButtonSize() {
|
||||
for ((w, h) in listOf(1920 to 1080, 1280 to 960)) {
|
||||
val normal = LegacyGamepadLayout(context, w, h).elements()
|
||||
for (scale in listOf(.8f, 1.25f)) {
|
||||
val elements = LegacyGamepadLayout(context, w, h, scale = scale).elements()
|
||||
assertEquals("$w x $h at $scale", emptyList<Pair<String, String>>(), overlapping(elements, w, h))
|
||||
val face = listOf("legacy:a", "legacy:y").map { id -> elements.first { it.id == id } }
|
||||
val faceNormal = listOf("legacy:a", "legacy:y").map { id -> normal.first { it.id == id } }
|
||||
val gap = (face[0].y - face[1].y) / (faceNormal[0].y - faceNormal[1].y)
|
||||
if (scale > 1f) assertTrue(gap > 1f) else assertTrue(gap < 1f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun scalingACustomLayoutScalesTheGapsBetweenNeighbours() {
|
||||
val left = listOf(InputSurfaceElement(InputControl.A, .05f, .5f, .08f, .1f, "one", name = "One"),
|
||||
InputSurfaceElement(InputControl.A, .16f, .5f, .08f, .1f, "two", name = "Two"))
|
||||
@@ -96,4 +131,87 @@ class InputLayoutToolsTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun aScaledGamepadStaysGeneratedAndRegeneratesOnRotation() {
|
||||
val (display, metrics) = InputLibraries.primaryDisplay(context)
|
||||
val long = maxOf(metrics.widthPixels, metrics.heightPixels)
|
||||
val short = minOf(metrics.widthPixels, metrics.heightPixels)
|
||||
val gamepad = InputLibraries.read(context).layouts.first { it.id == InputLibraries.OVERLAY }
|
||||
val scaled = gamepad.copy(scale = 1.25f, elements = LegacyGamepadLayout(display, long, short, scale = 1.25f).regenerate(gamepad.elements))
|
||||
assertEquals(long to short, OnScreenLayout.generatedSize(context, scaled, long, short))
|
||||
val rotated = OnScreenLayout.elements(context, scaled, short, long, android.graphics.Rect())
|
||||
assertEquals(LegacyGamepadLayout(context, short, long, scale = 1.25f).regenerate(scaled.elements), rotated)
|
||||
assertNull(OnScreenLayout.generatedSize(context, scaled.copy(scale = 1f), long, short))
|
||||
InputLibraries.update(context) { it.withLayout(scaled) }
|
||||
assertEquals(1.25f, InputLibraries.read(context).layouts.first { it.id == gamepad.id }.scale)
|
||||
}
|
||||
|
||||
private fun assertCross(elements: List<InputSurfaceElement>, width: Int, height: Int, ids: List<String>) {
|
||||
val (up, right, down, left) = ids.map { id -> elements.first { it.id == id }.let { (it.x + it.width / 2) * width to (it.y + it.height / 2) * height } }
|
||||
val cx = (up.first + right.first + down.first + left.first) / 4
|
||||
val cy = (up.second + right.second + down.second + left.second) / 4
|
||||
assertEquals(up.first, down.first, 1f)
|
||||
assertEquals(left.second, right.second, 1f)
|
||||
assertTrue(up.second < down.second && left.first < right.first)
|
||||
val reach = listOf(up, right, down, left).map { kotlin.math.hypot(it.first - cx, it.second - cy) }
|
||||
reach.forEach { assertEquals(reach[0], it, 1f) }
|
||||
}
|
||||
|
||||
private fun assertGamepadShape(elements: List<InputSurfaceElement>, width: Int, height: Int, label: String) {
|
||||
assertCross(elements, width, height, listOf("legacy:y", "legacy:b", "legacy:a", "legacy:x"))
|
||||
assertCross(elements, width, height, listOf("legacy:up", "legacy:right", "legacy:down", "legacy:left"))
|
||||
assertEquals(label, emptyList<Pair<String, String>>(), overlapping(elements, width, height))
|
||||
}
|
||||
|
||||
private fun assertStickView(elements: List<InputSurfaceElement>, width: Int, height: Int, label: String) {
|
||||
for (control in listOf(InputControl.LS, InputControl.RS)) {
|
||||
val stick = elements.first { it.control == control }
|
||||
assertTrue("$label ${stick.id} keeps its widened travel width", stick.width * width >= stick.height * height * 1.25f - 1f)
|
||||
assertTrue("$label ${stick.id} stays on screen", stick.x >= 0f && stick.x + stick.width <= 1.0001f)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun sticksKeepTheirFullViewAtSurfaceEdges() {
|
||||
for ((width, height) in listOf(2608 to 1200, 1920 to 1080, 1280 to 960)) {
|
||||
ControllerPrefs.setLayout(context, width, height, mapOf("ls" to (0f to .5f), "rs" to (1f to .5f)))
|
||||
val elements = LegacyGamepadLayout(context, width, height).elements()
|
||||
assertStickView(elements, width, height, "$width x $height")
|
||||
ControllerPrefs.resetLayout(context, width, height)
|
||||
}
|
||||
}
|
||||
|
||||
@Test @Config(qualifiers = "w833dp-h468dp-land-369dpi")
|
||||
fun buttonSizeKeepsTheGamepadShapeAtHandheldDensity() {
|
||||
for ((w, h) in listOf(1920 to 1080, 1920 to 1200)) {
|
||||
val normal = LegacyGamepadLayout(context, w, h).elements()
|
||||
assertGamepadShape(normal, w, h, "$w x $h")
|
||||
val right = setOf("legacy:a", "legacy:b", "legacy:x", "legacy:y", "legacy:rs", "legacy:rb", "legacy:rt", "legacy:start")
|
||||
val left = setOf("legacy:up", "legacy:right", "legacy:down", "legacy:left", "legacy:ls", "legacy:lb", "legacy:lt", "legacy:select")
|
||||
val moved = normal.map { e ->
|
||||
when (e.id) {
|
||||
in right -> e.copy(x = e.x + 21f / w, y = e.y + 18f / h)
|
||||
in left -> e.copy(x = e.x - 20f / w, y = e.y + 15f / h)
|
||||
else -> e
|
||||
}
|
||||
}
|
||||
for (scale in listOf(.8f, 1.25f)) {
|
||||
val generator = LegacyGamepadLayout(context, w, h, scale = scale)
|
||||
assertGamepadShape(generator.elements(), w, h, "$w x $h generated at $scale")
|
||||
val rescaled = generator.rescale(moved, LegacyGamepadLayout(context, w, h))
|
||||
assertGamepadShape(rescaled, w, h, "$w x $h moved at $scale")
|
||||
val a = rescaled.first { it.id == "legacy:a" }
|
||||
val generatedA = generator.elements().first { it.id == "legacy:a" }
|
||||
assertEquals(generatedA.x + 21f / w, a.x, .001f)
|
||||
assertEquals(generatedA.y + 18f / h, a.y, .001f)
|
||||
assertEquals(moved, LegacyGamepadLayout(context, w, h).rescale(rescaled, generator).let { back ->
|
||||
back.zip(moved).map { (b, m) -> if (kotlin.math.abs(b.x - m.x) < .001f && kotlin.math.abs(b.y - m.y) < .001f && kotlin.math.abs(b.width - m.width) < .001f) m else b }
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test @Config(qualifiers = "w745dp-h343dp-land-420dpi")
|
||||
fun wideHighDensityGamepadKeepsItsShape() {
|
||||
val elements = LegacyGamepadLayout(context, 2608, 1200).elements()
|
||||
assertGamepadShape(elements, 2608, 1200, "2608 x 1200")
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.content.Context
|
||||
import android.content.ContextWrapper
|
||||
import android.content.SharedPreferences
|
||||
import org.json.JSONObject
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Before
|
||||
@@ -48,6 +50,100 @@ class InputLibraryTest {
|
||||
assertEquals(library, InputLibraries.decode(InputLibraries.encode(library)))
|
||||
}
|
||||
|
||||
@Test fun reopeningARedesignLibraryRestoresTheGamepadAndKeepsCustomBindings() {
|
||||
val original = InputLibraries.read(context)
|
||||
val overlay = original.activeLayout(false, InputRole.PRIMARY)!!
|
||||
val custom = InputSurfaceElement(InputControl.A, .98f, .2f, .02f, .02f, id = "extra")
|
||||
val preset = original.preset(original.profile("game").binding(InputRole.PRIMARY))
|
||||
val saved = original.copy(
|
||||
layouts = original.layouts.map { if (it.id == overlay.id) it.copy(elements = listOf(custom), aspect = 0f) else it },
|
||||
bindings = original.bindings.map {
|
||||
if (it.id == preset.id) it.copy(elements = it.elements + mapOf("extra" to InputAction.Keys(listOf(29)),
|
||||
"legacy:a" to InputAction.Keys(listOf(30)))) else it
|
||||
},
|
||||
)
|
||||
for (version in 15..16) {
|
||||
val raw = JSONObject(InputLibraries.encode(saved)).put("version", version).toString()
|
||||
prefs.edit().putString("library", raw).commit()
|
||||
|
||||
val restored = InputLibraries.read(context)
|
||||
val layout = restored.activeLayout(false, InputRole.PRIMARY)!!
|
||||
assertTrue(layout.elements.any { it.id == "legacy:a" })
|
||||
assertEquals(custom.bounded(), layout.elements.single { it.id == "extra" })
|
||||
assertEquals(InputAction.Keys(listOf(30)), restored.preset(preset.id).elements["legacy:a"])
|
||||
assertEquals(InputAction.Keys(listOf(29)), restored.preset(preset.id).elements["extra"])
|
||||
assertEquals(raw, prefs.getString("library-before-controller-revert", null))
|
||||
assertEquals(restored, InputLibraries.read(context))
|
||||
assertEquals(restored, InputLibraries.update(context) { it })
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun failedRollbackBackupLeavesTheLayoutUsableAndRetriesLater() {
|
||||
val original = InputLibraries.read(context)
|
||||
val raw = JSONObject(InputLibraries.encode(original)).put("version", 16).toString()
|
||||
val backup = "library-before-controller-revert"
|
||||
prefs.edit().putString("library", raw).putString(backup, "previous backup").commit()
|
||||
|
||||
assertEquals(original, InputLibraries.read(contextWithFailedCommits()))
|
||||
assertEquals(raw, prefs.getString("library", null))
|
||||
assertEquals("previous backup", prefs.getString(backup, null))
|
||||
|
||||
assertEquals(original, InputLibraries.read(context))
|
||||
assertEquals(14, JSONObject(prefs.getString("library", null)!!).getInt("version"))
|
||||
assertEquals(raw, prefs.getString(backup, null))
|
||||
}
|
||||
|
||||
@Test fun failedRecoveryRestoresBothValuesAndTheNextEditRetriesRecovery() {
|
||||
val raw = "unreadable library"
|
||||
val backup = "library-recovery." + java.util.UUID.nameUUIDFromBytes(raw.toByteArray(Charsets.UTF_8))
|
||||
prefs.edit().putString("library", raw).putString(backup, "previous backup").commit()
|
||||
val failing = contextWithFailedCommits()
|
||||
|
||||
repeat(2) {
|
||||
assertThrows(IllegalStateException::class.java) { InputLibraries.update(failing) { it } }
|
||||
assertEquals(raw, prefs.getString("library", null))
|
||||
assertEquals("previous backup", prefs.getString(backup, null))
|
||||
}
|
||||
InputLibraries.update(context) { it }
|
||||
assertEquals(raw, prefs.getString(backup, null))
|
||||
assertNotNull(InputLibraries.decode(prefs.getString("library", null)!!))
|
||||
}
|
||||
|
||||
private fun contextWithFailedCommits(): Context = object : ContextWrapper(context) {
|
||||
override fun getSharedPreferences(name: String, mode: Int): SharedPreferences {
|
||||
val original = super.getSharedPreferences(name, mode)
|
||||
if (name != "input-profiles") return original
|
||||
return object : SharedPreferences by original {
|
||||
override fun edit(): SharedPreferences.Editor {
|
||||
val editor = original.edit()
|
||||
return object : SharedPreferences.Editor by editor {
|
||||
override fun putString(key: String, value: String?): SharedPreferences.Editor {
|
||||
editor.putString(key, value)
|
||||
return this
|
||||
}
|
||||
|
||||
override fun commit(): Boolean {
|
||||
editor.apply()
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun revertingKeepsIntentionallyEmptyGamepadsEmpty() {
|
||||
val original = InputLibraries.read(context)
|
||||
val doc = JSONObject(InputLibraries.encode(original)).put("version", 16)
|
||||
val layouts = doc.getJSONArray("layouts")
|
||||
val overlay = (0 until layouts.length()).map(layouts::getJSONObject)
|
||||
.single { it.getString("id") == InputLibraries.OVERLAY }
|
||||
overlay.put("kitless", true).put("elements", org.json.JSONArray())
|
||||
prefs.edit().putString("library", doc.toString()).commit()
|
||||
|
||||
assertTrue(InputLibraries.read(context).activeLayout(false, InputRole.PRIMARY)!!.elements.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun legacyLowerScreenBindingsKeepTheirOriginalControlsWithoutSavedGeometry() {
|
||||
prefs.edit().putBoolean("migrated", true).putString("profile.game",
|
||||
"""{"version":1,"bindings":[{"role":"SECONDARY","control":"a","action":{"type":"keys","codes":[57]}}]}""").commit()
|
||||
@@ -237,22 +333,144 @@ class InputLibraryTest {
|
||||
bindings = original.bindings.map { if (it.layoutId == InputLibraries.OVERLAY) it.copy(layoutId = null, elements = emptyMap(), clicks = emptyMap()) else it })
|
||||
val raw = org.json.JSONObject(InputLibraries.encode(fixed)).put("version", 2).toString()
|
||||
prefs.edit().putString("library", raw).commit()
|
||||
LegacyControllerPrefs.setOpacity(context, 60)
|
||||
ControllerPrefs.setStickClick(context, false)
|
||||
ControllerPrefs.setKeyboardButton(context, true)
|
||||
val size = context.resources.displayMetrics
|
||||
ControllerPrefs.setLayout(context, size.widthPixels, size.heightPixels, mapOf("a" to (.5f to .5f), "ls" to (.3f to .4f)))
|
||||
ControllerPrefs.setLayout(context, 1600, 900, mapOf("ls" to (.3f to .4f)))
|
||||
val migrated = InputLibraries.read(context)
|
||||
val saved = prefs.getString("library", null)
|
||||
assertEquals(migrated, InputLibraries.read(context))
|
||||
assertEquals(saved, prefs.getString("library", null))
|
||||
assertFalse(migrated.layouts.any { it.template == InputLayoutTemplate.OVERLAY })
|
||||
assertTrue(migrated.layouts.any { it.id == "migrated.layout.1600x900" })
|
||||
assertEquals(original.layout("game", InputRole.SECONDARY), migrated.layout("game", InputRole.SECONDARY))
|
||||
assertEquals(original.preset(original.profile("game").binding(InputRole.PHYSICAL)), migrated.preset(migrated.profile("game").binding(InputRole.PHYSICAL)))
|
||||
val layout = migrated.layout("game", InputRole.PRIMARY)!!
|
||||
val preset = migrated.preset(migrated.profile("game").binding(InputRole.PRIMARY))
|
||||
assertTrue(layout.editable)
|
||||
assertTrue(OnScreenLayout.generated(layout))
|
||||
assertEquals(60, layout.style.opacity)
|
||||
assertEquals(InputAction.Command(InputCommand.KEYBOARD), migrated.compile("game").elementAction(InputRole.PRIMARY, KitLayout.KEYBOARD_ID, InputControl.A))
|
||||
assertEquals(InputAction.Native(), migrated.compile("game").elementAction(InputRole.PRIMARY, KitLayout.DPAD_ID, InputControl.LS))
|
||||
assertEquals(InputAction.Native(), preset.action(InputSurfaceElement(InputControl.A, .1f, .1f, .1f, .1f)))
|
||||
assertEquals(InputAction.Command(InputCommand.KEYBOARD), preset.elements["builtin:keyboard"])
|
||||
assertEquals(InputAction.Disabled, preset.clickAction(layout.elements.first { it.control == InputControl.LS }))
|
||||
}
|
||||
|
||||
@Test fun oldGamepadPlacementAndVisibilityBecomeEditableElements() {
|
||||
ControllerPrefs.setLayout(context, 1200, 800, mapOf("ls" to (.4f to .5f)))
|
||||
ControllerPrefs.setSteamButton(context, false)
|
||||
ControllerPrefs.setTarget(context, "b", ControllerPrefs.OFF)
|
||||
val elements = LegacyGamepadLayout(context, 1200, 800).elements()
|
||||
val stick = elements.first { it.control == InputControl.LS }
|
||||
assertEquals(.4f, stick.x + stick.width - stick.height * 800f / 1200f / 2f, .0001f)
|
||||
assertEquals(.5f, stick.y + stick.height / 2f, .0001f)
|
||||
assertFalse(elements.any { it.control == InputControl.GUIDE || it.control == InputControl.B })
|
||||
assertTrue(elements.all { it == it.bounded() })
|
||||
}
|
||||
|
||||
@Test fun gamepadControlsAreRoundWithShoulderPillsAndACompactKeyboard() {
|
||||
val elements = LegacyGamepadLayout(context, 1200, 800).elements()
|
||||
val density = context.resources.displayMetrics.density
|
||||
for (element in elements.filter { it.id.startsWith("legacy:") }) {
|
||||
val shoulder = element.control in setOf(InputControl.LB, InputControl.RB, InputControl.LT, InputControl.RT)
|
||||
assertEquals(element.control.id, if (shoulder) InputButtonShape.PILL else InputButtonShape.CIRCLE, element.buttonShape)
|
||||
}
|
||||
val keyboard = elements.single { it.id == "builtin:keyboard" }
|
||||
assertEquals(InputButtonIcons.KEYBOARD, keyboard.icon)
|
||||
assertEquals(InputButtonShape.CIRCLE, keyboard.buttonShape)
|
||||
assertEquals(36 * density / 1200f, keyboard.width, .0001f)
|
||||
assertEquals(90 * density / 1200f, keyboard.x + keyboard.width / 2f, .0001f)
|
||||
assertEquals(1f - 34 * density / 800f, keyboard.y + keyboard.height / 2f, .0001f)
|
||||
}
|
||||
|
||||
@Test fun dpadButtonsMatchTheFaceButtonsInSizeAndSpacing() {
|
||||
val elements = LegacyGamepadLayout(context, 1200, 800).elements()
|
||||
fun centre(c: InputControl) = elements.single { it.id == "legacy:${c.id}" }.let { (it.x + it.width / 2f) * 1200 to (it.y + it.height / 2f) * 800 }
|
||||
fun size(c: InputControl) = elements.single { it.id == "legacy:${c.id}" }.width * 1200
|
||||
assertEquals(size(InputControl.A), size(InputControl.UP), .01f)
|
||||
assertEquals(centre(InputControl.A).second - centre(InputControl.Y).second, centre(InputControl.DOWN).second - centre(InputControl.UP).second, .01f)
|
||||
assertEquals(centre(InputControl.B).first - centre(InputControl.X).first, centre(InputControl.RIGHT).first - centre(InputControl.LEFT).first, .01f)
|
||||
}
|
||||
|
||||
@Test fun anUntouchedSavedDpadIsResizedAroundItsCentreAndAMovedOneIsKept() {
|
||||
val fresh = LegacyGamepadLayout(context, 1200, 800)
|
||||
val target = fresh.elements().filter { it.control in setOf(InputControl.UP, InputControl.RIGHT, InputControl.DOWN, InputControl.LEFT) }
|
||||
val cx = target.map { it.x + it.width / 2f }.average().toFloat()
|
||||
val cy = target.map { it.y + it.height / 2f }.average().toFloat()
|
||||
val scale = 26f / 30f
|
||||
val old = target.map { e ->
|
||||
val ex = cx + (e.x + e.width / 2f - cx) * 52f / 50f
|
||||
val ey = cy + (e.y + e.height / 2f - cy) * 52f / 50f
|
||||
e.copy(x = ex - e.width * scale / 2f, y = ey - e.height * scale / 2f, width = e.width * scale, height = e.height * scale, buttonShape = InputButtonShape.ROUNDED)
|
||||
}
|
||||
val restyled = fresh.restyle(old)
|
||||
for ((want, got) in target.zip(restyled)) {
|
||||
assertEquals(want.x, got.x, .0005f); assertEquals(want.y, got.y, .0005f)
|
||||
assertEquals(want.width, got.width, .0005f); assertEquals(InputButtonShape.CIRCLE, got.buttonShape)
|
||||
}
|
||||
val moved = old.mapIndexed { i, e -> if (i == 0) e.copy(buttonShape = InputButtonShape.RECTANGLE) else e }
|
||||
assertEquals(moved.drop(1).map { it.width }, fresh.restyle(moved).drop(1).map { it.width })
|
||||
val shifted = old.mapIndexed { i, e -> if (i == 0) e.copy(x = e.x + .03f) else e }
|
||||
assertEquals(shifted.map { listOf(it.x, it.y, it.width, it.height) }, fresh.restyle(shifted).map { listOf(it.x, it.y, it.width, it.height) })
|
||||
}
|
||||
|
||||
@Test fun stickTouchAreasReachFurtherOutwardButKeepTheirInnerEdge() {
|
||||
val elements = LegacyGamepadLayout(context, 1200, 800).elements()
|
||||
for (control in listOf(InputControl.LS, InputControl.RS)) {
|
||||
val stick = elements.single { it.control == control }
|
||||
assertEquals(control.id, stick.height * 800f * 1.25f, stick.width * 1200f, 1f)
|
||||
}
|
||||
val left = elements.single { it.control == InputControl.LS }
|
||||
val right = elements.single { it.control == InputControl.RS }
|
||||
ControllerPrefs.setLayout(context, 1200, 800, mapOf("ls" to (.3f to .5f), "rs" to (.7f to .5f)))
|
||||
val placed = LegacyGamepadLayout(context, 1200, 800).elements()
|
||||
val ls = placed.single { it.control == InputControl.LS }
|
||||
val rs = placed.single { it.control == InputControl.RS }
|
||||
assertEquals(.3f, ls.x + ls.width - ls.height * 800f / 1200f / 2f, .0001f)
|
||||
assertEquals(.7f, rs.x + rs.height * 800f / 1200f / 2f, .0001f)
|
||||
assertTrue(left.width > left.height * 800f / 1200f && right.width > right.height * 800f / 1200f)
|
||||
}
|
||||
|
||||
@Test fun adaptiveSticksToggleChangesOnlyTheSticksOfThatLayout() {
|
||||
val library = InputLibraries.read(context)
|
||||
val overlay = library.layouts.single { it.id == InputLibraries.OVERLAY }
|
||||
assertEquals(true, overlay.adaptiveSticks)
|
||||
InputLibraries.setAdaptiveSticks(context, overlay.id, false)
|
||||
val off = InputLibraries.read(context)
|
||||
val changed = off.layouts.single { it.id == overlay.id }
|
||||
assertEquals(false, changed.adaptiveSticks)
|
||||
assertFalse(ControllerPrefs.read(context).adaptiveSticks)
|
||||
assertEquals(overlay.elements.filter { it.kind != InputElementKind.STICK }, changed.elements.filter { it.kind != InputElementKind.STICK })
|
||||
assertEquals(library.layouts.filter { it.id != overlay.id }, off.layouts.filter { it.id != overlay.id })
|
||||
assertNull(off.layouts.single { it.id == InputLibraries.DECK }.adaptiveSticks)
|
||||
assertTrue(InputLibraries.setAdaptiveSticks(context, overlay.id, true))
|
||||
assertEquals(true, InputLibraries.read(context).layouts.single { it.id == overlay.id }.adaptiveSticks)
|
||||
prefs.edit().putString("library", JSONObject().put("version", 99).toString()).commit()
|
||||
assertFalse(InputLibraries.setAdaptiveSticks(context, overlay.id, false))
|
||||
assertTrue(ControllerPrefs.read(context).adaptiveSticks)
|
||||
}
|
||||
|
||||
@Test fun savedGamepadsFromTheFirstUnifiedBuildGetTheRoundLookOnce() {
|
||||
val fresh = InputLibraries.read(context)
|
||||
val overlay = fresh.layouts.single { it.id == InputLibraries.OVERLAY }
|
||||
val old = overlay.copy(elements = overlay.elements.map { e ->
|
||||
if (e.id == "builtin:keyboard") InputSurfaceElement(InputControl.A, .02f, .9f, .12f, .08f, "builtin:keyboard", name = "Keyboard")
|
||||
else if (e.control == InputControl.A) e.copy(buttonShape = InputButtonShape.RECTANGLE, x = .5f)
|
||||
else e.copy(buttonShape = InputButtonShape.ROUNDED)
|
||||
})
|
||||
val custom = SavedInputLayout("mine", "Mine", listOf(InputSurfaceElement(InputControl.B, .1f, .1f, .1f, .1f)))
|
||||
val stored = fresh.withLayout(old).withLayout(custom)
|
||||
val renamed = InputSurfaceElement(InputControl.A, .02f, .9f, .12f, .08f, "builtin:keyboard", name = "Keys")
|
||||
assertEquals(renamed, LegacyGamepadLayout(context, 1200, 800).restyle(listOf(renamed)).single())
|
||||
prefs.edit().putString("library", JSONObject(InputLibraries.encode(stored)).put("version", 8).toString()).commit()
|
||||
val upgraded = InputLibraries.read(context)
|
||||
val restyled = upgraded.layouts.single { it.id == InputLibraries.OVERLAY }.elements
|
||||
assertEquals(overlay.elements.single { it.id == "builtin:keyboard" }, restyled.single { it.id == "builtin:keyboard" })
|
||||
assertEquals(InputButtonShape.RECTANGLE, restyled.single { it.control == InputControl.A && it.id.startsWith("legacy:") }.buttonShape)
|
||||
assertEquals(.5f, restyled.single { it.control == InputControl.A && it.id.startsWith("legacy:") }.x, .0001f)
|
||||
assertEquals(InputButtonShape.PILL, restyled.single { it.control == InputControl.LB }.buttonShape)
|
||||
assertEquals(InputButtonShape.CIRCLE, restyled.single { it.control == InputControl.UP }.buttonShape)
|
||||
assertEquals(InputButtonShape.ROUNDED, upgraded.layouts.single { it.id == "mine" }.elements.single().buttonShape)
|
||||
assertEquals(upgraded, InputLibraries.read(context))
|
||||
for (desktop in listOf(false, true))
|
||||
assertEquals(InputAction.Command(InputCommand.KEYBOARD), upgraded.compileActive(desktop).elementAction(InputRole.PRIMARY, "builtin:keyboard", InputControl.A))
|
||||
}
|
||||
|
||||
@Test fun quickPartsAreModeSpecificAndDoNotEditSavedProfiles() {
|
||||
@@ -383,7 +601,7 @@ class InputLibraryTest {
|
||||
assertNull(fresh.layouts.single { it.id == InputLibraries.DECK }.style.tint)
|
||||
assertNull(fresh.layouts.single { it.id == InputLibraries.TRACKPAD }.style.tint)
|
||||
assertEquals(ControllerPrefs.STEAM_BLUE, fresh.layouts.single { it.id == InputLibraries.OVERLAY }.style.tint)
|
||||
val red = 0xFFFF6FB5.toInt()
|
||||
val red = ControllerPrefs.tints.last().first
|
||||
val blue = fresh.layouts.map { it.copy(style = it.style.copy(tint = if (it.id == InputLibraries.TRACKPAD) red else ControllerPrefs.STEAM_BLUE)) }
|
||||
val mine = SavedInputLayout("mine", "Mine", listOf(InputSurfaceElement(InputControl.B, .1f, .1f, .1f, .1f)))
|
||||
val old = JSONObject(InputLibraries.encode(blue.fold(fresh) { library, layout -> library.withLayout(layout) }.withLayout(mine))).put("version", 8)
|
||||
@@ -398,125 +616,6 @@ class InputLibraryTest {
|
||||
assertEquals(InputLibraries.read(context), InputLibraries.read(context))
|
||||
}
|
||||
|
||||
@Test fun anOldEditorGamepadStaysActiveAndCanSwitchToTheNewKit() {
|
||||
val fresh = InputLibraries.read(context)
|
||||
val a = InputSurfaceElement(InputControl.A, .7f, .6f, .1f, .2f)
|
||||
val key = InputSurfaceElement(InputControl.A, .4f, .1f, .08f, .15f, "jump", name = "Jump")
|
||||
val gamepad = fresh.layouts.single { it.id == InputLibraries.OVERLAY }.copy(elements = listOf(a, key), aspect = 2f)
|
||||
val actions = SavedInputBindings("old.actions", "Old", false, InputLibraries.OVERLAY, elements = mapOf("jump" to InputAction.Keys(listOf(57))))
|
||||
val old = JSONObject(InputLibraries.encode(fresh.withLayout(gamepad).withPreset(actions)
|
||||
.selectPart(false, InputRole.PRIMARY, actions.id))).put("version", 14)
|
||||
prefs.edit().putString("library", old.toString()).commit()
|
||||
val upgraded = InputLibraries.read(context)
|
||||
assertEquals(listOf(key), upgraded.layouts.single { it.id == InputLibraries.OVERLAY }.elements)
|
||||
val kept = upgraded.layouts.single { it.name == "Gamepad (old layout)" }
|
||||
assertEquals(listOf(a, key), kept.elements)
|
||||
assertTrue(kept.kitless)
|
||||
assertEquals(2f, kept.aspect)
|
||||
assertTrue(upgraded.bindings.any { it.layoutId == kept.id && it.elements["jump"] == InputAction.Keys(listOf(57)) })
|
||||
assertEquals(upgraded.bindings.count { it.layoutId == InputLibraries.OVERLAY }, upgraded.bindings.count { it.layoutId == kept.id })
|
||||
assertTrue(kept.supports(InputRole.PRIMARY) && kept.editable)
|
||||
assertEquals(kept.id, upgraded.activeLayout(false, InputRole.PRIMARY)?.id)
|
||||
assertEquals(kept.id, upgraded.activeLayout(true, InputRole.PRIMARY)?.id)
|
||||
assertEquals(actions.elements, upgraded.preset(upgraded.activePart(false, InputRole.PRIMARY).bindings).elements)
|
||||
assertEquals(upgraded, InputLibraries.read(context))
|
||||
ControlsChoice.choose(context, null, InputLibraries.OVERLAY, desktop = false)
|
||||
assertEquals(actions.id, InputLibraries.read(context).activePart(false, InputRole.PRIMARY).bindings)
|
||||
ControlsChoice.choose(context, null, kept.id, desktop = false)
|
||||
val restored = InputLibraries.read(context)
|
||||
assertEquals(upgraded.activePart(false, InputRole.PRIMARY), restored.activePart(false, InputRole.PRIMARY))
|
||||
assertEquals(actions.elements, restored.preset(restored.activePart(false, InputRole.PRIMARY).bindings).elements)
|
||||
}
|
||||
|
||||
@Test fun aPreviewLibraryRestoresItsPreviousLayoutOnlyWhenChosen() {
|
||||
val fresh = InputLibraries.read(context)
|
||||
val oldLayout = fresh.layouts.single { it.id == InputLibraries.OVERLAY }.copy(
|
||||
elements = listOf(InputSurfaceElement(InputControl.A, .7f, .6f, .1f, .2f)), aspect = 2f)
|
||||
prefs.edit().putString("library", JSONObject(InputLibraries.encode(fresh.withLayout(oldLayout))).put("version", 14).toString()).commit()
|
||||
InputLibraries.read(context)
|
||||
ControlsChoice.choose(context, null, InputLibraries.OVERLAY, desktop = false)
|
||||
|
||||
val previous = InputLibraries.previousLayoutId(InputLibraries.OVERLAY)
|
||||
val option = ControlsChoice.options(context, null, steamMode = true).single { it.id == previous }
|
||||
assertEquals(context.getString(com.droiddeck.launcher.R.string.osc_restore_previous_layout), option.detail)
|
||||
assertEquals(InputLibraries.OVERLAY, ControlsChoice.current(context, null, steamMode = true))
|
||||
ControlsChoice.choose(context, null, option.id, desktop = false)
|
||||
assertEquals(previous, ControlsChoice.current(context, null, steamMode = true))
|
||||
assertEquals(oldLayout.elements, InputLibraries.read(context).activeLayout(false, InputRole.PRIMARY)?.elements)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(qualifiers = "w640dp-h360dp-land-mdpi")
|
||||
fun uneditedOldStockGeometryFollowsTheNewKit() {
|
||||
// Captured with InputLibraries.read and encode at 56986b599 on the same display configuration.
|
||||
val old = requireNotNull(javaClass.getResource("/input/schema14-stock.json")).readText()
|
||||
assertEquals(14, JSONObject(old).getInt("version"))
|
||||
prefs.edit().putString("library", old).commit()
|
||||
|
||||
val upgraded = InputLibraries.read(context)
|
||||
assertEquals(InputLibraries.OVERLAY, upgraded.activeLayout(false, InputRole.PRIMARY)?.id)
|
||||
assertTrue(OnScreenLayout.generated(upgraded.activeLayout(false, InputRole.PRIMARY)!!))
|
||||
assertTrue(upgraded.layouts.none { it.id == InputLibraries.previousLayoutId(InputLibraries.OVERLAY) })
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(qualifiers = "w640dp-h360dp-land-mdpi")
|
||||
fun anOldStockLayoutWithACustomFrameStaysActive() {
|
||||
val old = JSONObject(requireNotNull(javaClass.getResource("/input/schema14-stock.json")).readText())
|
||||
val layouts = old.getJSONArray("layouts")
|
||||
val overlay = (0 until layouts.length()).map(layouts::getJSONObject)
|
||||
.single { it.getString("id") == InputLibraries.OVERLAY }
|
||||
overlay.put("aspect", 4.0 / 3.0)
|
||||
prefs.edit().putString("library", old.toString()).commit()
|
||||
|
||||
val active = requireNotNull(InputLibraries.read(context).activeLayout(false, InputRole.PRIMARY))
|
||||
assertEquals(InputLibraries.previousLayoutId(InputLibraries.OVERLAY), active.id)
|
||||
assertEquals(4f / 3f, active.aspect)
|
||||
assertTrue(active.kitless)
|
||||
}
|
||||
|
||||
@Test fun anActionForAKitButtonTheOldGamepadDidNotPlaceStillLoads() {
|
||||
val fresh = InputLibraries.read(context)
|
||||
val a = InputSurfaceElement(InputControl.A, .7f, .6f, .1f, .2f)
|
||||
val gamepad = fresh.layouts.single { it.id == InputLibraries.OVERLAY }.copy(elements = listOf(a), aspect = 2f)
|
||||
val actions = SavedInputBindings("old.actions", "Old", false, InputLibraries.OVERLAY,
|
||||
elements = mapOf("legacy:a" to InputAction.Keys(listOf(30)), "legacy:b" to InputAction.Keys(listOf(48))))
|
||||
prefs.edit().putString("library", JSONObject(InputLibraries.encode(fresh.withLayout(gamepad).withPreset(actions))).put("version", 14).toString()).commit()
|
||||
val upgraded = InputLibraries.read(context)
|
||||
val kept = upgraded.layouts.single { it.name == "Gamepad (old layout)" }
|
||||
val copy = upgraded.bindings.single { it.layoutId == kept.id && it.name == kept.name && it.elements.containsKey("legacy:a") }
|
||||
assertEquals(setOf("legacy:a"), copy.elements.keys)
|
||||
assertEquals(actions.elements, upgraded.preset("old.actions").elements)
|
||||
}
|
||||
|
||||
@Test fun anOldGamepadKeepsItsPositionsInPlaceWhenTheLibraryIsFull() {
|
||||
val fresh = InputLibraries.read(context)
|
||||
val a = InputSurfaceElement(InputControl.A, .7f, .6f, .1f, .2f)
|
||||
val gamepad = fresh.layouts.single { it.id == InputLibraries.OVERLAY }.copy(elements = listOf(a), aspect = 2f)
|
||||
val filler = (fresh.layouts.size until 256).map { SavedInputLayout("filler.$it", "Filler $it", listOf(InputSurfaceElement(InputControl.B, .1f, .1f, .1f, .1f))) }
|
||||
val full = filler.fold(fresh.withLayout(gamepad)) { library, layout -> library.withLayout(layout) }
|
||||
assertEquals(256, full.layouts.size)
|
||||
prefs.edit().putString("library", JSONObject(InputLibraries.encode(full)).put("version", 14).toString()).commit()
|
||||
val upgraded = InputLibraries.read(context)
|
||||
val overlay = upgraded.layouts.single { it.id == InputLibraries.OVERLAY }
|
||||
assertEquals(listOf(a), overlay.elements)
|
||||
assertTrue(overlay.kitless)
|
||||
assertEquals(256, upgraded.layouts.size)
|
||||
}
|
||||
|
||||
@Test fun aLayoutWithAllKitControlsRemovedStaysKeyOnly() {
|
||||
val fresh = InputLibraries.read(context)
|
||||
val key = InputSurfaceElement(InputControl.A, .4f, .1f, .08f, .15f, "jump", name = "Jump")
|
||||
val old = JSONObject(InputLibraries.encode(fresh.withLayout(fresh.layouts.single { it.id == InputLibraries.OVERLAY }.copy(elements = listOf(key), aspect = 2f))))
|
||||
.put("version", 14)
|
||||
prefs.edit().putString("library", old.toString()).commit()
|
||||
val upgraded = InputLibraries.read(context)
|
||||
val active = requireNotNull(upgraded.activeLayout(false, InputRole.PRIMARY))
|
||||
assertEquals(listOf(key), active.elements)
|
||||
assertTrue(active.kitless)
|
||||
assertTrue(OnScreenLayout.generated(upgraded.layouts.single { it.id == InputLibraries.OVERLAY }))
|
||||
}
|
||||
|
||||
@Test fun versionTenStockPanelsReturnToGrayOnce() {
|
||||
val fresh = InputLibraries.read(context)
|
||||
val blue = fresh.layouts.filter { it.id == InputLibraries.DECK || it.id == InputLibraries.TRACKPAD }
|
||||
|
||||
@@ -20,9 +20,9 @@ class InputProfilesTest {
|
||||
}
|
||||
|
||||
@Test fun migrationKeepsLegacyTouchMappingSeparateFromPhysicalControls() {
|
||||
LegacyControllerPrefs.setTarget(context, "a", "b")
|
||||
LegacyControllerPrefs.setTarget(context, "x", "off")
|
||||
LegacyControllerPrefs.setSelectSteam(context, true)
|
||||
ControllerPrefs.setTarget(context, "a", "b")
|
||||
ControllerPrefs.setTarget(context, "x", "off")
|
||||
ControllerPrefs.setSelectSteam(context, true)
|
||||
val game = InputProfiles.read(context, InputProfile.GAME)
|
||||
assertEquals(InputAction.Native(InputControl.B), game.action(InputRole.PRIMARY, InputControl.A))
|
||||
assertEquals(InputAction.Disabled, game.action(InputRole.PRIMARY, InputControl.X))
|
||||
@@ -35,7 +35,7 @@ class InputProfilesTest {
|
||||
}
|
||||
|
||||
@Test fun migrationPreservesSavedDesktopSelectBinding() {
|
||||
LegacyControllerPrefs.setSelectSteam(context, true)
|
||||
ControllerPrefs.setSelectSteam(context, true)
|
||||
context.getSharedPreferences("input-profiles", Context.MODE_PRIVATE).edit().putString("profile.desktop",
|
||||
"""{"version":1,"bindings":[{"role":"PHYSICAL","control":"select","action":{"type":"disabled"}}]}""").commit()
|
||||
assertEquals(InputAction.Disabled, InputProfiles.read(context, InputProfile.DESKTOP)
|
||||
@@ -68,8 +68,9 @@ class InputProfilesTest {
|
||||
.putString("profile.game", """{"version":999,"bindings":[]} """).commit()
|
||||
val profile = InputProfiles.read(context, InputProfile.GAME)
|
||||
assertEquals(InputProfile.defaults(InputProfile.GAME).bindings, profile.bindings)
|
||||
assertEquals(InputProfile.defaults(InputProfile.GAME).elements, profile.elements)
|
||||
assertEquals(InputAction.Command(InputCommand.KEYBOARD), profile.elementAction(InputRole.PRIMARY, KitLayout.KEYBOARD_ID, InputControl.A))
|
||||
assertEquals(mapOf(
|
||||
InputRole.PRIMARY to mapOf("builtin:keyboard" to InputAction.Command(InputCommand.KEYBOARD)),
|
||||
), profile.elements)
|
||||
}
|
||||
|
||||
@Test fun layoutsPersistIndependentOfBindingsAndStayInsideScreen() {
|
||||
|
||||
@@ -171,60 +171,4 @@ class InputSurfaceSourceTest {
|
||||
surface.click(true); surface.click(false)
|
||||
assertEquals(listOf("button:272:true", "button:272:false"), events)
|
||||
}
|
||||
|
||||
@Test fun theKitDpadPressesOnlyTheHeldDirectionAndKeepsEachDirectionsBinding() {
|
||||
val dpad = InputSurfaceElement(InputControl.LS, .1f, .1f, .3f, .3f, KitLayout.DPAD_ID, InputElementKind.DPAD)
|
||||
bridge.setInputProfile(InputProfile("test", bindings = mapOf(InputRole.SECONDARY to mapOf(InputControl.LEFT to InputAction.Keys(listOf(30))))))
|
||||
val pad = source(dpad)
|
||||
pad.update(1f, 0f)
|
||||
assertTrue(state().right)
|
||||
assertFalse(state().up || state().down || state().left)
|
||||
pad.update(0f, 0f)
|
||||
assertFalse(state().right)
|
||||
pad.update(-1f, 0f)
|
||||
assertEquals("key:30:true", events.last())
|
||||
assertFalse(state().left)
|
||||
pad.update(0f, 0f)
|
||||
assertEquals("key:30:false", events.last())
|
||||
}
|
||||
|
||||
@Test fun onScreenInputNeverCountsAsAControllerInHand() {
|
||||
var physical = 0; var player = 0
|
||||
bridge.setOnPhysicalInput { physical++ }
|
||||
bridge.setOnPlayerInput { player++ }
|
||||
val stick = source(InputSurfaceElement(InputControl.LS, .1f, .1f, .3f, .3f, "legacy:ls", InputElementKind.STICK))
|
||||
stick.update(1f, 0f); stick.update(0f, 0f)
|
||||
org.robolectric.Shadows.shadowOf(android.os.Looper.getMainLooper()).idle()
|
||||
assertEquals(0, physical)
|
||||
assertTrue(player > 0)
|
||||
}
|
||||
|
||||
@Test fun theKitDpadUsesSavedDirectionButtonsAndCancellingNeverRunsADirectionCommand() {
|
||||
val dpad = InputSurfaceElement(InputControl.LS, .1f, .1f, .3f, .3f, KitLayout.DPAD_ID, InputElementKind.DPAD)
|
||||
bridge.setInputProfile(InputProfile("test", elements = mapOf(InputRole.SECONDARY to mapOf("legacy:up" to InputAction.Keys(listOf(103)),
|
||||
"legacy:down" to InputAction.Command(InputCommand.KEYBOARD)))))
|
||||
val pad = source(dpad)
|
||||
pad.update(0f, -1f)
|
||||
assertEquals("key:103:true", events.last())
|
||||
pad.update(0f, 0f)
|
||||
assertEquals("key:103:false", events.last())
|
||||
events.clear()
|
||||
pad.update(0f, 1f)
|
||||
pad.cancel()
|
||||
assertTrue(events.none { it.startsWith("KEYBOARD") })
|
||||
}
|
||||
|
||||
@Test fun aDirectionHeldAcrossAProfileChangeWaitsForNeutral() {
|
||||
val dpad = InputSurfaceElement(InputControl.LS, .1f, .1f, .3f, .3f, KitLayout.DPAD_ID, InputElementKind.DPAD)
|
||||
bridge.setInputProfile(InputProfile("first", elements = mapOf(InputRole.SECONDARY to mapOf(KitLayout.DPAD_ID to InputAction.Directions(17, 32, 31, 30)))))
|
||||
val pad = source(dpad)
|
||||
pad.update(0f, -1f)
|
||||
bridge.setInputProfile(InputProfile("second", elements = mapOf(InputRole.SECONDARY to mapOf("legacy:up" to InputAction.Keys(listOf(103))))))
|
||||
events.clear()
|
||||
pad.update(0f, -1f)
|
||||
assertTrue(events.none { it == "key:103:true" })
|
||||
pad.update(0f, 0f)
|
||||
pad.update(0f, -1f)
|
||||
assertEquals("key:103:true", events.last())
|
||||
}
|
||||
}
|
||||
@@ -1,355 +0,0 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Rect
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
import kotlin.math.hypot
|
||||
|
||||
private const val HANDHELD = "w833dp-h468dp-land-369dpi"
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [34], manifest = Config.NONE, qualifiers = HANDHELD)
|
||||
class KitLayoutTest {
|
||||
private val context: Context get() = RuntimeEnvironment.getApplication()
|
||||
private val sizes = listOf(1080 to 1920, 1920 to 1080, 1240 to 1080, 2400 to 1080, 1080 to 2400, 1600 to 900, 1280 to 960)
|
||||
|
||||
private fun px(e: InputSurfaceElement, w: Int, h: Int) = floatArrayOf(e.x * w, e.y * h, e.width * w, e.height * h)
|
||||
private fun centre(e: InputSurfaceElement, w: Int, h: Int) = (e.x + e.width / 2) * w to (e.y + e.height / 2) * h
|
||||
|
||||
private fun overlapping(elements: List<InputSurfaceElement>, w: Int, h: Int): List<Pair<String, String>> {
|
||||
val result = mutableListOf<Pair<String, String>>()
|
||||
for ((i, a) in elements.withIndex()) for (b in elements.drop(i + 1)) {
|
||||
val (ax, ay) = centre(a, w, h); val (bx, by) = centre(b, w, h)
|
||||
val round = a.buttonShape == InputButtonShape.CIRCLE && b.buttonShape == InputButtonShape.CIRCLE
|
||||
val hit = if (round) hypot(ax - bx, ay - by) < (minOf(a.width * w, a.height * h) + minOf(b.width * w, b.height * h)) / 2 - .5f
|
||||
else kotlin.math.abs(ax - bx) < (a.width + b.width) * w / 2 - .5f && kotlin.math.abs(ay - by) < (a.height + b.height) * h / 2 - .5f
|
||||
if (hit) result += a.id to b.id
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
private fun ids(kit: PadKit) = KitLayout.elements(context, kit, 1920, 1080).map { it.id }.toSet()
|
||||
|
||||
@Test fun everyKitHasTheCommonControlsOnceEach() {
|
||||
val common = setOf("legacy:lt", "legacy:lb", "legacy:rt", "legacy:rb", "legacy:a", "legacy:b", "legacy:x", "legacy:y", "legacy:ls", "legacy:rs",
|
||||
"legacy:select", "legacy:start", "legacy:guide", "legacy:qam", KitLayout.DPAD_ID, KitLayout.KEYBOARD_ID)
|
||||
for (kit in PadKit.entries) {
|
||||
val elements = KitLayout.elements(context, kit, 1920, 1080)
|
||||
assertEquals(kit.name, elements.size, elements.map { it.id }.distinct().size)
|
||||
assertTrue(kit.name, elements.map { it.id }.containsAll(common))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun steamKitsAddGripsAndTrackpadsAndTheOthersAddStickClicks() {
|
||||
val grips = setOf("legacy:l4", "legacy:l5", "legacy:r4", "legacy:r5")
|
||||
val pads = setOf(InputControl.LEFT_PAD, InputControl.RIGHT_PAD)
|
||||
val clicks = setOf("legacy:l3", "legacy:r3")
|
||||
for (kit in PadKit.entries) {
|
||||
val elements = KitLayout.elements(context, kit, 1920, 1080)
|
||||
assertEquals(kit.name, kit.steam, elements.map { it.id }.containsAll(grips))
|
||||
assertEquals(kit.name, if (kit.steam) pads else emptySet<InputControl>(), elements.filter { it.kind == InputElementKind.TRACKPAD }.map { it.control }.toSet())
|
||||
assertEquals(kit.name, !kit.steam, elements.map { it.id }.containsAll(clicks))
|
||||
assertTrue(kit.name, elements.none { kit.steam && it.id in clicks || !kit.steam && it.id in grips })
|
||||
}
|
||||
assertEquals(KitLayout.elements(context, PadKit.STEAM_DECK, 1920, 1080), KitLayout.elements(context, PadKit.STEAM_CONTROLLER, 1920, 1080))
|
||||
assertEquals(KitLayout.elements(context, PadKit.DUALSHOCK, 1920, 1080), KitLayout.elements(context, PadKit.DUALSENSE, 1920, 1080))
|
||||
assertNotEquals(ids(PadKit.STEAM_DECK), ids(PadKit.XBOX))
|
||||
}
|
||||
|
||||
@Test fun onlySticksFloatAndTheDpadAndKeyboardAreKitElements() {
|
||||
for (kit in PadKit.entries) {
|
||||
val elements = KitLayout.elements(context, kit, 1920, 1080)
|
||||
for (e in elements) assertEquals(e.id, e.kind == InputElementKind.STICK, e.floating)
|
||||
assertEquals(InputElementKind.DPAD, elements.single { it.id == KitLayout.DPAD_ID }.kind)
|
||||
assertEquals(InputButtonIcons.KEYBOARD, elements.single { it.id == KitLayout.KEYBOARD_ID }.icon)
|
||||
for (shoulder in listOf("legacy:lt", "legacy:lb", "legacy:rt", "legacy:rb")) assertEquals(InputButtonShape.PILL, elements.single { it.id == shoulder }.buttonShape)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun controlsStayOnScreenAndApartAtEverySize() {
|
||||
for (kit in PadKit.entries) for ((w, h) in sizes) for (scale in listOf(.8f, 1f, 1.25f)) {
|
||||
val elements = KitLayout.elements(context, kit, w, h, scale = scale)
|
||||
for (e in elements) assertEquals("$kit $w x $h ${e.id}", e, e.bounded())
|
||||
assertEquals("$kit $w x $h at $scale", emptyList<Pair<String, String>>(), overlapping(elements, w, h))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun buttonsAreRoundAndStayRoundOnEveryAspect() {
|
||||
for (kit in PadKit.entries) for ((w, h) in sizes) {
|
||||
for (e in KitLayout.elements(context, kit, w, h).filter { it.buttonShape == InputButtonShape.CIRCLE })
|
||||
assertEquals("$kit $w x $h ${e.id}", e.width * w, e.height * h, 1f)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun theFaceButtonsFormACross() {
|
||||
for (kit in PadKit.entries) {
|
||||
val e = KitLayout.elements(context, kit, 2400, 1080).associateBy { it.id }
|
||||
val (yx, yy) = centre(e.getValue("legacy:y"), 2400, 1080); val (ax, ay) = centre(e.getValue("legacy:a"), 2400, 1080)
|
||||
val (xx, xy) = centre(e.getValue("legacy:x"), 2400, 1080); val (bx, by) = centre(e.getValue("legacy:b"), 2400, 1080)
|
||||
assertEquals(yx, ax, .5f); assertEquals(xy, by, .5f)
|
||||
assertTrue(yy < xy && xy < ay && xx < yx && yx < bx)
|
||||
assertEquals(ay - yy, bx - xx, .5f)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun safeInsetsMoveEdgeControlsInByTheInsetOnly() {
|
||||
val safe = Rect(120, 0, 60, 0)
|
||||
for (kit in PadKit.entries) {
|
||||
val plain = KitLayout.elements(context, kit, 2400, 1080).associateBy { it.id }
|
||||
val inset = KitLayout.elements(context, kit, 2400, 1080, safe)
|
||||
for (e in inset) {
|
||||
val (x, y, ew, eh) = px(e, 2400, 1080).toList()
|
||||
assertTrue("$kit ${e.id}", x >= safe.left - .5f && y >= safe.top - .5f && x + ew <= 2400 - safe.right + .5f && y + eh <= 1080 - safe.bottom + .5f)
|
||||
}
|
||||
val a = plain.getValue("legacy:lt"); val b = inset.single { it.id == "legacy:lt" }
|
||||
assertEquals(safe.left.toFloat(), (b.x - a.x) * 2400, .5f)
|
||||
val r = plain.getValue("legacy:rt"); val s = inset.single { it.id == "legacy:rt" }
|
||||
assertEquals(-safe.right.toFloat(), (s.x - r.x) * 2400, .5f)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun aSideCutoutOnlyMovesTheOverlappingCluster() {
|
||||
val w = 2400
|
||||
val h = 1080
|
||||
val plain = KitLayout.elements(context, PadKit.STEAM_DECK, w, h, rearButtons = false, trackpads = false)
|
||||
val left = Rect(10, 380, 120, 480)
|
||||
val right = Rect(w - 120, 380, w, 480)
|
||||
val adjusted = KitLayout.elements(context, PadKit.STEAM_DECK, w, h, Rect(120, 0, 120, 0),
|
||||
cutouts = listOf(left, right), rearButtons = false, trackpads = false)
|
||||
val face = setOf("legacy:a", "legacy:b", "legacy:x", "legacy:y")
|
||||
val xOffsets = plain.zip(adjusted).associate { (before, after) ->
|
||||
assertEquals(before.id, after.id)
|
||||
assertEquals(before.y, after.y, .00001f)
|
||||
assertEquals(before.width, after.width, .00001f)
|
||||
assertEquals(before.height, after.height, .00001f)
|
||||
assertTrue(after.x * w >= left.right || (after.x + after.width) * w <= left.left ||
|
||||
after.y * h >= left.bottom || (after.y + after.height) * h <= left.top)
|
||||
assertTrue(after.x * w >= right.right || (after.x + after.width) * w <= right.left ||
|
||||
after.y * h >= right.bottom || (after.y + after.height) * h <= right.top)
|
||||
before.id to (after.x - before.x) * w
|
||||
}
|
||||
assertTrue(xOffsets.getValue(KitLayout.DPAD_ID) in 1f..100f)
|
||||
assertTrue(xOffsets.getValue("legacy:b") in -100f..-1f)
|
||||
for ((id, offset) in xOffsets) if (id in face) assertEquals(xOffsets.getValue("legacy:b"), offset, .01f)
|
||||
else if (id != KitLayout.DPAD_ID) assertEquals(id, 0f, offset, .01f)
|
||||
assertTrue(overlapping(adjusted, w, h).isEmpty())
|
||||
}
|
||||
|
||||
@Test fun aCutoutShiftDoesNotCoverAnAddedControl() {
|
||||
val w = 2400
|
||||
val h = 1080
|
||||
val safe = Rect(120, 0, 0, 0)
|
||||
val extra = InputSurfaceElement(InputControl.B, .05f, .4f, .025f, .06f, id = "added")
|
||||
val layout = SavedInputLayout(InputLibraries.OVERLAY, "Gamepad", listOf(extra), aspect = w.toFloat() / h)
|
||||
val fallback = OnScreenLayout.elements(context, layout, w, h, safe, rearButtons = false, trackpads = false)
|
||||
val placed = OnScreenLayout.elements(context, layout, w, h, safe, cutouts = listOf(Rect(0, 380, 120, 480)),
|
||||
rearButtons = false, trackpads = false)
|
||||
assertEquals(fallback, placed)
|
||||
assertTrue(overlapping(placed, w, h).isEmpty())
|
||||
}
|
||||
|
||||
@Test fun startSelectAndHomeAreOnTheFloatingOverlayBottomRow() {
|
||||
for (kit in PadKit.entries) for ((w, h) in sizes) {
|
||||
val buttons = KitLayout.elements(context, kit, w, h)
|
||||
val keyboard = buttons.single { it.id == KitLayout.KEYBOARD_ID }
|
||||
for (button in buttons.filter { it.control == InputControl.SELECT || it.control == InputControl.START || it.control == InputControl.GUIDE }) {
|
||||
assertTrue("$kit $w x $h ${button.id}", button.y + button.height / 2 in keyboard.y..(keyboard.y + keyboard.height))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun theXboxAndPlayStationHomeButtonSitsBetweenSelectAndStart() {
|
||||
for (kit in PadKit.entries.filterNot { it.steam }) for ((w, h) in sizes.filter { it.first > it.second }) {
|
||||
val buttons = KitLayout.elements(context, kit, w, h).associateBy { it.control }
|
||||
val select = buttons.getValue(InputControl.SELECT); val start = buttons.getValue(InputControl.START); val home = buttons.getValue(InputControl.GUIDE)
|
||||
assertTrue("$kit $w x $h", select.x + select.width < home.x && home.x + home.width < start.x)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun widerScreensSpreadTheControlsInsteadOfStretchingThem() {
|
||||
for (kit in PadKit.entries) {
|
||||
val narrow = KitLayout.elements(context, kit, 1920, 1080).associateBy { it.id }
|
||||
val wide = KitLayout.elements(context, kit, 2400, 1080).associateBy { it.id }
|
||||
for ((id, n) in narrow) {
|
||||
val v = wide.getValue(id)
|
||||
assertEquals("$kit $id width", n.width * 1920, v.width * 2400, .5f)
|
||||
assertEquals("$kit $id y", n.y * 1080, v.y * 1080, .5f)
|
||||
val (nx, _) = centre(n, 1920, 1080); val (vx, _) = centre(v, 2400, 1080)
|
||||
val shift = vx - nx
|
||||
assertTrue("$kit $id moved $shift", listOf(0f, 240f, 480f).any { kotlin.math.abs(shift - it) < .5f })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun theCentreOfTheScreenStaysClear() {
|
||||
for (kit in PadKit.entries) for ((w, h) in sizes.filter { it.first > it.second }) {
|
||||
val box = android.graphics.RectF(w * .4f, h * .35f, w * .6f, h * .65f)
|
||||
for (e in KitLayout.elements(context, kit, w, h)) {
|
||||
val (x, y, ew, eh) = px(e, w, h).toList()
|
||||
assertFalse("$kit $w x $h ${e.id}", android.graphics.RectF.intersects(box, android.graphics.RectF(x, y, x + ew, y + eh)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test @Config(qualifiers = "mdpi")
|
||||
fun aBigScreenCapsTheControlsAtAHandheldHeight() {
|
||||
val metrics = context.resources.displayMetrics
|
||||
val dpi = metrics.ydpi.takeIf { it > metrics.densityDpi * .6f && it < metrics.densityDpi * 1.6f } ?: metrics.densityDpi.toFloat()
|
||||
val small = KitLayout.elements(context, PadKit.XBOX, 1600, 900).single { it.id == "legacy:a" }
|
||||
val big = KitLayout.elements(context, PadKit.XBOX, 3200, 1800).single { it.id == "legacy:a" }
|
||||
assertEquals(small.height * 900, big.height * 1800, 1f)
|
||||
val mm = small.height * 900 / dpi * 25.4f
|
||||
assertEquals(116f / 900f * 80f, mm, .3f)
|
||||
}
|
||||
|
||||
@Test fun aHandheldScreenUsesTheFullReferenceSize() {
|
||||
val a = KitLayout.elements(context, PadKit.XBOX, 1920, 1080).single { it.id == "legacy:a" }
|
||||
assertEquals(116f * 1.2f, a.height * 1080, 1f)
|
||||
}
|
||||
|
||||
@Test fun noDefaultControlSitsUnderTheCornerButton() {
|
||||
val density = context.resources.displayMetrics.density
|
||||
val corner = android.graphics.RectF(4 * density, 1080 - 52 * density, 52 * density, 1080 - 4 * density)
|
||||
for (kit in PadKit.entries) for (e in KitLayout.elements(context, kit, 1920, 1080)) {
|
||||
val (cx, cy) = centre(e, 1920, 1080)
|
||||
val r = minOf(e.width * 1920, e.height * 1080) / 2
|
||||
val nx = cx.coerceIn(corner.left, corner.right); val ny = cy.coerceIn(corner.top, corner.bottom)
|
||||
val touches = if (e.buttonShape == InputButtonShape.CIRCLE) hypot(cx - nx, cy - ny) < r - 1f
|
||||
else android.graphics.RectF.intersects(corner, android.graphics.RectF(e.x * 1920, e.y * 1080, (e.x + e.width) * 1920, (e.y + e.height) * 1080))
|
||||
assertFalse("$kit ${e.id} is under the corner button", touches)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun clustersStayTogetherOnTallAndSquareScreens() {
|
||||
val ratio = mapOf(PadKit.STEAM_DECK to 96f / 58f, PadKit.STEAM_CONTROLLER to 96f / 58f, PadKit.XBOX to 94f / 58f,
|
||||
PadKit.DUALSHOCK to 96f / 58f, PadKit.DUALSENSE to 96f / 58f)
|
||||
for (kit in PadKit.entries) for ((w, h) in listOf(1080 to 1920, 1240 to 1080, 2400 to 1080)) {
|
||||
val e = KitLayout.elements(context, kit, w, h).associateBy { it.id }
|
||||
val face = listOf("legacy:y", "legacy:x", "legacy:b", "legacy:a").map { centre(e.getValue(it), w, h) }
|
||||
val cx = face.map { it.first }.average().toFloat(); val cy = face.map { it.second }.average().toFloat()
|
||||
val radius = e.getValue("legacy:a").height * h / 2
|
||||
val spread = if (h > w) .3f / .17f else ratio.getValue(kit)
|
||||
for ((x, y) in face) assertEquals("$kit $w x $h", radius * spread, hypot(x - cx, y - cy), 1f)
|
||||
if (kit == PadKit.XBOX && h <= w) {
|
||||
val (lx, ly) = centre(e.getValue("legacy:ls"), w, h); val (cx3, cy3) = centre(e.getValue("legacy:l3"), w, h)
|
||||
val unit = e.getValue("legacy:ls").height * h / 208f
|
||||
assertEquals("$w x $h", hypot(150f, 110f) * unit, hypot(cx3 - lx, cy3 - ly), 1f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test @Config(qualifiers = "mdpi")
|
||||
fun smallControlsKeepTheirShapeOnABigLowDensityScreen() {
|
||||
for (kit in PadKit.entries) {
|
||||
val elements = KitLayout.elements(context, kit, 1920, 1080)
|
||||
for (e in elements.filter { it.buttonShape == InputButtonShape.CIRCLE }) assertEquals("$kit ${e.id}", e.width * 1920, e.height * 1080, 1f)
|
||||
assertEquals(kit.name, emptyList<Pair<String, String>>(), overlapping(elements, 1920, 1080))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun theBottomLeftRowStartsRightOfTheCornerButtonWithGaps() {
|
||||
val density = context.resources.displayMetrics.density
|
||||
for (safe in listOf(Rect(), Rect(120, 0, 0, 40))) for (kit in PadKit.entries) for ((w, h) in sizes) {
|
||||
val elements = KitLayout.elements(context, kit, w, h, safe)
|
||||
val keyboard = elements.single { it.id == KitLayout.KEYBOARD_ID }
|
||||
val row = elements.filter { e -> val cy = e.y + e.height / 2; cy > keyboard.y && cy < keyboard.y + keyboard.height && e.x + e.width / 2 < .5f }
|
||||
.sortedBy { it.x }
|
||||
assertEquals("$kit $w x $h", keyboard, row.first())
|
||||
assertTrue("$kit $w x $h $safe keyboard at ${keyboard.x * w}", keyboard.x * w >= safe.left + 52 * density - .5f)
|
||||
for ((a, b) in row.zipWithNext()) assertTrue("$kit $w x $h ${a.id} ${b.id}", (b.x - a.x - a.width) * w >= 8 * density - .5f)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun portraitSurfacesPutTheWholePadInTheLowerPartAboveABottomRow() {
|
||||
val density = context.resources.displayMetrics.density
|
||||
for (kit in PadKit.entries) for ((w, h) in listOf(1080 to 1920, 1200 to 2000, 1080 to 2400)) {
|
||||
val elements = KitLayout.elements(context, kit, w, h)
|
||||
val row = 60 * density
|
||||
val area = minOf(h * .6f, w * 1.15f)
|
||||
assertTrue("$kit $w x $h", elements.minOf { it.y } * h >= h - row - area - .5f)
|
||||
assertTrue("$kit $w x $h", elements.maxOf { (it.y + it.height) * h } <= h + .5f)
|
||||
val bottomRow = elements.filter { (it.y + it.height / 2) * h > h - row }
|
||||
assertTrue("$kit $w x $h", bottomRow.any { it.id == KitLayout.KEYBOARD_ID } && bottomRow.any { it.control == InputControl.QAM })
|
||||
assertTrue("$kit $w x $h", bottomRow.minOf { it.x } * w >= 52 * density - .5f)
|
||||
val stick = elements.first { it.id == "legacy:ls" }
|
||||
assertTrue("$kit $w x $h", stick.width * w >= w * if (kit.steam) .2f else .3f)
|
||||
assertTrue("$kit $w x $h", elements.any { it.id == "legacy:rs" })
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun anEmptySurfaceHasNoControls() {
|
||||
assertTrue(KitLayout.elements(context, PadKit.STEAM_DECK, 0, 1080).isEmpty())
|
||||
assertTrue(KitLayout.elements(context, PadKit.STEAM_DECK, 1920, 0).isEmpty())
|
||||
}
|
||||
|
||||
@Test fun theDockedStripAddsGripsOnlyForSteamKitsAndNeverSystemButtons() {
|
||||
val density = context.resources.displayMetrics.density
|
||||
for (kit in PadKit.entries) {
|
||||
val placed = KitLayout.dock(context, kit, 1080, 1300, true, InputControl.LS, InputControl.RS)
|
||||
val boxes = GamepadGeometry.layout(1080f, 1300f, density, true, grips = kit.steam, trackpads = kit.steam)
|
||||
assertEquals(kit.name, kit.steam && boxes.containsKey(GamepadGeometry.Slot.L4), placed.any { it.control == InputControl.L4 })
|
||||
assertEquals(kit.name, kit.steam, placed.any { it.control == InputControl.L4 })
|
||||
assertNull(placed.firstOrNull { it.control == InputControl.GUIDE || it.control == InputControl.QAM })
|
||||
assertEquals(1, placed.count { it.id == KitLayout.DPAD_ID })
|
||||
assertTrue(placed.none { it.floating })
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun onlySteamKitsPutTrackpadsInTheDockedStrip() {
|
||||
for (kit in PadKit.entries) {
|
||||
val placed = KitLayout.dock(context, kit, 1080, 1300, true, InputControl.LS, InputControl.RIGHT_PAD).map { it.control }
|
||||
assertEquals(kit.toString(), kit.steam, InputControl.RIGHT_PAD in placed && InputControl.LEFT_PAD in placed)
|
||||
assertTrue(kit.toString(), InputControl.RS in placed && InputControl.LS in placed)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun aSmallerPortraitPadKeepsTheGripsAndANarrowBottomRowNeverOverlaps() {
|
||||
val grips = setOf("legacy:l4", "legacy:l5", "legacy:r4", "legacy:r5")
|
||||
for (scale in listOf(.8f, 1f)) {
|
||||
val ids = KitLayout.elements(context, PadKit.STEAM_DECK, 720, 1280, scale = scale).map { it.id }
|
||||
assertTrue("$scale", ids.containsAll(grips))
|
||||
}
|
||||
for (kit in PadKit.entries) {
|
||||
val (w, h) = 720 to 1280
|
||||
val elements = KitLayout.elements(context, kit, w, h, Rect(120, 0, 0, 0))
|
||||
assertEquals(kit.toString(), emptyList<Pair<String, String>>(), overlapping(elements, w, h))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun noKitControlIsSmallerThanTheOldGamepadOnAHandheld() {
|
||||
val dp = context.resources.displayMetrics.density
|
||||
for (kit in PadKit.entries) {
|
||||
val e = KitLayout.elements(context, kit, 1920, 1080).associateBy { it.id }
|
||||
assertTrue("$kit face", e.getValue("legacy:a").width * 1920 / 2 >= 30 * dp - 1)
|
||||
assertTrue("$kit d-pad", e.getValue(KitLayout.DPAD_ID).width * 1920 / 2 >= 60 * dp)
|
||||
assertTrue("$kit stick", e.getValue("legacy:ls").width * 1920 / 2 >= 40 * dp)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun aTopCutoutNeverPushesTheShoulderRowIntoTheMiddleControls() {
|
||||
for (kit in PadKit.entries) for (top in listOf(0, 20, 60, 120)) {
|
||||
val elements = KitLayout.elements(context, kit, 1600, 900, Rect(0, top, 0, 0))
|
||||
val lb = elements.single { it.id == "legacy:lb" }
|
||||
val middle = elements.filter { it.id == KitLayout.DPAD_ID || it.id == "legacy:y" }
|
||||
for (m in middle) assertTrue("$kit $top ${m.id}", m.y * 900 >= (lb.y + lb.height) * 900 - .5f || m.x * 1600 >= (lb.x + lb.width) * 1600)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun insetsThatLeaveLessRoomShrinkTheKitInsteadOfOverlappingIt() {
|
||||
for (kit in PadKit.entries) for ((w, h, safe) in listOf(Triple(1600, 900, Rect(0, 60, 0, 0)), Triple(1600, 900, Rect(0, 730, 0, 0)),
|
||||
Triple(1600, 900, Rect(0, 200, 0, 0)), Triple(1600, 900, Rect(0, 200, 0, 150)), Triple(1600, 900, Rect(0, 390, 0, 0)),
|
||||
Triple(1920, 1080, Rect(80, 120, 80, 90)), Triple(2400, 1080, Rect(120, 30, 60, 40)))) {
|
||||
val elements = KitLayout.elements(context, kit, w, h, safe)
|
||||
assertEquals("$kit $w x $h $safe", emptyList<Pair<String, String>>(), overlapping(elements, w, h))
|
||||
if (safe.top + safe.bottom <= 400) for (e in elements) {
|
||||
val (x, y, ew, eh) = px(e, w, h).toList()
|
||||
assertTrue("$kit $safe ${e.id}", x >= safe.left - .5f && y >= safe.top - .5f && x + ew <= w - safe.right + .5f && y + eh <= h - safe.bottom + .5f)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.content.Context
|
||||
|
||||
/** Writes the controller settings older builds saved, so tests can seed the migrations that read them. */
|
||||
internal object LegacyControllerPrefs {
|
||||
private fun edit(context: Context) = ControllerPrefs.prefs(context).edit()
|
||||
|
||||
fun setTarget(context: Context, id: String, target: String) { edit(context).putString("map.$id", target).commit() }
|
||||
fun target(context: Context, id: String): String = ControllerPrefs.read(context).mapping[id] ?: id
|
||||
fun setSelectSteam(context: Context, on: Boolean) { edit(context).putBoolean("selectSteam", on).commit() }
|
||||
fun setOpacity(context: Context, percent: Int) { edit(context).putInt("opacity", percent).commit() }
|
||||
fun setStickClick(context: Context, on: Boolean) { edit(context).putBoolean("stickClick", on).commit() }
|
||||
}
|
||||
@@ -1,229 +0,0 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.content.Context
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import org.json.JSONObject
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [34], manifest = Config.NONE)
|
||||
class OnScreenControlPrefsTest {
|
||||
private val context: Context get() = RuntimeEnvironment.getApplication()
|
||||
private val session get() = context.getSharedPreferences("session", Context.MODE_PRIVATE)
|
||||
private val library get() = context.getSharedPreferences("input-profiles", Context.MODE_PRIVATE)
|
||||
|
||||
@Before fun reset() {
|
||||
for (name in listOf("session", "game-controls", "input-profiles", "input-surfaces", "controller")) context.getSharedPreferences(name, Context.MODE_PRIVATE).edit().clear().commit()
|
||||
}
|
||||
|
||||
@Test fun oldShowModesKeepTheirMeaning() {
|
||||
assertEquals(SessionPrefs.OSC_AUTO, SessionPrefs.oscMode(context))
|
||||
for ((saved, mode) in listOf(SessionPrefs.OSC_AUTO to SessionPrefs.OSC_AUTO, SessionPrefs.OSC_ALWAYS to SessionPrefs.OSC_ALWAYS,
|
||||
SessionPrefs.OSC_NEVER to SessionPrefs.OSC_NEVER, SessionPrefs.OSC_STEAM_QAM to SessionPrefs.OSC_STEAM_QAM,
|
||||
SessionPrefs.OSC_STEAM_TOUCH to SessionPrefs.OSC_AUTO, "buttons" to SessionPrefs.OSC_AUTO)) {
|
||||
session.edit().putString("osc", saved).commit()
|
||||
assertEquals(saved, mode, SessionPrefs.oscMode(context))
|
||||
}
|
||||
session.edit().putString("osc", SessionPrefs.OSC_STEAM_QAM).commit()
|
||||
assertEquals(SessionPrefs.OSC_STEAM_QAM, SessionPrefs.oscMode(context, steamSession = true))
|
||||
assertEquals(SessionPrefs.OSC_AUTO, SessionPrefs.oscMode(context, steamSession = false))
|
||||
session.edit().putString("osc", SessionPrefs.OSC_STEAM_TOUCH).commit()
|
||||
assertEquals(SessionPrefs.OSC_ALWAYS, SessionPrefs.oscMode(context, steamSession = true))
|
||||
SessionPrefs.setOscMode(context, SessionPrefs.OSC_AUTO)
|
||||
assertEquals(SessionPrefs.OSC_AUTO, SessionPrefs.oscMode(context, steamSession = true))
|
||||
assertTrue(SessionPrefs.steamTouchLayout(context))
|
||||
}
|
||||
|
||||
@Test fun theOldSteamTouchModeBecomesTheSteamLayoutUntilChanged() {
|
||||
assertFalse(SessionPrefs.steamTouchLayout(context))
|
||||
session.edit().putString("osc", SessionPrefs.OSC_STEAM_TOUCH).commit()
|
||||
assertTrue(SessionPrefs.steamTouchLayout(context))
|
||||
SessionPrefs.setSteamTouchLayout(context, false)
|
||||
assertFalse(SessionPrefs.steamTouchLayout(context))
|
||||
session.edit().putString("osc", SessionPrefs.OSC_ALWAYS).putBoolean("steamTouchLayout", true).commit()
|
||||
assertTrue(SessionPrefs.steamTouchLayout(context))
|
||||
}
|
||||
|
||||
@Test fun eachGameKeepsItsOwnLayoutChoice() {
|
||||
assertNull(GameControls.bindings(context, null))
|
||||
assertNull(GameControls.bindings(context, 7))
|
||||
GameControls.choose(context, 7, "mine.bindings", steam = false)
|
||||
assertEquals("mine.bindings", GameControls.bindings(context, 7))
|
||||
assertNull(GameControls.bindings(context, 8))
|
||||
assertFalse(GameControls.steamLayout(context, 7))
|
||||
GameControls.choose(context, 7, null, steam = true)
|
||||
assertNull(GameControls.bindings(context, 7))
|
||||
assertTrue(GameControls.steamLayout(context, 7))
|
||||
}
|
||||
|
||||
@Test fun gamesWithoutAChoiceFollowTheDefaultSteamLayout() {
|
||||
SessionPrefs.setSteamTouchLayout(context, true)
|
||||
assertTrue(GameControls.steamLayout(context, null))
|
||||
assertTrue(GameControls.steamLayout(context, 9))
|
||||
GameControls.choose(context, 9, null, steam = false)
|
||||
assertFalse(GameControls.steamLayout(context, 9))
|
||||
assertTrue(GameControls.steamLayout(context, 10))
|
||||
}
|
||||
|
||||
@Test fun kitElementsWithoutSavedBindingsGetTheirDefaultActions() {
|
||||
val profile = InputProfile("empty")
|
||||
assertEquals(InputAction.Native(), profile.elementAction(InputRole.PRIMARY, KitLayout.DPAD_ID, InputControl.LS))
|
||||
assertEquals(InputAction.Command(InputCommand.KEYBOARD), profile.elementAction(InputRole.PRIMARY, KitLayout.KEYBOARD_ID, InputControl.A))
|
||||
assertEquals(InputAction.Native(), profile.elementAction(InputRole.PRIMARY, "legacy:a", InputControl.A))
|
||||
assertEquals(InputAction.Disabled, profile.elementAction(InputRole.PRIMARY, "custom:1", InputControl.A))
|
||||
val mapped = profile.copy(bindings = mapOf(InputRole.PRIMARY to mapOf(InputControl.A to InputAction.Keys(listOf(57)))),
|
||||
elements = mapOf(InputRole.PRIMARY to mapOf(KitLayout.KEYBOARD_ID to InputAction.Disabled)))
|
||||
assertEquals(InputAction.Keys(listOf(57)), mapped.elementAction(InputRole.PRIMARY, "legacy:a", InputControl.A))
|
||||
assertEquals(InputAction.Disabled, mapped.elementAction(InputRole.PRIMARY, KitLayout.KEYBOARD_ID, InputControl.A))
|
||||
|
||||
val bindings = SavedInputBindings("b", "B", false, "layout")
|
||||
assertEquals(InputAction.Native(), bindings.action(InputSurfaceElement(InputControl.LS, 0f, 0f, .1f, .1f, KitLayout.DPAD_ID, InputElementKind.DPAD)))
|
||||
assertEquals(InputAction.Command(InputCommand.KEYBOARD), bindings.action(InputSurfaceElement(InputControl.A, 0f, 0f, .1f, .1f, KitLayout.KEYBOARD_ID)))
|
||||
assertEquals(InputAction.Disabled, bindings.action(InputSurfaceElement(InputControl.A, 0f, 0f, .1f, .1f, "custom:1")))
|
||||
}
|
||||
|
||||
private fun storeAt(version: Int, change: (InputLibrary) -> InputLibrary) {
|
||||
val stored = change(InputLibraries.read(context))
|
||||
library.edit().putString("library", JSONObject(InputLibraries.encode(stored)).put("version", version).toString()).commit()
|
||||
}
|
||||
|
||||
@Test fun gamepadsSavedByTheOldEditorFollowTheKitAgainOnce() {
|
||||
val placed = KitLayout.elements(context, PadKit.STEAM_DECK, 1920, 1080)
|
||||
val custom = SavedInputLayout("custom", "Custom", listOf(InputSurfaceElement(InputControl.B, .1f, .1f, .1f, .1f)), aspect = 2f)
|
||||
storeAt(14) { lib ->
|
||||
val overlay = lib.layouts.single { it.id == InputLibraries.OVERLAY }
|
||||
lib.withLayout(overlay.copy(elements = placed, aspect = 16f / 9, scale = 1.25f))
|
||||
.withLayout(SavedInputLayout("copy", "Copy", placed, aspect = 16f / 9, origin = InputLibraries.OVERLAY))
|
||||
.withLayout(SavedInputLayout("migrated.layout.1600x900", "Gamepad", placed, aspect = 16f / 9))
|
||||
.withLayout(custom)
|
||||
}
|
||||
val before = InputLibraries.decode(library.getString("library", null)!!)!!
|
||||
val upgraded = InputLibraries.read(context)
|
||||
for (id in listOf(InputLibraries.OVERLAY, "copy", "migrated.layout.1600x900")) {
|
||||
val layout = upgraded.layouts.single { it.id == id }
|
||||
assertTrue(id, layout.elements.isEmpty())
|
||||
assertEquals(id, 0f, layout.aspect)
|
||||
assertEquals(id, 1f, layout.scale)
|
||||
assertTrue(id, OnScreenLayout.generated(layout))
|
||||
}
|
||||
assertNull(upgraded.layouts.single { it.id == InputLibraries.OVERLAY }.origin)
|
||||
assertEquals(InputLibraries.OVERLAY, upgraded.layouts.single { it.id == "migrated.layout.1600x900" }.origin)
|
||||
assertEquals(custom, upgraded.layouts.single { it.id == "custom" })
|
||||
for (id in listOf(InputLibraries.DECK, InputLibraries.TRACKPAD)) assertEquals(before.layouts.single { it.id == id }, upgraded.layouts.single { it.id == id })
|
||||
assertEquals(upgraded, InputLibraries.read(context))
|
||||
val edited = upgraded.withLayout(upgraded.layouts.single { it.id == InputLibraries.OVERLAY }.copy(elements = placed, aspect = 16f / 9))
|
||||
InputLibraries.update(context) { edited }
|
||||
assertEquals(placed, InputLibraries.read(context).layouts.single { it.id == InputLibraries.OVERLAY }.elements)
|
||||
}
|
||||
|
||||
@Test fun theKitUpgradeKeepsScreenKeysMergedIntoTheGamepad() {
|
||||
val key = InputSurfaceElement(InputControl.A, .45f, .1f, .1f, .1f, "imported:0", name = "Find", alwaysShown = true)
|
||||
storeAt(14) { lib ->
|
||||
val overlay = lib.layouts.single { it.id == InputLibraries.OVERLAY }
|
||||
val bindings = lib.preset(lib.activePart(false, InputRole.PRIMARY).bindings)
|
||||
lib.withLayout(overlay.copy(elements = KitLayout.elements(context, PadKit.STEAM_DECK, 1920, 1080) + key, aspect = 16f / 9))
|
||||
.withPreset(bindings.copy(elements = bindings.elements + (key.id to InputAction.Keys(listOf(29, 33)))))
|
||||
}
|
||||
val upgraded = InputLibraries.read(context)
|
||||
assertEquals(listOf(key.id), upgraded.layouts.single { it.id == InputLibraries.OVERLAY }.elements.map { it.id }.filter { it.startsWith("imported:") })
|
||||
assertEquals(InputAction.Keys(listOf(29, 33)), upgraded.compileActive(false).elementAction(InputRole.PRIMARY, key.id, InputControl.A))
|
||||
}
|
||||
|
||||
@Test fun bindingsSavedForKitControlsSurviveTheKitUpgrade() {
|
||||
storeAt(14) { lib ->
|
||||
val overlay = lib.layouts.single { it.id == InputLibraries.OVERLAY }
|
||||
val bindings = lib.preset(lib.activePart(false, InputRole.PRIMARY).bindings)
|
||||
lib.withLayout(overlay.copy(elements = KitLayout.elements(context, PadKit.STEAM_DECK, 1920, 1080), aspect = 16f / 9))
|
||||
.withPreset(bindings.copy(elements = bindings.elements + ("legacy:a" to InputAction.Keys(listOf(57))),
|
||||
clicks = bindings.clicks + ("legacy:ls" to InputAction.Disabled)))
|
||||
}
|
||||
val upgraded = InputLibraries.read(context)
|
||||
assertTrue(OnScreenLayout.generated(upgraded.layouts.single { it.id == InputLibraries.OVERLAY }))
|
||||
val profile = upgraded.compileActive(false)
|
||||
assertEquals(InputAction.Keys(listOf(57)), profile.elementAction(InputRole.PRIMARY, "legacy:a", InputControl.A))
|
||||
assertEquals(InputAction.Disabled, profile.clicks[InputRole.PRIMARY]?.get("legacy:ls"))
|
||||
}
|
||||
|
||||
@Test fun changingShowKeepsTheSteamLayoutAnOlderBuildStoredThere() {
|
||||
val prefs = context.getSharedPreferences("session", Context.MODE_PRIVATE)
|
||||
prefs.edit().clear().putString("osc", SessionPrefs.OSC_STEAM_TOUCH).commit()
|
||||
SessionPrefs.setOscMode(context, SessionPrefs.OSC_ALWAYS)
|
||||
assertEquals(SessionPrefs.OSC_ALWAYS, SessionPrefs.oscMode(context))
|
||||
assertTrue(SessionPrefs.steamTouchLayout(context))
|
||||
}
|
||||
|
||||
@Test fun aGamepadWithEveryKitControlRemovedStaysEmptyAndKeepsKitBindingsOnOtherEdits() {
|
||||
val library = InputLibraries.read(context)
|
||||
val overlay = library.layouts.single { it.id == InputLibraries.OVERLAY }
|
||||
val key = InputSurfaceElement(InputControl.A, .4f, .4f, .1f, .1f, "imported:9", name = "Key")
|
||||
val emptied = overlay.copy(elements = listOf(key), aspect = 16f / 9, kitless = true)
|
||||
InputLibraries.update(context) { it.withLayout(emptied) }
|
||||
val stored = InputLibraries.read(context).layouts.single { it.id == InputLibraries.OVERLAY }
|
||||
assertFalse(OnScreenLayout.generated(stored))
|
||||
assertEquals(listOf("imported:9"), OnScreenLayout.elements(context, stored, 1920, 1080, android.graphics.Rect()).map { it.id })
|
||||
val bindings = library.preset(library.activePart(false, InputRole.PRIMARY).bindings)
|
||||
val withKey = InputLibraries.update(context) { lib ->
|
||||
lib.withLayout(overlay).withPreset(bindings.copy(elements = bindings.elements + ("legacy:a" to InputAction.Keys(listOf(30)))))
|
||||
}
|
||||
val dimmed = withKey.withLayout(overlay.copy(style = overlay.style.copy(opacity = 50)))
|
||||
assertEquals(InputAction.Keys(listOf(30)), dimmed.preset(bindings.id).elements["legacy:a"])
|
||||
}
|
||||
|
||||
@Test fun aSavedKitDpadKeepsItsDirectionOverrides() {
|
||||
val library = InputLibraries.read(context)
|
||||
val overlay = library.layouts.single { it.id == InputLibraries.OVERLAY }
|
||||
val saved = overlay.copy(elements = KitLayout.elements(context, PadKit.XBOX, 1920, 1080), aspect = 16f / 9)
|
||||
val bindings = library.preset(library.activePart(false, InputRole.PRIMARY).bindings)
|
||||
val withUp = library.withLayout(saved).withPreset(bindings.copy(elements = bindings.elements + ("legacy:up" to InputAction.Keys(listOf(103)))))
|
||||
val edited = withUp.withLayout(saved.copy(style = saved.style.copy(opacity = 60))).validate()
|
||||
assertEquals(InputAction.Keys(listOf(103)), edited.preset(bindings.id).elements["legacy:up"])
|
||||
val noDpad = edited.withLayout(saved.copy(elements = saved.elements.filterNot { it.id == KitLayout.DPAD_ID }))
|
||||
assertEquals(InputAction.Keys(listOf(103)), noDpad.preset(bindings.id).elements["legacy:up"])
|
||||
}
|
||||
|
||||
@Test fun removingAKitControlFromAGamepadLayoutKeepsItsActionForReset() {
|
||||
val library = InputLibraries.read(context)
|
||||
val overlay = library.layouts.single { it.id == InputLibraries.OVERLAY }
|
||||
val kit = KitLayout.elements(context, PadKit.XBOX, 1920, 1080)
|
||||
val bindings = library.preset(library.activePart(false, InputRole.PRIMARY).bindings)
|
||||
val withA = library.withLayout(overlay.copy(elements = kit, aspect = 16f / 9))
|
||||
.withPreset(bindings.copy(elements = bindings.elements + ("legacy:a" to InputAction.Keys(listOf(30)))))
|
||||
val noA = withA.withLayout(overlay.copy(elements = kit.filterNot { it.id == "legacy:a" }, aspect = 16f / 9)).validate()
|
||||
assertEquals(InputAction.Keys(listOf(30)), noA.preset(bindings.id).elements["legacy:a"])
|
||||
val kitless = noA.withLayout(overlay.copy(elements = emptyList(), kitless = true)).validate()
|
||||
assertEquals(InputAction.Keys(listOf(30)), kitless.preset(bindings.id).elements["legacy:a"])
|
||||
val custom = SavedInputLayout("custom", "Custom", listOf(InputSurfaceElement(InputControl.B, .1f, .1f, .1f, .1f, "legacy:b")))
|
||||
assertNull(custom.element("legacy:a"))
|
||||
assertNull(overlay.element("imported:404"))
|
||||
}
|
||||
|
||||
@Test fun aFailedRecoverySaveLeavesTheStoredLibraryAsItWas() {
|
||||
val stored = JSONObject().put("version", 1).put("profiles", "broken").toString()
|
||||
val real = context.getSharedPreferences("input-profiles", Context.MODE_PRIVATE)
|
||||
real.edit().clear().putString("library", stored).commit()
|
||||
val failing = object : android.content.ContextWrapper(context) {
|
||||
override fun getSharedPreferences(name: String, mode: Int): android.content.SharedPreferences {
|
||||
val prefs = super.getSharedPreferences(name, mode)
|
||||
return object : android.content.SharedPreferences by prefs {
|
||||
override fun edit(): android.content.SharedPreferences.Editor {
|
||||
val editor = prefs.edit()
|
||||
return object : android.content.SharedPreferences.Editor by editor {
|
||||
override fun putString(key: String?, value: String?) = apply { editor.putString(key, value) }
|
||||
override fun remove(key: String?) = apply { editor.remove(key) }
|
||||
override fun commit(): Boolean { editor.apply(); return false }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
assertTrue(runCatching { InputLibraries.update(failing) { it } }.isFailure)
|
||||
assertEquals(stored, real.getString("library", null))
|
||||
assertTrue(real.all.keys.none { it.startsWith("library-recovery.") })
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,6 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Looper
|
||||
import android.view.ViewConfiguration
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import java.time.Duration
|
||||
import org.robolectric.Shadows.shadowOf
|
||||
import org.robolectric.Robolectric
|
||||
import androidx.activity.ComponentActivity
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.widget.FrameLayout
|
||||
@@ -112,11 +105,25 @@ class OnScreenControlsTest {
|
||||
view.updateLayout(SavedInputLayout("test", "Test", listOf(left.copy(floating = floating)), aspect = ASPECT))
|
||||
measure(view)
|
||||
touch(MotionEvent.ACTION_DOWN, 3 to (230f to 300f))
|
||||
assertEquals(if (floating) 0f else .5f, state().leftX, .01f)
|
||||
assertEquals(if (floating) 0f else .5f, state().leftX, .001f)
|
||||
touch(MotionEvent.ACTION_UP, 3 to (230f to 300f))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun systemOnlyVisibilityMovesSteamAndQamToTheBottomCornersAndReleasesOtherButtons() {
|
||||
val guide = InputSurfaceElement(InputControl.GUIDE, .4f, .7f, .1f, .2f)
|
||||
view.updateLayout(SavedInputLayout("test", "Test", listOf(button, guide), aspect = ASPECT))
|
||||
measure(view)
|
||||
touch(MotionEvent.ACTION_DOWN, 0 to (800f to 250f))
|
||||
view.setButtonsOnly(true)
|
||||
measure(view)
|
||||
assertFalse(state().isDown(PadState.A))
|
||||
assertFalse(view.takesTouchAt(800f, 250f))
|
||||
assertFalse(view.takesTouchAt(450f, 480f))
|
||||
assertTrue(view.takesTouchAt(44f, 556f))
|
||||
assertTrue(view.takesTouchAt(956f, 556f))
|
||||
}
|
||||
|
||||
@Test fun aCancelledSecondFingerDoesNotArmAStickClick() {
|
||||
touch(MotionEvent.ACTION_DOWN, 7 to (800f to 250f))
|
||||
touch(MotionEvent.ACTION_POINTER_DOWN or (1 shl 8), 7 to (800f to 250f), 9 to (200f to 300f))
|
||||
@@ -170,111 +177,54 @@ class OnScreenControlsTest {
|
||||
assertFalse(state().isDown(PadState.L3))
|
||||
}
|
||||
|
||||
private val corner get() = 26 * context.resources.displayMetrics.density to 600 - 26 * context.resources.displayMetrics.density
|
||||
|
||||
private fun tapCorner() {
|
||||
val (x, y) = corner
|
||||
touch(MotionEvent.ACTION_DOWN, 1 to (x to y)); touch(MotionEvent.ACTION_UP, 1 to (x to y))
|
||||
shadowOf(Looper.getMainLooper()).idle()
|
||||
@Test fun theQuickToggleHidesEverythingButTheKeyboardAndShowsItAgain() {
|
||||
val keyboard = InputSurfaceElement(InputControl.A, .4f, .4f, .1f, .1f, "builtin:keyboard", name = "Keyboard")
|
||||
view.updateLayout(SavedInputLayout("test", "Test", listOf(left, button, keyboard), aspect = ASPECT))
|
||||
measure(view)
|
||||
}
|
||||
|
||||
@Test fun tappingTheCornerHidesTheControlsAndTappingAgainShowsThem() {
|
||||
val taps = mutableListOf<OnScreenControls.Hidden?>()
|
||||
view.onCornerTap = { taps += it }
|
||||
touch(MotionEvent.ACTION_DOWN, 4 to (800f to 250f))
|
||||
assertTrue(state().isDown(PadState.A))
|
||||
val (x, y) = corner
|
||||
assertTrue(view.cornerTakes(x, y))
|
||||
assertFalse(view.cornerTakes(800f, 250f))
|
||||
touch(MotionEvent.ACTION_POINTER_DOWN or (1 shl 8), 4 to (800f to 250f), 1 to (x to y))
|
||||
touch(MotionEvent.ACTION_POINTER_UP or (1 shl 8), 4 to (800f to 250f), 1 to (x to y))
|
||||
shadowOf(Looper.getMainLooper()).idle()
|
||||
measure(view)
|
||||
assertEquals(OnScreenControls.Hidden.BY_TAP, view.hidden)
|
||||
assertFalse(state().isDown(PadState.A))
|
||||
assertFalse(view.takesTouchAt(800f, 250f))
|
||||
val density = context.resources.displayMetrics.density
|
||||
val x = 34 * density
|
||||
val y = 600 - 34 * density
|
||||
assertTrue(view.takesTouchAt(x, y))
|
||||
touch(MotionEvent.ACTION_UP, 4 to (800f to 250f))
|
||||
tapCorner()
|
||||
assertNull(view.hidden)
|
||||
assertTrue(view.takesTouchAt(800f, 250f))
|
||||
assertEquals(listOf(OnScreenControls.Hidden.BY_TAP, null), taps)
|
||||
}
|
||||
|
||||
@Test fun holdingTheCornerOpensTheMenuOnLiftWithoutHiding() {
|
||||
var held = 0
|
||||
val taps = mutableListOf<OnScreenControls.Hidden?>()
|
||||
view.onCornerHold = { held++ }
|
||||
view.onCornerTap = { taps += it }
|
||||
val activity = Robolectric.buildActivity(ComponentActivity::class.java).setup().get()
|
||||
activity.setContentView(view, FrameLayout.LayoutParams(1000, 600))
|
||||
touch(MotionEvent.ACTION_UP, 4 to (x to y))
|
||||
touch(MotionEvent.ACTION_DOWN, 5 to (x to y)); touch(MotionEvent.ACTION_CANCEL, 5 to (x to y)); touch(MotionEvent.ACTION_UP, 5 to (x to y))
|
||||
assertFalse(view.isQuickHidden)
|
||||
touch(MotionEvent.ACTION_DOWN, 1 to (x to y)); touch(MotionEvent.ACTION_UP, 1 to (x to y))
|
||||
measure(view)
|
||||
val (x, y) = corner
|
||||
touch(MotionEvent.ACTION_DOWN, 1 to (x to y))
|
||||
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(ViewConfiguration.getLongPressTimeout() + 50L))
|
||||
assertEquals(0, held)
|
||||
touch(MotionEvent.ACTION_UP, 1 to (x to y))
|
||||
shadowOf(Looper.getMainLooper()).idle()
|
||||
assertEquals(1, held)
|
||||
assertNull(view.hidden)
|
||||
assertTrue(taps.isEmpty())
|
||||
touch(MotionEvent.ACTION_DOWN, 1 to (x to y))
|
||||
touch(MotionEvent.ACTION_CANCEL, 1 to (x to y))
|
||||
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(ViewConfiguration.getLongPressTimeout() + 50L))
|
||||
touch(MotionEvent.ACTION_UP, 1 to (x to y))
|
||||
shadowOf(Looper.getMainLooper()).idle()
|
||||
assertEquals(1, held)
|
||||
assertNull(view.hidden)
|
||||
assertTrue(taps.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun aControllerHideReleasesHeldControlsAndATapBringsThemBack() {
|
||||
touch(MotionEvent.ACTION_DOWN, 4 to (800f to 250f))
|
||||
view.setPresentation(OnScreenControls.Hidden.BY_CONTROLLER)
|
||||
measure(view)
|
||||
assertFalse(state().isDown(PadState.A))
|
||||
assertTrue(view.isQuickHidden)
|
||||
assertFalse(view.takesTouchAt(800f, 250f))
|
||||
touch(MotionEvent.ACTION_UP, 4 to (800f to 250f))
|
||||
tapCorner()
|
||||
assertNull(view.hidden)
|
||||
assertTrue(view.takesTouchAt(450f, 270f))
|
||||
touch(MotionEvent.ACTION_DOWN, 2 to (800f to 250f)); touch(MotionEvent.ACTION_UP, 2 to (800f to 250f))
|
||||
assertTrue(view.isQuickHidden)
|
||||
touch(MotionEvent.ACTION_DOWN, 3 to (x to y)); touch(MotionEvent.ACTION_UP, 3 to (x to y))
|
||||
measure(view)
|
||||
assertFalse(view.isQuickHidden)
|
||||
assertTrue(view.takesTouchAt(800f, 250f))
|
||||
}
|
||||
|
||||
@Test fun tappingTheCornerKeepsTheShortcutsMode() {
|
||||
fun shownIds() = view.inputSurface.shownElements.map { it.id }
|
||||
view.setPresentation(null, shortcuts = true)
|
||||
view.setButtonsOnly(true)
|
||||
measure(view)
|
||||
val shortcuts = listOf(OnScreenLayout.STEAM_SHORTCUT_ID, OnScreenLayout.QAM_SHORTCUT_ID)
|
||||
assertEquals(shortcuts, shownIds())
|
||||
tapCorner()
|
||||
assertTrue(shownIds().isEmpty())
|
||||
tapCorner()
|
||||
assertEquals(shortcuts, shownIds())
|
||||
touch(MotionEvent.ACTION_DOWN, 6 to (x to y)); touch(MotionEvent.ACTION_UP, 6 to (x to y))
|
||||
assertFalse(view.isQuickHidden)
|
||||
}
|
||||
|
||||
@Test fun theCornerIsGoneWithoutALayoutAndOnTheDockedStrip() {
|
||||
val (x, y) = corner
|
||||
view.updateLayout(null)
|
||||
@Test fun hidingTheGamepadKeepsAlwaysShownKeysDrawnAndTouchable() {
|
||||
val key = InputSurfaceElement(InputControl.A, .45f, .1f, .1f, .1f, "imported:0", name = "Find", alwaysShown = true)
|
||||
view.updateLayout(SavedInputLayout("test", "Test", listOf(left, button, key), aspect = ASPECT))
|
||||
measure(view)
|
||||
assertFalse(view.cornerTakes(x, y))
|
||||
assertFalse(view.takesTouchAt(x, y))
|
||||
val docked = OnScreenControls(context, bridge, OnScreenLayout.Dock(false, grips = true))
|
||||
docked.updateLayout(SavedInputLayout("test", "Test", listOf(button), aspect = ASPECT))
|
||||
measure(docked)
|
||||
assertFalse(docked.cornerTakes(x, y))
|
||||
docked.releaseAll()
|
||||
}
|
||||
|
||||
@Test fun switchingTheVirtualControllerRedrawsTheSameLayoutWithTheNewKit() {
|
||||
assertEquals(PadKit.STEAM_DECK, view.inputSurface.kit)
|
||||
SessionPrefs.setSteamController(context, SessionPrefs.CONTROLLER_DS4)
|
||||
assertTrue(view.hasPinned)
|
||||
view.setPinnedOnly(true)
|
||||
measure(view)
|
||||
assertTrue(view.takesTouchAt(500f, 90f))
|
||||
assertFalse(view.takesTouchAt(800f, 250f))
|
||||
assertFalse(view.takesTouchAt(200f, 300f))
|
||||
view.setPinnedOnly(false)
|
||||
measure(view)
|
||||
assertTrue(view.takesTouchAt(800f, 250f))
|
||||
assertTrue(view.takesTouchAt(500f, 90f))
|
||||
view.setQuickHidden(true)
|
||||
measure(view)
|
||||
assertTrue(view.takesTouchAt(500f, 90f))
|
||||
assertFalse(view.takesTouchAt(800f, 250f))
|
||||
view.updateLayout(SavedInputLayout("test", "Test", listOf(left, button), aspect = ASPECT))
|
||||
assertEquals(PadKit.DUALSHOCK, view.inputSurface.kit)
|
||||
SessionPrefs.setSteamController(context, SessionPrefs.CONTROLLER_XBOX360)
|
||||
view.reload()
|
||||
assertEquals(PadKit.XBOX, view.inputSurface.kit)
|
||||
SessionPrefs.setSteamController(context, SessionPrefs.CONTROLLER_DECK)
|
||||
assertFalse(view.hasPinned)
|
||||
}
|
||||
|
||||
private companion object { const val ASPECT = 1000f / 600f }
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.droiddeck.launcher.input
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Rect
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import org.json.JSONObject
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Before
|
||||
@@ -39,25 +38,37 @@ class OnScreenLayoutTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun steamShortcutsClearPinnedControlsAndStayInsideTheSafeArea() {
|
||||
val safe = Rect(20, 10, 30, 25)
|
||||
val pin = InputSurfaceElement(InputControl.A, .05f, .8f, .2f, .15f, "pin")
|
||||
val shortcuts = OnScreenLayout.steamShortcuts(1000, 600, safe, 2f, listOf(pin))
|
||||
val (steam, qam) = shortcuts
|
||||
assertEquals(OnScreenLayout.STEAM_SHORTCUT_ID, steam.id)
|
||||
assertEquals(OnScreenLayout.QAM_SHORTCUT_ID, qam.id)
|
||||
assertTrue(steam.y + steam.height < pin.y)
|
||||
assertEquals(OnScreenLayout.steamShortcuts(1000, 600, safe, 2f).last().y, qam.y)
|
||||
assertInside(shortcuts, 1000, 600, safe)
|
||||
@Test fun theBuiltInGamepadIsRegeneratedForEverySizeWithoutStretching() {
|
||||
val layout = gamepad()
|
||||
for ((w, h) in listOf(1200 to 540, 540 to 1200, 900 to 850)) {
|
||||
val placed = OnScreenLayout.elements(context, layout, w, h, Rect())
|
||||
assertEquals(layout.elements.map { it.id }, placed.map { it.id })
|
||||
assertEquals(LegacyGamepadLayout(context, w, h).regenerate(layout.elements), placed)
|
||||
for (id in listOf("legacy:a", "legacy:up", "legacy:guide")) assertSquare(placed.first { it.id == id }, w, h)
|
||||
assertInside(placed, w, h)
|
||||
}
|
||||
}
|
||||
|
||||
val tall = pin.copy(y = .1f, height = .85f)
|
||||
val beside = OnScreenLayout.steamShortcuts(1000, 600, safe, 2f, listOf(tall))
|
||||
assertEquals(2, beside.size)
|
||||
assertTrue(beside.first().x > tall.x + tall.width)
|
||||
assertInside(beside, 1000, 600, safe)
|
||||
@Test @Config(qualifiers = "w745dp-h343dp-land-420dpi")
|
||||
fun aBuiltInGamepadSavedAtTheDisplaySizeRegeneratesForTheMeasuredSurface() {
|
||||
val saved = gamepad().copy(elements = LegacyGamepadLayout(context, 2608, 1200).elements(), aspect = 2608f / 1200)
|
||||
val placed = OnScreenLayout.elements(context, saved, 2048, 1200, Rect())
|
||||
assertEquals(LegacyGamepadLayout(context, 2048, 1200).regenerate(saved.elements), placed)
|
||||
}
|
||||
|
||||
val cover = pin.copy(x = 0f, y = 0f, width = 1f, height = 1f)
|
||||
assertTrue(OnScreenLayout.steamShortcuts(1000, 600, safe, 2f, listOf(cover)).isEmpty())
|
||||
@Test @Config(qualifiers = "w745dp-h343dp-land-420dpi")
|
||||
fun previouslyGeneratedEdgeSticksRegenerateWithoutOverridingCustomGeometry() {
|
||||
val w = 2608
|
||||
val h = 1200
|
||||
ControllerPrefs.setLayout(context, w, h, mapOf("ls" to (0f to .5f), "rs" to (1f to .5f)))
|
||||
val generator = LegacyGamepadLayout(context, w, h)
|
||||
val old = generator.elements(previousStickGeometry = true)
|
||||
val current = generator.elements()
|
||||
assertTrue(old.filter { it.control == InputControl.LS || it.control == InputControl.RS }.zip(current.filter { it.control == InputControl.LS || it.control == InputControl.RS }).any { (a, b) -> kotlin.math.abs(a.width - b.width) > .01f })
|
||||
val saved = gamepad().copy(elements = old, aspect = w.toFloat() / h)
|
||||
assertEquals(LegacyGamepadLayout(context, 2048, h).regenerate(old), OnScreenLayout.elements(context, saved, 2048, h, Rect()))
|
||||
val custom = saved.copy(elements = old.map { if (it.id == "legacy:a") it.copy(x = .4f) else it })
|
||||
assertEquals(OnScreenLayout.fit(custom.elements, custom.aspect, 1f, 2048, h, Rect()), OnScreenLayout.elements(context, custom, 2048, h, Rect()))
|
||||
}
|
||||
|
||||
@Test fun savingTheEditorFrameKeepsEveryControlWhereTheEditorShowsIt() {
|
||||
@@ -79,27 +90,6 @@ class OnScreenLayoutTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun onlyAnUntouchedBuiltInGamepadOrACopyOfOneFollowsTheKit() {
|
||||
assertTrue(OnScreenLayout.generated(gamepad()))
|
||||
assertTrue(OnScreenLayout.generated(SavedInputLayout("copy", "Copy", origin = InputLibraries.OVERLAY)))
|
||||
assertFalse(OnScreenLayout.generated(SavedInputLayout("custom", "Custom")))
|
||||
assertFalse(OnScreenLayout.generated(SavedInputLayout("copy", "Copy", origin = InputLibraries.DECK)))
|
||||
val edited = gamepad().copy(elements = listOf(InputSurfaceElement(InputControl.A, .5f, .5f, .1f, .1f)), aspect = 2f)
|
||||
assertFalse(OnScreenLayout.generated(edited))
|
||||
assertEquals(listOf("legacy:a"), OnScreenLayout.elements(context, edited, 2000, 1000, Rect()).map { it.id })
|
||||
}
|
||||
|
||||
@Test fun theBuiltInGamepadFollowsTheVirtualControllersKitAndScale() {
|
||||
for ((type, kit) in listOf(SessionPrefs.CONTROLLER_DECK to PadKit.STEAM_DECK, SessionPrefs.CONTROLLER_XBOX360 to PadKit.XBOX,
|
||||
SessionPrefs.CONTROLLER_DUALSENSE to PadKit.DUALSENSE)) {
|
||||
SessionPrefs.setSteamController(context, type)
|
||||
val safe = Rect(40, 0, 20, 10)
|
||||
assertEquals(KitLayout.elements(context, kit, 2400, 1080, safe), OnScreenLayout.elements(context, gamepad(), 2400, 1080, safe))
|
||||
assertEquals(KitLayout.elements(context, kit, 2400, 1080, safe, 1.25f), OnScreenLayout.elements(context, gamepad().copy(scale = 1.25f), 2400, 1080, safe))
|
||||
}
|
||||
assertEquals(emptyList<InputSurfaceElement>(), OnScreenLayout.elements(context, null, 2400, 1080, Rect()))
|
||||
}
|
||||
|
||||
@Test fun editorAndGameUseTheSamePixelRectsOnWideAndStandardScreens() {
|
||||
val layout = gamepad()
|
||||
for ((w, h) in listOf(2000 to 900, 1600 to 900)) {
|
||||
@@ -115,7 +105,7 @@ class OnScreenLayoutTest {
|
||||
@Test fun editedGeneratedAndCustomLayoutsKeepTheirPixelRectsAcrossRefreshes() {
|
||||
for ((w, h) in listOf(2000 to 900, 1600 to 900)) {
|
||||
val generated = gamepad()
|
||||
val generatedEdit = KitLayout.elements(context, PadKit.current(context), w, h).map { if (it.id == "legacy:a") it.copy(x = .3f, y = .4f, width = .12f, height = .12f) else it }
|
||||
val generatedEdit = generated.elements.map { if (it.id == "legacy:a") it.copy(x = .3f, y = .4f, width = .12f, height = .12f) else it }
|
||||
val generatedSaved = generated.copy(elements = generatedEdit, aspect = w.toFloat() / h)
|
||||
val generatedPixels = px(OnScreenLayout.elements(context, generatedSaved, w, h, Rect()).first { it.id == "legacy:a" }, w, h)
|
||||
val generatedRefresh = px(OnScreenLayout.editorElements(context, generatedSaved, w, h, edited = true).first { it.id == "legacy:a" }, w, h)
|
||||
@@ -127,6 +117,25 @@ class OnScreenLayoutTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun resetPositionsRestoresGeneratedGeometryAfterAnEdit() {
|
||||
for ((w, h) in listOf(2000 to 900, 1600 to 900)) {
|
||||
val original = gamepad()
|
||||
val moved = original.copy(elements = original.elements.map { if (it.id == "legacy:a") it.copy(x = .3f) else it }, aspect = w.toFloat() / h)
|
||||
val reset = LegacyGamepadLayout(context, w, h).regenerate(moved.elements)
|
||||
assertEquals(LegacyGamepadLayout(context, w, h).regenerate(original.elements), OnScreenLayout.elements(context, moved.copy(elements = reset), w, h, Rect()))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun regenerationKeepsTheUsersButtonStylesAndRemovedButtons() {
|
||||
val layout = gamepad().let { g -> g.copy(elements = g.elements.filterNot { it.id == "legacy:y" }.map { if (it.id == "legacy:a") it.copy(opacity = .4f, icon = 0, name = "Jump") else it }) }
|
||||
val placed = OnScreenLayout.elements(context, layout, 2000, 1000, Rect())
|
||||
assertNull(placed.firstOrNull { it.id == "legacy:y" })
|
||||
val a = placed.first { it.id == "legacy:a" }
|
||||
assertEquals(.4f, a.opacity)
|
||||
assertEquals("Jump", a.name)
|
||||
assertEquals(LegacyGamepadLayout(context, 2000, 1000).elements().first { it.id == "legacy:a" }.x, a.x, .0001f)
|
||||
}
|
||||
|
||||
@Test fun anEditedLayoutKeepsItsAspectAndCornersWhenTheScreenRotates() {
|
||||
val corner = InputSurfaceElement(InputControl.A, .85f, .7f, .1f, .2f)
|
||||
val left = InputSurfaceElement(InputControl.LS, .05f, .5f, .2f, .4f)
|
||||
@@ -149,24 +158,6 @@ class OnScreenLayoutTest {
|
||||
|
||||
private fun round(v: Float) = Math.round(v * 10000f) / 10000f
|
||||
|
||||
@Test fun aNarrowLandscapeLayoutOnAWideLandscapeScreenKeepsItsEdgeAnchoring() {
|
||||
val right = InputSurfaceElement(InputControl.A, .9f, .4f, .06f, .08f, "a")
|
||||
val layout = SavedInputLayout("edited", "Edited", listOf(right), aspect = 4f / 3f)
|
||||
val (x, _, w, _) = px(OnScreenLayout.elements(context, layout, 2400, 1029, Rect()).single(), 2400, 1029).toList()
|
||||
assertEquals(2400f - .04f * 1029f * 4f / 3f, x + w, 1f)
|
||||
}
|
||||
|
||||
@Test fun aLandscapeLayoutShownInPortraitKeepsItsClustersTogetherAtTheBottom() {
|
||||
val y = InputSurfaceElement(InputControl.Y, .8f, .25f, .08f, .16f, "y")
|
||||
val a = InputSurfaceElement(InputControl.A, .8f, .6f, .08f, .16f, "a")
|
||||
val layout = SavedInputLayout("edited", "Edited", listOf(y, a), aspect = 2f)
|
||||
val (_, yTop, _, yHeight) = px(OnScreenLayout.elements(context, layout, 1000, 2000, Rect(0, 0, 0, 40)).single { it.id == "y" }, 1000, 2000).toList()
|
||||
val (_, aTop, _, _) = px(OnScreenLayout.elements(context, layout, 1000, 2000, Rect(0, 0, 0, 40)).single { it.id == "a" }, 1000, 2000).toList()
|
||||
assertEquals(.35f * 500f, aTop - yTop, 1f)
|
||||
assertEquals(2000f - 40f - .75f * 500f, yTop, 1f)
|
||||
assertEquals(.16f * 500f, yHeight, 1f)
|
||||
}
|
||||
|
||||
@Test fun controlsStayOutOfTheDisplayCutout() {
|
||||
val safe = Rect(120, 0, 0, 40)
|
||||
val generated = OnScreenLayout.elements(context, gamepad(), 2400, 1080, safe)
|
||||
@@ -176,12 +167,31 @@ class OnScreenLayoutTest {
|
||||
assertInside(OnScreenLayout.elements(context, edge, 2400, 1080, safe), 2400, 1080, safe)
|
||||
}
|
||||
|
||||
@Test fun steamAndQamOnlyModePutsLargeButtonsInTheBottomCornersAndTheKeyboardBetween() {
|
||||
val safe = Rect(80, 0, 30, 20)
|
||||
val placed = OnScreenLayout.elements(context, gamepad(), 1000, 500, safe, buttonsOnly = true)
|
||||
assertEquals(setOf(InputControl.GUIDE, InputControl.QAM, InputControl.A), placed.map { it.control }.toSet())
|
||||
val radius = 30 * density
|
||||
val inset = 44 * density
|
||||
fun centre(e: InputSurfaceElement) = (e.x + e.width / 2f) * 1000 to (e.y + e.height / 2f) * 500
|
||||
val guide = placed.first { it.control == InputControl.GUIDE }
|
||||
val qam = placed.first { it.control == InputControl.QAM }
|
||||
val keyboard = placed.first { it.id == "builtin:keyboard" }
|
||||
assertEquals(2 * radius, guide.width * 1000, .5f)
|
||||
assertEquals(80 + inset, centre(guide).first, .5f)
|
||||
assertEquals(500 - 20 - inset, centre(guide).second, .5f)
|
||||
assertEquals(1000 - 30 - inset, centre(qam).first, .5f)
|
||||
assertEquals(500f, centre(keyboard).first, .5f)
|
||||
assertEquals(500 - 20 - inset, centre(keyboard).second, .5f)
|
||||
val user = SavedInputLayout("edited", "Edited", listOf(InputSurfaceElement(InputControl.A, .5f, .5f, .1f, .1f)))
|
||||
assertEquals(setOf(InputControl.GUIDE, InputControl.QAM), OnScreenLayout.elements(context, user, 2000, 1000, Rect(), buttonsOnly = true).map { it.control }.toSet())
|
||||
}
|
||||
|
||||
@Test fun theUnfoldedStripUsesTheDockGeometryInLandscapeAndPortrait() {
|
||||
for ((size, portrait) in listOf((2208 to 800) to false, (1080 to 1300) to true)) {
|
||||
val (w, h) = size
|
||||
val placed = OnScreenLayout.elements(context, gamepad(), w, h, Rect(), dock = OnScreenLayout.Dock(portrait, grips = true))
|
||||
val steam = PadKit.current(context).steam
|
||||
val boxes = GamepadGeometry.layout(w.toFloat(), h.toFloat(), density, portrait, grips = steam, trackpads = steam)
|
||||
val boxes = GamepadGeometry.layout(w.toFloat(), h.toFloat(), density, portrait)
|
||||
val ls = placed.first { it.id == "legacy:ls" }
|
||||
val box = boxes.getValue(GamepadGeometry.Slot.LEFT_MAIN)
|
||||
assertEquals(box.left, ls.x * w, 1f)
|
||||
@@ -189,7 +199,7 @@ class OnScreenLayoutTest {
|
||||
assertEquals(box.height, ls.height * h, 1f)
|
||||
assertSquare(placed.first { it.id == "legacy:a" }, w, h)
|
||||
assertNull(placed.firstOrNull { it.control == InputControl.GUIDE || it.control == InputControl.QAM })
|
||||
assertEquals(steam && GamepadGeometry.Slot.L4 in boxes, placed.any { it.control == InputControl.L4 })
|
||||
assertEquals(portrait, placed.any { it.control == InputControl.L4 })
|
||||
assertInside(placed, w, h)
|
||||
val solid = placed.filter { it.kind != InputElementKind.STICK }
|
||||
for (a in solid) for (b in solid) if (a !== b) {
|
||||
@@ -223,15 +233,8 @@ class OnScreenLayoutTest {
|
||||
assertTrue(migrated.profiles.any { it.id == "migrated.screenkeys.0" })
|
||||
assertTrue(prefs.getBoolean(LegacyScreenKeyMigration.MERGED, false))
|
||||
assertEquals(migrated, InputLibraries.read(context))
|
||||
}
|
||||
|
||||
@Test fun migratedScreenKeysAreDrawnNextToTheKitGamepad() {
|
||||
prefs.edit().clear().commit()
|
||||
ControllerPrefs.prefs(context).edit().putString("screenKeys", legacyKeys).commit()
|
||||
val layout = InputLibraries.read(context).activeLayout(false, InputRole.PRIMARY)!!
|
||||
val placed = OnScreenLayout.elements(context, layout, 2400, 1080, Rect()).map { it.id }
|
||||
assertTrue(placed.contains("imported:0"))
|
||||
assertTrue(placed.containsAll(listOf("legacy:a", KitLayout.DPAD_ID, "legacy:ls")))
|
||||
val placed = OnScreenLayout.elements(context, layout, 2400, 1080, Rect())
|
||||
assertEquals(layout.elements.map { it.id }, placed.map { it.id })
|
||||
}
|
||||
|
||||
@Test fun librariesMigratedBeforeTheMergeGetTheirScreenKeysBackOnceWithoutLosingEdits() {
|
||||
@@ -263,6 +266,20 @@ class OnScreenLayoutTest {
|
||||
assertEquals(selected, LegacyScreenKeyMigration.merge(selected, shown))
|
||||
}
|
||||
|
||||
@Test fun alwaysShownKeysStayInButtonsOnlyModeAndLeaveTheUnfoldedStrip() {
|
||||
val key = InputSurfaceElement(InputControl.A, .45f, .1f, .1f, .1f, "imported:0", name = "Find", alwaysShown = true)
|
||||
val plain = InputSurfaceElement(InputControl.A, .45f, .4f, .1f, .1f, "imported:1", name = "Jump")
|
||||
val layout = gamepad().let { it.copy(elements = it.elements + key + plain) }
|
||||
val buttons = OnScreenLayout.elements(context, layout, 1000, 500, Rect(), buttonsOnly = true)
|
||||
assertTrue(buttons.any { it.id == key.id })
|
||||
assertFalse(buttons.any { it.id == plain.id })
|
||||
assertEquals(OnScreenLayout.elements(context, gamepad(), 1000, 500, Rect(), buttonsOnly = true), buttons.filterNot { it.id == key.id })
|
||||
val strip = OnScreenLayout.elements(context, layout, 2208, 800, Rect(), dock = OnScreenLayout.Dock(false, grips = false))
|
||||
assertFalse(strip.any { it.id == key.id })
|
||||
assertTrue(strip.any { it.id == plain.id })
|
||||
assertTrue(OnScreenLayout.elements(context, layout, 1000, 500, Rect()).map { it.id }.containsAll(listOf(key.id, plain.id)))
|
||||
}
|
||||
|
||||
@Test fun migratedScreenKeysAreAlwaysShownButOtherElementsAreNot() {
|
||||
prefs.edit().clear().commit()
|
||||
ControllerPrefs.prefs(context).edit().putString("screenKeys", legacyKeys).commit()
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.content.Context
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import org.junit.After
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [34], manifest = Config.NONE)
|
||||
class PadKitTest {
|
||||
private val context: Context get() = RuntimeEnvironment.getApplication()
|
||||
@After fun reset() { context.getSharedPreferences("session", Context.MODE_PRIVATE).edit().clear().commit() }
|
||||
|
||||
@Test fun eachVirtualControllerGetsItsOwnKit() {
|
||||
assertEquals(PadKit.STEAM_DECK, PadKit.of(SessionPrefs.CONTROLLER_DECK))
|
||||
assertEquals(PadKit.STEAM_CONTROLLER, PadKit.of(SessionPrefs.CONTROLLER_STEAM))
|
||||
assertEquals(PadKit.XBOX, PadKit.of(SessionPrefs.CONTROLLER_XBOX360))
|
||||
assertEquals(PadKit.DUALSHOCK, PadKit.of(SessionPrefs.CONTROLLER_DS4))
|
||||
assertEquals(PadKit.DUALSENSE, PadKit.of(SessionPrefs.CONTROLLER_DUALSENSE))
|
||||
assertEquals(PadKit.STEAM_DECK, PadKit.of(SessionPrefs.CONTROLLER_NONE))
|
||||
assertEquals(PadKit.STEAM_DECK, PadKit.of("switchpro"))
|
||||
}
|
||||
|
||||
@Test fun theKitFollowsTheChosenVirtualController() {
|
||||
assertEquals(PadKit.STEAM_DECK, PadKit.current(context))
|
||||
SessionPrefs.setSteamController(context, SessionPrefs.CONTROLLER_DUALSENSE)
|
||||
assertEquals(PadKit.DUALSENSE, PadKit.current(context))
|
||||
}
|
||||
|
||||
@Test fun steamAndPlayStationKitsAreGroupedForTheirLayouts() {
|
||||
assertEquals(setOf(PadKit.STEAM_DECK, PadKit.STEAM_CONTROLLER), PadKit.entries.filter { it.steam }.toSet())
|
||||
assertEquals(setOf(PadKit.DUALSHOCK, PadKit.DUALSENSE), PadKit.entries.filter { it.playStation }.toSet())
|
||||
assertFalse(PadKit.XBOX.steam || PadKit.XBOX.playStation)
|
||||
}
|
||||
|
||||
@Test fun faceGlyphsMatchTheRealControllers() {
|
||||
assertEquals(FaceGlyphs.MONO_LETTERS, PadKit.STEAM_DECK.face)
|
||||
assertEquals(FaceGlyphs.MONO_LETTERS, PadKit.STEAM_CONTROLLER.face)
|
||||
assertEquals(FaceGlyphs.COLOR_LETTERS, PadKit.XBOX.face)
|
||||
assertEquals(FaceGlyphs.COLOR_SYMBOLS, PadKit.DUALSHOCK.face)
|
||||
assertEquals(FaceGlyphs.MONO_SYMBOLS, PadKit.DUALSENSE.face)
|
||||
assertEquals(DpadStyle.ARROWS, PadKit.DUALSHOCK.dpad)
|
||||
assertEquals(DpadStyle.ARROWS, PadKit.DUALSENSE.dpad)
|
||||
}
|
||||
|
||||
@Test fun onlyXboxNamesItsShouldersBumpersAndTriggers() {
|
||||
val shoulders = listOf(InputControl.LB, InputControl.RB, InputControl.LT, InputControl.RT)
|
||||
assertEquals(listOf("LB", "RB", "LT", "RT"), shoulders.map(PadKit.XBOX::label))
|
||||
for (kit in PadKit.entries - PadKit.XBOX) assertEquals(kit.name, listOf("L1", "R1", "L2", "R2"), shoulders.map(kit::label))
|
||||
for (kit in PadKit.entries) assertEquals(InputControl.A.label, kit.label(InputControl.A))
|
||||
}
|
||||
|
||||
@Test fun playStationFaceButtonsAreNamedByTheirSymbols() {
|
||||
val face = listOf(InputControl.A, InputControl.B, InputControl.X, InputControl.Y)
|
||||
for (kit in listOf(PadKit.DUALSHOCK, PadKit.DUALSENSE)) {
|
||||
assertEquals(kit.name, listOf("Cross", "Circle", "Square", "Triangle"), face.map(kit::name))
|
||||
assertEquals("L1", kit.name(InputControl.LB))
|
||||
val elements = KitLayout.elements(context, kit, 1920, 1080).associateBy { it.id }
|
||||
assertEquals("Triangle", elements.getValue("legacy:y").name)
|
||||
assertEquals("Cross", elements.getValue("legacy:a").name)
|
||||
}
|
||||
for (kit in listOf(PadKit.STEAM_DECK, PadKit.STEAM_CONTROLLER, PadKit.XBOX)) {
|
||||
assertEquals(kit.name, face.map { it.label }, face.map(kit::name))
|
||||
assertEquals(kit.label(InputControl.LT), kit.name(InputControl.LT))
|
||||
assertEquals(InputControl.Y.label, KitLayout.elements(context, kit, 1920, 1080).single { it.id == "legacy:y" }.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,8 +24,7 @@ class PhysicalInputBindingsTest {
|
||||
override fun command(command: InputCommand) { events += command.name }
|
||||
override fun requestMotion() {}
|
||||
})
|
||||
private val presses = ArrayList<Int>()
|
||||
private val bindings = PhysicalInputBindings(router) { presses += it.deviceId }
|
||||
private val bindings = PhysicalInputBindings(router)
|
||||
|
||||
private fun device(id: Int): InputDevice {
|
||||
val device = InputDeviceBuilder.newBuilder().setId(id).setName("Thor extra keys").setDescriptor("keys-$id")
|
||||
@@ -56,7 +55,6 @@ class PhysicalInputBindingsTest {
|
||||
assertEquals(listOf("29 true", "30 true", "30 false", "29 false"), events)
|
||||
bindings.onKey(event(device.id, true), true)
|
||||
assertEquals("28 true", events.last())
|
||||
assertEquals(listOf(device.id, device.id), presses)
|
||||
}
|
||||
|
||||
@Test fun releasesRemainConsumedAfterOpeningMenuAndVirtualKeysAreUntouched() {
|
||||
|
||||
@@ -177,8 +177,8 @@ class PhysicalShortcutsTest {
|
||||
}
|
||||
|
||||
@Test fun resetAndRemovalPreserveOtherControllerSettings() {
|
||||
LegacyControllerPrefs.setSelectSteam(context, true)
|
||||
LegacyControllerPrefs.setTarget(context, "a", "b")
|
||||
ControllerPrefs.setSelectSteam(context, true)
|
||||
ControllerPrefs.setTarget(context, "a", "b")
|
||||
assign(key(), Action.STEAM)
|
||||
assign(key(KeyEvent.KEYCODE_BUTTON_2), Action.QAM)
|
||||
PhysicalShortcuts.remove(context, PhysicalShortcuts.read(context).first())
|
||||
@@ -186,7 +186,7 @@ class PhysicalShortcutsTest {
|
||||
PhysicalShortcuts.remove(context, PhysicalShortcuts.read(context).single())
|
||||
assertTrue(PhysicalShortcuts.read(context).isEmpty())
|
||||
assertTrue(ControllerPrefs.read(context).selectSteam)
|
||||
assertEquals("b", LegacyControllerPrefs.target(context, "a"))
|
||||
assertEquals("b", ControllerPrefs.target(context, "a"))
|
||||
assign(key(), Action.STEAM)
|
||||
ControllerPrefs.resetAll(context)
|
||||
assertTrue(PhysicalShortcuts.read(context).isEmpty())
|
||||
|
||||
@@ -36,7 +36,7 @@ class SelectProfileRoutingTest {
|
||||
@Before fun setUp() {
|
||||
context.getSharedPreferences("input-profiles", 0).edit().clear().commit()
|
||||
context.getSharedPreferences("controller", 0).edit().clear().commit()
|
||||
LegacyControllerPrefs.setSelectSteam(context, true)
|
||||
ControllerPrefs.setSelectSteam(context, true)
|
||||
shadowOf(context.getSystemService(InputManager::class.java)).addInputDevice(device)
|
||||
bridge.setInputRouter(InputRouter(output))
|
||||
bridge.setInputProfile(InputProfiles.active(context, desktop = false))
|
||||
|
||||
@@ -80,8 +80,7 @@ class SessionKeyboardPadTest {
|
||||
ReflectionHelpers.setField(activity, "steamTouchOptions",
|
||||
SteamTouchConfig.Options(inputMode = SteamTouchConfig.INPUT_CONTROLLER))
|
||||
SessionPrefs.setTouchMode(activity, SessionPrefs.TOUCH_DIRECT)
|
||||
SessionPrefs.setOscMode(activity, SessionPrefs.OSC_ALWAYS)
|
||||
SessionPrefs.setSteamTouchLayout(activity, true)
|
||||
SessionPrefs.setOscMode(activity, SessionPrefs.OSC_STEAM_TOUCH)
|
||||
update()
|
||||
assertEquals(View.VISIBLE, steam.visibility)
|
||||
assertEquals(SessionPrefs.TOUCH_OFF, routedTouchMode())
|
||||
@@ -96,22 +95,6 @@ class SessionKeyboardPadTest {
|
||||
assertEquals(SessionPrefs.TOUCH_OFF, routedTouchMode())
|
||||
}
|
||||
|
||||
@Test fun hidingTheSteamLayoutForAControllerKeepsSteamsTouchControllerPlugged() {
|
||||
SteamTouchDevice.prepare(directory)
|
||||
val steam = SteamTouchControls(activity, SteamTouchDevice.current!!, {}, {})
|
||||
ReflectionHelpers.setField(activity, "steamTouchControls", steam)
|
||||
SessionPrefs.setOscMode(activity, SessionPrefs.OSC_AUTO)
|
||||
SessionPrefs.setSteamTouchLayout(activity, true)
|
||||
ReflectionHelpers.setField(activity, "controlsHiddenByTap", true)
|
||||
update()
|
||||
assertEquals(View.GONE, steam.visibility)
|
||||
assertTrue(SteamTouchDevice.current!!.plugged)
|
||||
ReflectionHelpers.setField(activity, "controlsHiddenByTap", false)
|
||||
update()
|
||||
assertEquals(View.VISIBLE, steam.visibility)
|
||||
assertTrue(SteamTouchDevice.current!!.plugged)
|
||||
}
|
||||
|
||||
@Test fun endingTheAgentForgetsSteamsKeyboard() {
|
||||
steamKeyboard(true)
|
||||
AgentGuest.stop()
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import com.droiddeck.launcher.ui.InputSurfaceView
|
||||
import org.junit.After
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [34], manifest = Config.NONE, qualifiers = "w833dp-h468dp-land-369dpi")
|
||||
class ShowLayoutTest {
|
||||
private val context: Context get() = RuntimeEnvironment.getApplication()
|
||||
@After fun close() { context.getSharedPreferences("session", Context.MODE_PRIVATE).edit().clear().commit() }
|
||||
|
||||
private fun sized(view: View, w: Int, h: Int) {
|
||||
view.measure(View.MeasureSpec.makeMeasureSpec(w, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(h, View.MeasureSpec.EXACTLY))
|
||||
view.layout(0, 0, w, h)
|
||||
}
|
||||
|
||||
@Test fun aGeneratedLayoutIsDrawnFromTheKitAtTheViewSize() {
|
||||
SessionPrefs.setSteamController(context, SessionPrefs.CONTROLLER_XBOX360)
|
||||
val view = InputSurfaceView(context)
|
||||
sized(view, 1240, 1080)
|
||||
view.showLayout(SavedInputLayout(InputLibraries.OVERLAY, "Gamepad"))
|
||||
assertEquals(KitLayout.elements(context, PadKit.XBOX, 1240, 1080), view.shownElements)
|
||||
view.releaseInputs()
|
||||
}
|
||||
|
||||
@Test fun overlayExtrasAreIndependentAndKeepTheirPreferencesWhenRecreated() {
|
||||
SessionPrefs.setSteamController(context, SessionPrefs.CONTROLLER_DECK)
|
||||
val kit = SavedInputLayout(InputLibraries.OVERLAY, "Gamepad")
|
||||
val grips = setOf(InputControl.L4, InputControl.L5, InputControl.R4, InputControl.R5)
|
||||
val trackpads = setOf(InputControl.LEFT_PAD, InputControl.RIGHT_PAD)
|
||||
fun controls(dock: OnScreenLayout.Dock? = null, layout: SavedInputLayout = kit): OnScreenControls =
|
||||
OnScreenControls(context, null, dock).also { it.updateLayout(layout); sized(it, 1920, 1080) }
|
||||
fun shown(view: OnScreenControls) = view.inputSurface.shownElements.map { it.control }.toSet()
|
||||
val overlay = controls()
|
||||
assertTrue(shown(overlay).intersect(grips + trackpads).isEmpty())
|
||||
SessionPrefs.setOscRearButtons(context, true)
|
||||
overlay.reload()
|
||||
assertTrue(shown(overlay).containsAll(grips))
|
||||
assertTrue(shown(overlay).intersect(trackpads).isEmpty())
|
||||
SessionPrefs.setOscTrackpads(context, true)
|
||||
SessionPrefs.setOscRearButtons(context, false)
|
||||
assertTrue(shown(controls()).containsAll(trackpads))
|
||||
assertTrue(shown(controls()).intersect(grips).isEmpty())
|
||||
|
||||
SessionPrefs.setOscTrackpads(context, false)
|
||||
val customPad = InputSurfaceElement(InputControl.LEFT_PAD, .4f, .4f, .15f, .15f, id = "custom-pad")
|
||||
val edited = kit.copy(elements = listOf(customPad,
|
||||
InputSurfaceElement(InputControl.RIGHT_PAD, .6f, .4f, .15f, .15f, id = "legacy:right-pad")))
|
||||
assertEquals(listOf(customPad.id), controls(layout = edited).inputSurface.shownElements.map { it.id })
|
||||
|
||||
val dock = OnScreenLayout.Dock(portrait = true, grips = true)
|
||||
val panel = OnScreenControls(context, null, dock).also { it.updateLayout(kit); sized(it, 1080, 1300) }
|
||||
assertTrue(shown(panel).containsAll(grips + trackpads))
|
||||
}
|
||||
|
||||
@Test fun aSavedLayoutIsDrawnAsSaved() {
|
||||
val saved = listOf(InputSurfaceElement(InputControl.A, .4f, .4f, .1f, .1f))
|
||||
val view = InputSurfaceView(context)
|
||||
sized(view, 1240, 1080)
|
||||
view.showLayout(SavedInputLayout("mine", "Mine", saved))
|
||||
assertEquals(saved, view.shownElements)
|
||||
view.showLayout(null)
|
||||
assertTrue(view.shownElements.isEmpty())
|
||||
view.releaseInputs()
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,6 @@ import java.util.UUID
|
||||
@Config(sdk = [34], manifest = Config.NONE, shadows = [SteamControllerBleTest.Writer::class])
|
||||
class SteamControllerBleTest {
|
||||
private val keys = ArrayList<Pair<Int, Boolean>>()
|
||||
private var presses = 0
|
||||
private val router = InputRouter(object : InputOutput {
|
||||
override fun key(code: Int, down: Boolean) { keys += code to down }
|
||||
override fun button(code: Int, down: Boolean) {}
|
||||
@@ -43,7 +42,7 @@ class SteamControllerBleTest {
|
||||
Writer.features = 0
|
||||
router.setProfile(InputProfile.defaults(InputProfile.GAME)
|
||||
.withBinding(InputRole.PHYSICAL, InputControl.A, InputAction.Keys(listOf(57))))
|
||||
controller = SteamControllerBle(RuntimeEnvironment.getApplication(), router) { presses++ }
|
||||
controller = SteamControllerBle(RuntimeEnvironment.getApplication(), router)
|
||||
handler = ReflectionHelpers.getField(controller, "handler")
|
||||
shadowOf(handler.looper).pause()
|
||||
controller.start()
|
||||
@@ -61,23 +60,6 @@ class SteamControllerBleTest {
|
||||
drain(handler.looper)
|
||||
}
|
||||
|
||||
@Test fun newInputNotifiesOncePerPressOrStickDeflection() {
|
||||
subscribe(controller)
|
||||
val held = ByteArray(45).apply { this[1] = 1 }
|
||||
val stick = held.copyOf().apply { this[10] = 80 }
|
||||
state(ByteArray(45))
|
||||
assertEquals(0, presses)
|
||||
state(held)
|
||||
state(held)
|
||||
assertEquals(1, presses)
|
||||
state(stick)
|
||||
state(stick)
|
||||
assertEquals(2, presses)
|
||||
state(ByteArray(45))
|
||||
state(held)
|
||||
assertEquals(3, presses)
|
||||
}
|
||||
|
||||
@Test fun stopReleasesAndDetachesInputBeforeQueuedCallbacksCanPublish() {
|
||||
state(ByteArray(45).apply { this[1] = 1 })
|
||||
assertEquals(listOf(57 to true), keys)
|
||||
|
||||
@@ -61,7 +61,7 @@ class StickDeadZoneTest {
|
||||
val button = PhysicalShortcuts.Button("test-pad", "Test pad", KeyEvent.KEYCODE_BUTTON_MODE, 0)
|
||||
val binding = PhysicalShortcuts.Binding(button, PhysicalShortcuts.Action.QAM)
|
||||
PhysicalShortcuts.assign(context, button, binding.action)
|
||||
LegacyControllerPrefs.setTarget(context, "a", "b")
|
||||
ControllerPrefs.setTarget(context, "a", "b")
|
||||
ControllerPrefs.setRumble(context, false)
|
||||
for (percent in ControllerPrefs.deadZones) {
|
||||
ControllerPrefs.setDeadZone(context, percent)
|
||||
@@ -395,22 +395,27 @@ class StickDeadZoneTest {
|
||||
@Test fun neutralScreenStickPressClearsRetainedPhysicalInput() {
|
||||
val device = device()
|
||||
for (adaptive in listOf(false, true)) {
|
||||
ControllerPrefs.setAdaptiveSticks(context, adaptive)
|
||||
ControllerPrefs.setLayout(context, 1200, 800, mapOf("ls" to (0.45f to 0.5f), "rs" to (0.55f to 0.5f)))
|
||||
for (id in listOf("ls", "rs")) {
|
||||
motion(device, MotionEvent.AXIS_X to 0.6f, MotionEvent.AXIS_Z to 0.7f)
|
||||
val view = OnScreenControls(context, bridge)
|
||||
val elements = KitLayout.elements(context, PadKit.STEAM_DECK, 1200, 800).map { if (it.kind == InputElementKind.STICK) it.copy(floating = adaptive) else it }
|
||||
view.updateLayout(SavedInputLayout("test", "Test", elements, aspect = 1200f / 800f))
|
||||
val elements = LegacyGamepadLayout(context, 1200, 800).elements()
|
||||
view.updateLayout(SavedInputLayout("test", "Test", elements))
|
||||
view.measure(android.view.View.MeasureSpec.makeMeasureSpec(1200, android.view.View.MeasureSpec.EXACTLY), android.view.View.MeasureSpec.makeMeasureSpec(800, android.view.View.MeasureSpec.EXACTLY))
|
||||
view.layout(0, 0, 1200, 800)
|
||||
val control = elements.first { it.id == "legacy:$id" }
|
||||
val x = (control.x + control.width / 2) * 1200
|
||||
val y = (control.y + control.height / 2) * 800
|
||||
val control = elements.first { it.control.id == id }
|
||||
val left = (control.x * 1200).toInt()
|
||||
val top = (control.y * 800).toInt()
|
||||
val height = (control.height * 800).toInt()
|
||||
val x = left + if (id == "ls") (control.width * 1200).toInt() - height / 2f else height / 2f
|
||||
val y = top + height / 2f
|
||||
val down = MotionEvent.obtain(1000, 1000, MotionEvent.ACTION_DOWN, x, y, 0)
|
||||
try { assertTrue(view.dispatchTouchEvent(down)) } finally { down.recycle() }
|
||||
assertEquals(0f, if (id == "ls") pad().leftX else pad().rightX, .05f)
|
||||
assertEquals(0f, if (id == "ls") pad().leftX else pad().rightX, 0f)
|
||||
assertTrue((if (id == "ls") pad().rightX else pad().leftX) > 0f)
|
||||
bridge.setStickDeadZone(25)
|
||||
assertEquals(0f, if (id == "ls") pad().leftX else pad().rightX, .05f)
|
||||
assertEquals(0f, if (id == "ls") pad().leftX else pad().rightX, 0f)
|
||||
motion(device, MotionEvent.AXIS_X to 0.6f, MotionEvent.AXIS_Z to 0.7f)
|
||||
val button = elements.first { it.control == InputControl.A }
|
||||
val bx = (button.x + button.width / 2) * 1200
|
||||
|
||||
@@ -29,6 +29,16 @@ class SessionBackgroundPrefsTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun steamAndQuickAccessFallsBackToAutoOutsideSteam() {
|
||||
SessionPrefs.setOscMode(context, SessionPrefs.OSC_STEAM_QAM)
|
||||
assertEquals(SessionPrefs.OSC_AUTO, SessionPrefs.oscMode(context, steamSession = false))
|
||||
assertEquals(SessionPrefs.OSC_STEAM_QAM, SessionPrefs.oscMode(context))
|
||||
assertEquals(SessionPrefs.OSC_STEAM_QAM, SessionPrefs.oscMode(context, steamSession = true))
|
||||
|
||||
SessionPrefs.setOscMode(context, SessionPrefs.OSC_ALWAYS)
|
||||
assertEquals(SessionPrefs.OSC_ALWAYS, SessionPrefs.oscMode(context, steamSession = false))
|
||||
}
|
||||
|
||||
@Test fun automaticPipDefaultsOnAndHonorsSavedChoices() {
|
||||
assertEquals(true, SessionPrefs.pipAutoEnter(context))
|
||||
SessionPrefs.setPipAutoEnter(context, false)
|
||||
|
||||
@@ -60,20 +60,6 @@ class SessionDisplayTest {
|
||||
assertEquals(864, SessionDisplay.unfoldedGameHeight(1920, 1080))
|
||||
}
|
||||
|
||||
@Test fun unfoldedControlsFitTheGamesOwnAspectUnderTheCap() {
|
||||
assertEquals(810, SessionDisplay.unfoldedGameHeight(1080, 1920, aspect = 4f / 3f))
|
||||
assertEquals(606, SessionDisplay.unfoldedGameHeight(1080, 1920, aspect = 16f / 9f))
|
||||
assertEquals((1920 * SessionDisplay.UNFOLDED_MAX_GAME_SHARE).toInt() and 1.inv(), SessionDisplay.unfoldedGameHeight(1080, 1920, aspect = 9f / 16f))
|
||||
assertEquals(SessionDisplay.unfoldedGameHeight(1080, 1920, aspect = .5f), SessionDisplay.unfoldedGameHeight(1080, 1920, aspect = .1f))
|
||||
assertEquals(810, SessionDisplay.unfoldedGameHeight(1080, 1920, 136, aspect = 4f / 3f))
|
||||
assertEquals(1240, SessionDisplay.unfoldedGameHeight(2448, 1848, 136, aspect = 16f / 9f))
|
||||
}
|
||||
|
||||
@Test fun aTallScreenTakesTheTabRowFromTheControlsSoTheGameKeepsTheFullWidth() {
|
||||
assertEquals(606, SessionDisplay.unfoldedGameHeight(1080, 1920, 146))
|
||||
assertEquals(1080, SessionDisplay.unfoldedGameHeight(1080, 2400, 146, aspect = 1f))
|
||||
}
|
||||
|
||||
@Test fun aTabRowUnderTheBarComesOutOfTheGameNotTheControls() {
|
||||
assertEquals(1376, SessionDisplay.unfoldedGameHeight(2448, 1848, 0))
|
||||
assertEquals(1240, SessionDisplay.unfoldedGameHeight(2448, 1848, 136))
|
||||
|
||||
@@ -9,7 +9,6 @@ import com.droiddeck.launcher.input.InputControl
|
||||
import com.droiddeck.launcher.input.InputProfile
|
||||
import com.droiddeck.launcher.input.InputProfiles
|
||||
import com.droiddeck.launcher.input.InputRole
|
||||
import com.droiddeck.launcher.input.LegacyControllerPrefs
|
||||
import com.droiddeck.launcher.input.InputSurfaceLayout
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Before
|
||||
@@ -53,7 +52,7 @@ class SettingsResetTest {
|
||||
SessionPrefs.setHudOpacity(app, 40)
|
||||
SessionPrefs.setDroidDeckHudConfig(app, "hudSize=mega,showFPSGraph=0")
|
||||
SessionPrefs.setDroidDeckHudPosition(app, 120f, 40f)
|
||||
LegacyControllerPrefs.setOpacity(app, 40)
|
||||
ControllerPrefs.setOpacity(app, 40)
|
||||
AppUiPrefs.setScale(app, 150)
|
||||
FrameGen.set(app, FrameGen.Mode(FrameGen.ENGINE_DDFG, 3))
|
||||
prefs("steam_touch").edit().putBoolean("gyro", false).commit()
|
||||
@@ -155,7 +154,7 @@ class SettingsResetTest {
|
||||
val defaultGame = InputProfiles.read(app, InputProfile.GAME)
|
||||
val defaultDesktop = InputProfiles.read(app, InputProfile.DESKTOP)
|
||||
val defaultSurface = InputSurfaceLayout.read(app, InputProfile.DESKTOP)
|
||||
LegacyControllerPrefs.setTarget(app, "a", "b")
|
||||
ControllerPrefs.setTarget(app, "a", "b")
|
||||
InputProfiles.select(app, InputProfile.DESKTOP)
|
||||
InputProfiles.save(app, InputProfile.defaults(InputProfile.GAME)
|
||||
.withBinding(InputRole.PHYSICAL, InputControl.A, InputAction.Disabled))
|
||||
|
||||
@@ -33,12 +33,12 @@ class GamepadGeometryTest {
|
||||
private val grips = setOf(Slot.L4, Slot.L5, Slot.R5, Slot.R4)
|
||||
private val portraitPanels get() = panels.take(3) + Panel("312dp phone portrait", 720, 1280, 369 / 160f)
|
||||
private fun portraitBoxes(panel: Panel) =
|
||||
GamepadGeometry.layout(panel.width.toFloat(), panel.controlsHeight.toFloat(), panel.density, portraitDock = true, grips = true)
|
||||
GamepadGeometry.layout(panel.width.toFloat(), panel.controlsHeight.toFloat(), panel.density, portraitDock = true)
|
||||
|
||||
@Test fun everyControlIsPlacedAndPanelsOnlyWhenUpright() {
|
||||
for (panel in panels) {
|
||||
val upright = panel.height > panel.width
|
||||
val expected = Slot.values().toSet() - grips - setOf(Slot.LEFT_TOUCH, Slot.RIGHT_TOUCH) - if (upright) emptySet() else setOf(Slot.PANELS)
|
||||
val expected = Slot.values().toSet() - grips - if (upright) emptySet() else setOf(Slot.PANELS)
|
||||
assertEquals(panel.name, expected, boxes(panel).keys)
|
||||
}
|
||||
}
|
||||
@@ -94,7 +94,7 @@ class GamepadGeometryTest {
|
||||
@Test fun portraitDockPlacesAllControlsWithinThePanel() {
|
||||
for (panel in portraitPanels) {
|
||||
val b = portraitBoxes(panel)
|
||||
assertEquals(panel.name, Slot.values().toSet() - setOf(Slot.STEAM, Slot.QAM, Slot.PANELS, Slot.LEFT_TOUCH, Slot.RIGHT_TOUCH), b.keys)
|
||||
assertEquals(panel.name, Slot.values().toSet(), b.keys)
|
||||
for ((slot, box) in b) {
|
||||
val where = "${panel.name}: $slot $box"
|
||||
assertTrue(where, box.left >= 0f && box.top >= 0f)
|
||||
@@ -126,70 +126,20 @@ class GamepadGeometryTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun portraitDockPutsShouldersAndMenusInOneRowAboveTheGripsAndTheGamepad() {
|
||||
@Test fun portraitDockMovesUtilitiesAndGripsAboveTheGamepad() {
|
||||
for (panel in portraitPanels) {
|
||||
val b = portraitBoxes(panel)
|
||||
val row = listOf(Slot.LEFT_OUTER_SHOULDER, Slot.LEFT_INNER_SHOULDER, Slot.VIEW, Slot.MENU, Slot.RIGHT_INNER_SHOULDER, Slot.RIGHT_OUTER_SHOULDER)
|
||||
for (slot in row) assertEquals("${panel.name}: $slot", 8 * panel.density, b.getValue(slot).top, 0.5f)
|
||||
assertEquals(panel.name, row, row.sortedBy { b.getValue(it).cx })
|
||||
assertEquals(panel.name, 8 * panel.density, b.getValue(Slot.VIEW).top, 0.5f)
|
||||
assertTrue(panel.name, b.getValue(Slot.MENU).bottom < b.getValue(Slot.L4).top)
|
||||
assertTrue(panel.name, b.getValue(Slot.L4).bottom < b.getValue(Slot.LEFT_SECOND).top)
|
||||
assertTrue(panel.name, b.getValue(Slot.LEFT_SECOND).bottom < b.getValue(Slot.LEFT_MAIN).top)
|
||||
assertTrue(panel.name, b.getValue(Slot.L4).bottom < b.getValue(Slot.LEFT_OUTER_SHOULDER).top)
|
||||
assertTrue(panel.name, b.getValue(Slot.LEFT_OUTER_SHOULDER).bottom < b.getValue(Slot.LEFT_SECOND).top)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun aPortraitDockWithoutGripsGivesTheirRowToTheGamepad() {
|
||||
for (panel in portraitPanels) {
|
||||
val with = portraitBoxes(panel)
|
||||
val without = GamepadGeometry.layout(panel.width.toFloat(), panel.controlsHeight.toFloat(), panel.density, portraitDock = true, grips = false)
|
||||
assertTrue(panel.name, grips.none { it in without })
|
||||
assertTrue(panel.name, without.getValue(Slot.LEFT_SECOND).top < with.getValue(Slot.LEFT_SECOND).top)
|
||||
assertTrue(panel.name, without.getValue(Slot.LEFT_SECOND).width >= with.getValue(Slot.LEFT_SECOND).width)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun aShorterPortraitDockStillGetsTheUprightLayout() {
|
||||
val (w, h, density) = Triple(1080f, 1010f, 369 / 160f)
|
||||
val b = GamepadGeometry.layout(w, h, density, portraitDock = true, grips = false)
|
||||
assertEquals(8 * density, b.getValue(Slot.VIEW).top, 0.5f)
|
||||
assertTrue(b.getValue(Slot.RIGHT_SECOND).width >= w * 0.3f)
|
||||
}
|
||||
|
||||
@Test fun shortPanelsKeepTheExistingLayoutEvenWhenPortraitDockIsRequested() {
|
||||
for ((width, height, density) in listOf(Triple(1920f, 1080f, 2f), Triple(720f, 600f, 2.3f))) {
|
||||
assertEquals(GamepadGeometry.layout(width, height, density),
|
||||
GamepadGeometry.layout(width, height, density, portraitDock = true))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun aPortraitDockWithTrackpadsPutsThemOutsideBothSticksWithoutOverlap() {
|
||||
for (panel in portraitPanels) {
|
||||
val b = GamepadGeometry.layout(panel.width.toFloat(), panel.controlsHeight.toFloat(), panel.density, portraitDock = true, trackpads = true)
|
||||
val row = listOf(Slot.LEFT_TOUCH, Slot.LEFT_MAIN, Slot.RIGHT_MAIN, Slot.RIGHT_TOUCH)
|
||||
assertEquals(panel.name, row, row.sortedBy { b.getValue(it).cx })
|
||||
val placed = b.entries.toList()
|
||||
for (i in placed.indices) for (j in i + 1 until placed.size)
|
||||
assertFalse("${panel.name}: ${placed[i].key} overlaps ${placed[j].key}", placed[i].value.overlaps(placed[j].value))
|
||||
for ((slot, box) in b) assertTrue("${panel.name}: $slot", box.bottom <= panel.controlsHeight + .5f && box.right <= panel.width + .5f)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun landscapePanelsGiveTheGripsSlotsWithoutOverlap() {
|
||||
for (panel in panels.filter { it.width > it.height }) {
|
||||
val b = GamepadGeometry.layout(panel.width.toFloat(), panel.controlsHeight.toFloat(), panel.density, grips = true)
|
||||
assertTrue(panel.name, grips.all { it in b })
|
||||
val placed = b.entries.toList()
|
||||
for (i in placed.indices) for (j in i + 1 until placed.size)
|
||||
assertFalse("${panel.name}: ${placed[i].key} overlaps ${placed[j].key}", placed[i].value.overlaps(placed[j].value))
|
||||
for ((slot, box) in b) assertTrue("${panel.name}: $slot", box.top >= -.5f && box.bottom <= panel.controlsHeight + .5f)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun gripsNeverOverlapTheClustersOnSmallTallPanels() {
|
||||
for ((w, h) in listOf(360f to 296f, 480f to 300f, 640f to 420f, 900f to 520f)) {
|
||||
val b = GamepadGeometry.layout(w, h, 1f, grips = true)
|
||||
for (g in grips.filter { it in b }) for ((slot, box) in b) if (slot != g)
|
||||
assertFalse("$w x $h: $g overlaps $slot", b.getValue(g).overlaps(box))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.ui.test.*
|
||||
import com.droiddeck.launcher.input.*
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import com.droiddeck.launcher.session.SessionState
|
||||
import com.droiddeck.launcher.session.SessionService
|
||||
import org.junit.Assert.*
|
||||
@@ -36,8 +35,6 @@ class InputSettingsTest {
|
||||
context.getSharedPreferences("input-profiles", Context.MODE_PRIVATE).edit().clear().commit()
|
||||
context.getSharedPreferences("input-surfaces", Context.MODE_PRIVATE).edit().clear().commit()
|
||||
context.getSharedPreferences("controller", Context.MODE_PRIVATE).edit().clear().commit()
|
||||
context.getSharedPreferences("game-controls", Context.MODE_PRIVATE).edit().clear().commit()
|
||||
context.getSharedPreferences("session", Context.MODE_PRIVATE).edit().clear().commit()
|
||||
}
|
||||
|
||||
@Test fun commandSymbolsAreSelectableForAnyCustomButton() {
|
||||
@@ -63,12 +60,42 @@ class InputSettingsTest {
|
||||
ModeSettingsActions(onResolution = {}, onHdr = {}, onTouch = {}, onSuspendPolicy = {}, onOsc = {},
|
||||
onInputSettings = { opened++ }, onDirectAudio = {}, onMic = {}, onDismiss = {}), SheetTab.CONTROLS)
|
||||
} }
|
||||
compose.onNodeWithText(context.getString(R.string.ctrl_edit)).performSemanticsAction(androidx.compose.ui.semantics.SemanticsActions.OnClick)
|
||||
compose.onNodeWithTag("input-profile-expand").performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.ctrl_edit)).performClick()
|
||||
compose.runOnIdle { assertEquals(1, opened); mode.value = SessionService.MODE_DESKTOP }
|
||||
compose.onNodeWithText(context.getString(R.string.ctrl_edit)).performSemanticsAction(androidx.compose.ui.semantics.SemanticsActions.OnClick)
|
||||
compose.onNodeWithText(context.getString(R.string.ctrl_edit)).performClick()
|
||||
compose.runOnIdle { assertEquals(2, opened) }
|
||||
}
|
||||
|
||||
@Test fun quickMenuCombinesPartsWithoutChangingTheSavedProfile() {
|
||||
val original = InputLibraries.read(context)
|
||||
compose.setContent { DroidDeckTheme {
|
||||
androidx.compose.foundation.layout.Column { InputQuickSettings(rememberMenuHost(), desktop = true) }
|
||||
} }
|
||||
compose.onNodeWithTag("setting-input-profile").assertExists()
|
||||
compose.onNodeWithTag("setting-input-part-PHYSICAL").assertDoesNotExist()
|
||||
compose.onNodeWithTag("input-profile-expand").performClick()
|
||||
compose.onNodeWithTag("setting-input-part-PHYSICAL").assertExists()
|
||||
compose.onNodeWithTag("setting-input-part-PRIMARY").assertExists()
|
||||
compose.onNodeWithTag("setting-input-part-SECONDARY").performClick()
|
||||
compose.onNodeWithText("Deck grips + trackpads").performScrollTo().performClick()
|
||||
compose.runOnIdle {
|
||||
val changed = InputLibraries.read(context)
|
||||
assertEquals(InputStockLayouts.DECK, changed.activePart(true, InputRole.SECONDARY).bindings)
|
||||
assertEquals(original.profiles, changed.profiles)
|
||||
assertEquals(original.compileActive(false), changed.compileActive(false))
|
||||
}
|
||||
compose.onNodeWithText(context.getString(R.string.input_save_combination)).performClick()
|
||||
compose.onNode(hasSetTextAction()).performTextInput("Reading")
|
||||
compose.onNodeWithText(context.getString(R.string.gesture_save_changes)).performClick()
|
||||
compose.runOnIdle {
|
||||
val saved = InputLibraries.read(context)
|
||||
assertEquals("Reading", saved.profile(saved.activeId(true)).name)
|
||||
assertTrue(saved.selection(true).parts.isEmpty())
|
||||
assertEquals(original.profile("desktop"), saved.profile("desktop"))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun actionDraftSurvivesRouteAndTypeChanges() {
|
||||
var saved: InputAction? = null
|
||||
compose.setContent { DroidDeckTheme { InputActionEditor(InputControl.RS, InputAction.Scroll(27f, true), "Right stick", {}, { saved = it }) } }
|
||||
@@ -87,7 +114,8 @@ class InputSettingsTest {
|
||||
@Test fun bindingEditorPersistsDisabledWithoutChangingTouchControls() {
|
||||
var changed = false
|
||||
compose.setContent { DroidDeckTheme { InputSettingsPage({}, { changed = true }) } }
|
||||
compose.onNodeWithTag("input-remap").performScrollTo().performClick()
|
||||
compose.onNodeWithTag("input-profile-game").performScrollTo().performClick()
|
||||
compose.onNodeWithTag("input-part-physical").performScrollTo().performClick()
|
||||
compose.onNodeWithTag("input-binding-a").performScrollTo().performClick()
|
||||
compose.onNodeWithText("Disabled", substring = false).performScrollTo().performClick()
|
||||
compose.runOnIdle { assertFalse(changed) }
|
||||
@@ -106,9 +134,12 @@ class InputSettingsTest {
|
||||
val layout = library.layout(InputProfile.GAME, InputRole.SECONDARY)!!
|
||||
compose.setContent { DroidDeckTheme { InputSurfaceDialog(InputProfile.GAME, {}, { changed = true },
|
||||
role = InputRole.PRIMARY, layoutId = layout.id, bindingsId = library.profile(InputProfile.GAME).binding(InputRole.SECONDARY)) } }
|
||||
addButton(layout)
|
||||
compose.onNodeWithText(context.getString(R.string.input_options)).assertExists()
|
||||
compose.onNodeWithText(context.getString(R.string.input_editor_done)).performScrollTo().performClick()
|
||||
compose.onNodeWithTag("input-editor-tools").performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.input_editor_add)).performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.input_element_button), substring = false).performClick()
|
||||
compose.onNodeWithTag("input-editor-tools").performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.input_properties)).assertExists()
|
||||
compose.onNodeWithText(context.getString(R.string.input_editor_done)).performClick()
|
||||
compose.runOnIdle {
|
||||
assertTrue(changed)
|
||||
val updated = InputLibraries.read(context)
|
||||
@@ -118,124 +149,64 @@ class InputSettingsTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun remapButtonsOpensThePhysicalControllerAndBackReturnsToTheControllerPage() {
|
||||
@Test fun aNewProfileIsIndependentAndDoesNotBecomeActive() {
|
||||
compose.setContent { DroidDeckTheme { InputSettingsPage({}) } }
|
||||
compose.onNodeWithTag("input-remap").performScrollTo().performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.input_physical).uppercase()).assertExists()
|
||||
compose.onNodeWithText(context.getString(R.string.input_new_profile)).performScrollTo().performClick()
|
||||
compose.onNodeWithTag("input-name").performTextInput("Minecraft")
|
||||
compose.onNodeWithText(context.getString(R.string.gesture_save_changes)).performClick()
|
||||
compose.runOnIdle {
|
||||
val library = InputLibraries.read(context)
|
||||
val created = library.profiles.single { it.name == "Minecraft" }
|
||||
for (role in InputRole.entries) assertNotEquals(library.profile(InputProfile.GAME).binding(role), created.binding(role))
|
||||
assertNotEquals(library.layout(InputProfile.GAME, InputRole.SECONDARY)!!.id, library.layout(created.id, InputRole.SECONDARY)!!.id)
|
||||
assertEquals(InputProfiles.AUTO, library.selected)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun openingAProfileDoesNotActivateItAndBackKeepsItsContext() {
|
||||
compose.setContent { DroidDeckTheme { InputSettingsPage({}) } }
|
||||
compose.onNodeWithTag("input-profile-desktop").performScrollTo().performClick()
|
||||
compose.onNodeWithTag("input-part-physical").performScrollTo().performClick()
|
||||
compose.onNodeWithTag("input-binding-a").performScrollTo().performClick()
|
||||
compose.onNodeWithText("Disabled", substring = false).performScrollTo().performClick()
|
||||
compose.onNodeWithTag("input-action-save").performClick()
|
||||
compose.onNodeWithTag("input-remap-reset").performScrollTo().assertExists()
|
||||
compose.onNodeWithText(context.getString(R.string.mode_back)).performClick()
|
||||
compose.onNodeWithTag("osc-edit").assertExists()
|
||||
compose.runOnIdle {
|
||||
assertEquals(InputProfiles.AUTO, InputLibraries.read(context).selected)
|
||||
assertEquals(InputAction.Disabled, InputProfiles.read(context, InputProfile.GAME).action(InputRole.PHYSICAL, InputControl.A))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun inGameRemapOpensStraightOnThePhysicalController() {
|
||||
var closed = false
|
||||
compose.setContent { DroidDeckTheme { InputSettingsPage({ closed = true }, remapOnly = true) } }
|
||||
compose.onNodeWithTag("input-binding-a").assertExists()
|
||||
compose.onNodeWithTag("osc-edit").assertDoesNotExist()
|
||||
compose.onNodeWithText(context.getString(R.string.mode_back)).performClick()
|
||||
compose.runOnIdle { assertTrue(closed) }
|
||||
compose.onNodeWithTag("input-part-secondary").assertExists()
|
||||
compose.runOnIdle { assertEquals(InputProfiles.AUTO, InputLibraries.read(context).selected) }
|
||||
}
|
||||
|
||||
@Test fun settingsShowTheInGameControllerPageForTheDefault() {
|
||||
@Test fun profileCreationCanExplicitlyShareOnlyPhysicalControls() {
|
||||
compose.setContent { DroidDeckTheme { InputSettingsPage({}) } }
|
||||
compose.onNodeWithText(context.getString(R.string.osc_group_for, context.getString(R.string.osc_default)).uppercase()).assertExists()
|
||||
for (label in listOf(R.string.osc_layout, R.string.osc_edit_layout, R.string.osc_show, R.string.input_touches, R.string.unfolded_controls,
|
||||
R.string.input_virtual_controller, R.string.ctrl_rumble, R.string.ctrl_dead_zone, R.string.input_remap_buttons))
|
||||
compose.onNodeWithText(context.getString(label)).performScrollTo().assertExists()
|
||||
for (removed in listOf(R.string.input_default_profiles, R.string.input_profiles, R.string.input_new_profile))
|
||||
compose.onNodeWithText(context.getString(removed)).assertDoesNotExist()
|
||||
compose.onNodeWithTag("input-profile-game").assertDoesNotExist()
|
||||
compose.onNodeWithTag("setting-osc-show").performScrollTo().performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.osc_steam_shortcuts_only)).performClick()
|
||||
compose.runOnIdle { assertEquals(SessionPrefs.OSC_STEAM_QAM, SessionPrefs.oscMode(context)) }
|
||||
compose.onNodeWithTag("setting-osc-show").performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.common_never)).performClick()
|
||||
compose.runOnIdle { assertEquals(SessionPrefs.OSC_NEVER, SessionPrefs.oscMode(context)) }
|
||||
}
|
||||
|
||||
@Test fun theLayoutMenuDescribesEachChoiceAndDeletesAnUnusedLayout() {
|
||||
InputLibraries.update(context) { it.copyLayout(InputLibraries.OVERLAY, "Big sticks", "big-sticks") }
|
||||
compose.setContent { DroidDeckTheme { InputSettingsPage({}) } }
|
||||
compose.onNodeWithTag("setting-osc-layout").performScrollTo().performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.osc_layout_gamepad_detail)).assertExists()
|
||||
compose.onNodeWithText(context.getString(R.string.osc_layout_steam_detail)).assertExists()
|
||||
compose.onNodeWithTag("osc-delete-${InputLibraries.OVERLAY}").assertDoesNotExist()
|
||||
compose.onNodeWithTag("osc-delete-big-sticks").performClick()
|
||||
compose.onNodeWithTag("osc-delete-confirm").performClick()
|
||||
compose.runOnIdle { assertTrue(InputLibraries.read(context).layouts.none { it.id == "big-sticks" }) }
|
||||
compose.onNodeWithTag("setting-osc-layout").performScrollTo().performClick()
|
||||
compose.onNodeWithText("Big sticks").assertDoesNotExist()
|
||||
}
|
||||
|
||||
@Test fun choosingTheDefaultLayoutAppliesToGamesWithoutTheirOwn() {
|
||||
InputLibraries.update(context) { it.copyLayout(InputLibraries.OVERLAY, "Big sticks", "big-sticks") }
|
||||
ControlsChoice.newForGame(context, 7, "Castle Crashers", desktop = false)
|
||||
compose.setContent { DroidDeckTheme { InputSettingsPage({}) } }
|
||||
compose.onNodeWithTag("setting-osc-layout").performScrollTo().performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.osc_layout_steam)).assertExists()
|
||||
compose.onNodeWithText("Big sticks").performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.input_new_profile)).performScrollTo().performClick()
|
||||
compose.onNodeWithTag("input-name").performTextInput("Shared controls")
|
||||
compose.onNodeWithTag("input-share-physical").performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.gesture_save_changes)).performClick()
|
||||
compose.runOnIdle {
|
||||
assertEquals("big-sticks", ControlsChoice.current(context, null, steamMode = true))
|
||||
assertEquals("big-sticks", ControlsChoice.current(context, 8, steamMode = true))
|
||||
assertNotEquals("big-sticks", ControlsChoice.current(context, 7, steamMode = true))
|
||||
assertEquals("big-sticks", InputLibraries.read(context).activeLayout(false, InputRole.PRIMARY)!!.id)
|
||||
val library = InputLibraries.read(context)
|
||||
val created = library.profiles.single { it.name == "Shared controls" }
|
||||
assertEquals(library.profile("game").binding(InputRole.PHYSICAL), created.binding(InputRole.PHYSICAL))
|
||||
assertNotEquals(library.profile("game").binding(InputRole.SECONDARY), created.binding(InputRole.SECONDARY))
|
||||
}
|
||||
compose.onNodeWithTag("osc-edit").performScrollTo().performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.osc_scope_default, "Big sticks")).assertExists()
|
||||
compose.onNodeWithTag("input-editor-split").assertDoesNotExist()
|
||||
}
|
||||
|
||||
@Test fun useDefaultReturnsAGameToTheDefaultLayout() {
|
||||
ControlsChoice.newForGame(context, 42, "Castle Crashers", desktop = false)
|
||||
compose.setContent { DroidDeckTheme { InputSettingsPage({}) } }
|
||||
compose.onNodeWithText(context.getString(R.string.osc_games_own).uppercase()).performScrollTo().assertExists()
|
||||
compose.onNodeWithTag("osc-use-default-42").performScrollTo().performClick()
|
||||
compose.runOnIdle { assertNull(GameControls.bindings(context, 42)) }
|
||||
compose.onNodeWithText(context.getString(R.string.osc_games_own).uppercase()).assertDoesNotExist()
|
||||
}
|
||||
|
||||
@Test fun justThisGameSavesTheEditIntoTheGamesOwnCopy() {
|
||||
@Test fun hidingEditorToolsPreservesPlacedElements() {
|
||||
val library = InputLibraries.read(context)
|
||||
val layout = library.layout("game", InputRole.PRIMARY)!!
|
||||
var closed = false
|
||||
compose.setContent { DroidDeckTheme { InputSurfaceDialog("game", { closed = true }, {}, role = InputRole.PRIMARY,
|
||||
layoutId = layout.id, bindingsId = library.profile("game").binding(InputRole.PRIMARY),
|
||||
scope = context.getString(R.string.osc_scope_default, layout.name),
|
||||
split = InputEditorSplit(context.getString(R.string.osc_just_this_game), "Gamepad · saved for Castle Crashers",
|
||||
{ lib, layoutId, bindingsId -> ControlsChoice.copyForGame(context, lib, 7, "Castle Crashers", false, layoutId, bindingsId) },
|
||||
{ bindingsId -> ControlsChoice.useForGame(context, 7, "Castle Crashers", bindingsId) }) ) } }
|
||||
compose.onNodeWithTag("input-editor-split").performClick()
|
||||
compose.onNodeWithText("Gamepad · saved for Castle Crashers").assertExists()
|
||||
compose.onNodeWithTag("input-editor-split").assertDoesNotExist()
|
||||
pressPlus(2)
|
||||
compose.onNodeWithText(context.getString(R.string.input_editor_done)).performScrollTo().performClick()
|
||||
compose.runOnIdle {
|
||||
assertTrue(closed)
|
||||
val saved = InputLibraries.read(context)
|
||||
assertTrue(OnScreenLayout.generated(saved.layouts.first { it.id == layout.id }))
|
||||
val own = saved.layouts.first { it.id == ControlsChoice.current(context, 7, steamMode = false) }
|
||||
assertNotEquals(layout.id, own.id)
|
||||
assertFalse(OnScreenLayout.generated(own))
|
||||
assertEquals(layout.id, ControlsChoice.current(context, 8, steamMode = false))
|
||||
}
|
||||
val layout = library.layout("game", InputRole.SECONDARY)!!
|
||||
compose.setContent { DroidDeckTheme { InputSurfaceDialog("game", {}, {}, role = InputRole.PRIMARY,
|
||||
layoutId = layout.id, bindingsId = library.profile("game").binding(InputRole.SECONDARY)) } }
|
||||
compose.onNodeWithTag("input-editor-tools").performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.input_editor_add)).performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.input_element_button)).performClick()
|
||||
compose.onNodeWithTag("input-layout-canvas").performTouchInput { click(center) }
|
||||
compose.onNodeWithTag("input-editor-tools").performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.input_hide_tools)).performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.input_editor_add)).assertDoesNotExist()
|
||||
compose.onNodeWithTag("input-editor-tools").performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.input_editor_done)).performClick()
|
||||
compose.runOnIdle { assertEquals(layout.elements.size + 1, InputLibraries.read(context).layout("game", InputRole.SECONDARY)!!.elements.size) }
|
||||
}
|
||||
|
||||
private val add get() = context.getString(R.string.input_editor_add)
|
||||
|
||||
private fun addButton(layout: SavedInputLayout) {
|
||||
compose.onNodeWithText(add).performScrollTo().performClick()
|
||||
val clicks = listOf("legacy:l3", "legacy:r3").count { id -> layout.elements.none { it.id == id } }
|
||||
compose.onAllNodesWithText(add)[1 + clicks + InputElementKind.entries.indexOf(InputElementKind.BUTTON)].performScrollTo().performClick()
|
||||
}
|
||||
|
||||
@Test fun theEditorToolbarStaysAboveTheCanvasAndAddOpensAndClosesItsList() {
|
||||
@Test fun localToolsCanMoveAndExpandWithoutMovingTheCanvas() {
|
||||
val library = InputLibraries.read(context)
|
||||
compose.setContent { DroidDeckTheme { InputSurfaceDialog("game", {}, {}, role = InputRole.PRIMARY,
|
||||
layoutId = library.layout("game", InputRole.SECONDARY)!!.id, bindingsId = library.profile("game").binding(InputRole.SECONDARY)) } }
|
||||
@@ -245,75 +216,69 @@ class InputSettingsTest {
|
||||
assertEquals(android.view.WindowManager.LayoutParams.MATCH_PARENT, window.attributes.height)
|
||||
}
|
||||
val canvas = compose.onNodeWithTag("input-layout-canvas").fetchSemanticsNode().boundsInRoot
|
||||
val tools = compose.onNodeWithTag("input-editor-tools").fetchSemanticsNode().boundsInRoot
|
||||
assertTrue(tools.top >= canvas.top && tools.bottom < canvas.center.y)
|
||||
val button = context.getString(R.string.input_element_button)
|
||||
compose.onNodeWithText(button).assertDoesNotExist()
|
||||
compose.onNodeWithText(add).performScrollTo().performClick()
|
||||
compose.onNodeWithText(button).assertIsDisplayed()
|
||||
compose.onAllNodesWithText(add).onFirst().performScrollTo().performClick()
|
||||
compose.onNodeWithText(button).assertDoesNotExist()
|
||||
val before = compose.onNodeWithTag("input-editor-tools").fetchSemanticsNode().boundsInRoot
|
||||
compose.onNodeWithTag("input-editor-tools").performTouchInput { swipe(center, center + androidx.compose.ui.geometry.Offset(250f, 150f), 500) }
|
||||
val after = compose.onNodeWithTag("input-editor-tools").fetchSemanticsNode().boundsInRoot
|
||||
assertTrue(after.left > before.left + 100f)
|
||||
compose.onNodeWithTag("input-editor-tools").performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.input_editor_add)).assertIsDisplayed()
|
||||
assertEquals(canvas, compose.onNodeWithTag("input-layout-canvas").fetchSemanticsNode().boundsInRoot)
|
||||
compose.onNodeWithTag("input-editor-tools").performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.input_editor_add)).assertDoesNotExist()
|
||||
}
|
||||
|
||||
@Test @Config(qualifiers = "w833dp-h468dp-land-369dpi")
|
||||
fun removedKitControlsWaitUnderHiddenAndRestoringThemKeepsTheGamepadGenerated() {
|
||||
val library = InputLibraries.read(context)
|
||||
val layout = library.layout("game", InputRole.PRIMARY)!!
|
||||
val a = InputLibraries.defaultPositions(context, library, layout)!!.first.single { it.id == "legacy:a" }
|
||||
compose.setContent { DroidDeckTheme { InputSurfaceDialog("game", {}, {}, role = InputRole.PRIMARY,
|
||||
layoutId = layout.id, bindingsId = library.profile("game").binding(InputRole.PRIMARY)) } }
|
||||
compose.onNodeWithText(context.getString(R.string.input_hidden_count, 0)).performScrollTo().performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.input_nothing_hidden)).assertExists()
|
||||
compose.onNodeWithText(context.getString(R.string.input_hidden_count, 0)).performScrollTo().performClick()
|
||||
compose.onNodeWithTag("input-layout-canvas").performTouchInput { click(percentOffset(a.x + a.width / 2, a.y + a.height / 2)) }
|
||||
compose.onNodeWithText(context.getString(R.string.input_remove_element)).performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.input_hidden_count, 1)).performScrollTo().performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.input_restore)).performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.input_hidden_count, 0)).assertExists()
|
||||
compose.onNodeWithText(context.getString(R.string.input_editor_done)).performScrollTo().performClick()
|
||||
compose.runOnIdle { assertTrue(OnScreenLayout.generated(InputLibraries.read(context).layouts.first { it.id == layout.id })) }
|
||||
@Test fun deckPresetOffersItsRealElementsAndTheCommonEditor() {
|
||||
InputLibraries.update(context) { it.useLayout("game", InputRole.SECONDARY, InputLibraries.DECK, shared = true) }
|
||||
compose.setContent { DroidDeckTheme { InputSettingsPage({}) } }
|
||||
compose.onNodeWithTag("input-profile-game").performScrollTo().performClick()
|
||||
compose.onNodeWithTag("input-part-secondary").performScrollTo().performClick()
|
||||
compose.onNodeWithTag("input-element-legacy:l4").performScrollTo().assertIsDisplayed()
|
||||
compose.onNodeWithTag("input-binding-a").assertDoesNotExist()
|
||||
}
|
||||
|
||||
@Test fun resetAfterResizingMakesTheGamepadFollowTheKitAgain() {
|
||||
val library = InputLibraries.read(context)
|
||||
val layout = library.layout("game", InputRole.PRIMARY)!!
|
||||
compose.setContent { DroidDeckTheme { InputSurfaceDialog("game", {}, {}, role = InputRole.PRIMARY,
|
||||
layoutId = layout.id, bindingsId = library.profile("game").binding(InputRole.PRIMARY)) } }
|
||||
val reset = compose.onNodeWithText(context.getString(R.string.hud_reset_button))
|
||||
reset.performScrollTo().assertIsNotEnabled()
|
||||
pressPlus(2)
|
||||
reset.performScrollTo().assertIsEnabled().performClick()
|
||||
compose.onNodeWithTag("input-editor-scale").assertTextEquals("100%")
|
||||
reset.performScrollTo().assertIsNotEnabled()
|
||||
compose.onNodeWithText(context.getString(R.string.input_editor_done)).performScrollTo().performClick()
|
||||
compose.runOnIdle { assertTrue(OnScreenLayout.generated(InputLibraries.read(context).layouts.first { it.id == layout.id })) }
|
||||
@Test fun mouseTrackpadPresetIsEditableLikeAnyOtherLayout() {
|
||||
InputLibraries.update(context) { it.useLayout("game", InputRole.SECONDARY, InputLibraries.TRACKPAD, shared = true) }
|
||||
compose.setContent { DroidDeckTheme { InputSettingsPage({}) } }
|
||||
compose.onNodeWithTag("input-profile-game").performScrollTo().performClick()
|
||||
compose.onNodeWithTag("input-part-secondary").performScrollTo().performClick()
|
||||
compose.onNodeWithTag("input-element-legacy:right-pad").performScrollTo().assertIsDisplayed()
|
||||
compose.onNodeWithTag("input-surface-secondary").performScrollTo().assertIsDisplayed()
|
||||
compose.onNodeWithTag("input-binding-a").assertDoesNotExist()
|
||||
}
|
||||
|
||||
@Test @Config(qualifiers = "w833dp-h468dp-land-369dpi")
|
||||
fun removingAndRestoringAKitButtonKeepsItsAction() {
|
||||
val library = InputLibraries.read(context)
|
||||
val layout = library.layout("game", InputRole.PRIMARY)!!
|
||||
val bindingsId = library.profile("game").binding(InputRole.PRIMARY)
|
||||
InputLibraries.update(context) { lib -> lib.preset(bindingsId).let { b -> lib.withPreset(b.copy(elements = b.elements + ("legacy:a" to InputAction.Keys(listOf(30))))) } }
|
||||
val a = InputLibraries.defaultPositions(context, library, layout)!!.first.single { it.id == "legacy:a" }
|
||||
compose.setContent { DroidDeckTheme { InputSurfaceDialog("game", {}, {}, role = InputRole.PRIMARY, layoutId = layout.id, bindingsId = bindingsId) } }
|
||||
compose.onNodeWithTag("input-layout-canvas").performTouchInput { click(percentOffset(a.x + a.width / 2, a.y + a.height / 2)) }
|
||||
compose.onNodeWithText(context.getString(R.string.input_remove_element)).performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.input_editor_done)).performScrollTo().performClick()
|
||||
compose.runOnIdle { assertEquals(InputAction.Keys(listOf(30)), InputLibraries.read(context).preset(bindingsId).elements["legacy:a"]) }
|
||||
@Test fun primaryScreenOffersItsActualElementsAndTheCommonEditor() {
|
||||
compose.setContent { DroidDeckTheme { InputSettingsPage({}) } }
|
||||
compose.onNodeWithTag("input-profile-game").performScrollTo().performClick()
|
||||
compose.onNodeWithTag("input-part-primary").performScrollTo().performClick()
|
||||
compose.onNodeWithTag("input-element-legacy:a").performScrollTo().assertIsDisplayed()
|
||||
compose.onNodeWithTag("input-binding-a").assertDoesNotExist()
|
||||
compose.onNodeWithTag("input-surface-primary").performScrollTo().performClick()
|
||||
compose.onNodeWithTag("input-editor-tools").performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.input_editor_add)).assertIsDisplayed()
|
||||
compose.onNodeWithTag("input-layout-canvas").assertExists()
|
||||
}
|
||||
|
||||
@Test fun resetAndSaveKeepTheDpadDirectionOverrides() {
|
||||
val library = InputLibraries.read(context)
|
||||
val layout = library.layout("game", InputRole.PRIMARY)!!
|
||||
val bindingsId = library.profile("game").binding(InputRole.PRIMARY)
|
||||
InputLibraries.update(context) { lib -> lib.preset(bindingsId).let { b -> lib.withPreset(b.copy(elements = b.elements + ("legacy:up" to InputAction.Keys(listOf(103))))) } }
|
||||
compose.setContent { DroidDeckTheme { InputSurfaceDialog("game", {}, {}, role = InputRole.PRIMARY, layoutId = layout.id, bindingsId = bindingsId) } }
|
||||
pressPlus(2)
|
||||
compose.onNodeWithText(context.getString(R.string.hud_reset_button)).performScrollTo().performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.input_editor_done)).performScrollTo().performClick()
|
||||
compose.runOnIdle { assertEquals(InputAction.Keys(listOf(103)), InputLibraries.read(context).preset(bindingsId).elements["legacy:up"]) }
|
||||
@Test fun deviceSettingsAreInlineBelowProfiles() {
|
||||
compose.setContent { DroidDeckTheme { InputSettingsPage({}) } }
|
||||
compose.onNodeWithTag("input-more").assertDoesNotExist()
|
||||
compose.onNodeWithText(context.getString(R.string.ctrl_dead_zone)).performScrollTo().assertIsDisplayed()
|
||||
compose.onNodeWithTag("input-profile-game").performScrollTo().assertIsDisplayed()
|
||||
}
|
||||
|
||||
@Test fun migratedPadClicksRemainEditableWithoutChangingMovement() {
|
||||
compose.setContent { DroidDeckTheme { InputSettingsPage({}) } }
|
||||
compose.onNodeWithTag("input-profile-desktop").performScrollTo().performClick()
|
||||
compose.onNodeWithTag("input-part-secondary").performScrollTo().performClick()
|
||||
compose.onNodeWithTag("input-click-legacy:right-pad").performScrollTo().performClick()
|
||||
compose.onNodeWithText("Disabled", substring = false).performScrollTo().performClick()
|
||||
compose.onNodeWithTag("input-action-save").performClick()
|
||||
compose.runOnIdle {
|
||||
val library = InputLibraries.read(context)
|
||||
val pad = library.layout("desktop", InputRole.SECONDARY)!!.elements.first { it.control == InputControl.RIGHT_PAD }
|
||||
val profile = library.compile("desktop")
|
||||
assertEquals(InputAction.Disabled, profile.elementClickAction(InputRole.SECONDARY, pad))
|
||||
assertEquals(InputAction.Pointer(), profile.elementAction(InputRole.SECONDARY, pad.id, pad.control))
|
||||
}
|
||||
}
|
||||
|
||||
@Test @Config(sdk = [34]) fun secondarySettingsCanOpenAnActivityDialogAndCloseCleanly() {
|
||||
@@ -326,8 +291,8 @@ class InputSettingsTest {
|
||||
val host = androidx.compose.ui.platform.LocalContext.current.findActivity() as androidx.activity.ComponentActivity
|
||||
if (open.value) InputDisplayContent(host, display, { open.value = false }) { InputSettingsPage({ open.value = false }) }
|
||||
} }
|
||||
compose.onNodeWithText(context.getString(R.string.input_read_timing)).performScrollTo().performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.common_close)).assertExists()
|
||||
compose.onNodeWithText(context.getString(R.string.input_new_profile)).performScrollTo().performClick()
|
||||
compose.onNodeWithTag("input-name").assertExists()
|
||||
compose.runOnIdle {
|
||||
assertTrue(ShadowDialog.getShownDialogs().filterIsInstance<Presentation>().any { it.isShowing && it.display.displayId == displayId })
|
||||
val dialog = ShadowDialog.getShownDialogs().last { it !is Presentation && it.isShowing }
|
||||
@@ -455,14 +420,15 @@ class InputSettingsTest {
|
||||
val round = mutableStateOf(0)
|
||||
compose.setContent { DroidDeckTheme { androidx.compose.runtime.key(round.value) { InputSurfaceDialog("game", {}, {}, role = InputRole.PRIMARY,
|
||||
layoutId = layout.id, bindingsId = library.profile("game").binding(InputRole.SECONDARY)) } } }
|
||||
compose.onNodeWithText(context.getString(R.string.hud_reset_button)).performScrollTo().assertIsNotEnabled()
|
||||
repeat(4) { compose.onNodeWithText("\u2212").performScrollTo().performClick() }
|
||||
compose.onNodeWithTag("input-editor-scale").assertTextEquals("80%")
|
||||
compose.onNodeWithTag("input-editor-tools").performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.input_reset_positions)).performScrollTo().assertIsNotEnabled()
|
||||
compose.onNodeWithTag("input-editor-scale").performScrollTo().performSemanticsAction(androidx.compose.ui.semantics.SemanticsActions.SetProgress) { it(80f) }
|
||||
compose.onNodeWithText(context.getString(R.string.input_editor_done)).performScrollTo().performClick()
|
||||
val scaled = InputLibraries.read(context).layouts.first { it.id == layout.id }
|
||||
assertEquals(layout.elements.scaled(.8f), scaled.elements)
|
||||
compose.runOnIdle { round.value = 1 }
|
||||
compose.onNodeWithText(context.getString(R.string.hud_reset_button)).performScrollTo().performClick()
|
||||
compose.onNodeWithTag("input-editor-tools").performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.input_reset_positions)).performScrollTo().performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.input_editor_done)).performScrollTo().performClick()
|
||||
compose.runOnIdle { assertEquals(layout.elements, InputLibraries.read(context).layouts.first { it.id == layout.id }.elements) }
|
||||
}
|
||||
@@ -484,54 +450,104 @@ class InputSettingsTest {
|
||||
com.droiddeck.launcher.input.ControllerPrefs.setSnap(context, true)
|
||||
}
|
||||
|
||||
private fun pressPlus(times: Int) = repeat(times) { compose.onNodeWithText("+").performScrollTo().performClick() }
|
||||
@Test fun quickButtonTogglesHideBuiltInButtonsWithoutDeletingThem() {
|
||||
compose.setContent { DroidDeckTheme { InputSettingsPage({}) } }
|
||||
compose.onNodeWithTag("input-profile-game").performScrollTo().performClick()
|
||||
compose.onNodeWithTag("input-part-primary").performScrollTo().performClick()
|
||||
val before = InputLibraries.read(context).layout("game", InputRole.PRIMARY)!!
|
||||
compose.onNodeWithTag("setting-quick-keyboard").performScrollTo().performClick()
|
||||
compose.runOnIdle {
|
||||
val after = InputLibraries.read(context).layout("game", InputRole.PRIMARY)!!
|
||||
assertEquals(before.elements, after.elements)
|
||||
assertEquals(setOf(InputCommand.KEYBOARD), after.style.hidden)
|
||||
}
|
||||
compose.onNodeWithTag("setting-quick-keyboard").performScrollTo().performClick()
|
||||
compose.runOnIdle { assertTrue(InputLibraries.read(context).layout("game", InputRole.PRIMARY)!!.style.hidden.isEmpty()) }
|
||||
}
|
||||
|
||||
@Test fun sizeButtonsScaleTheWholeGamepadAndUndoAsOneStep() {
|
||||
@Test fun layoutsCanBeImportedAndExported() {
|
||||
val source = java.io.File(context.cacheDir, "jump.icp").apply {
|
||||
writeText("""{"name":"Jump keys","elements":[{"type":"BUTTON","shape":"CIRCLE","bindings":["KEY_SPACE"],"scale":1.0,"x":0.8,"y":0.7,"text":"Jump"}]}""")
|
||||
}
|
||||
val target = java.io.File(context.cacheDir, "out.icp").apply { delete() }
|
||||
val registry = object : androidx.activity.result.ActivityResultRegistry() {
|
||||
override fun <I, O> onLaunch(requestCode: Int, contract: androidx.activity.result.contract.ActivityResultContract<I, O>, input: I,
|
||||
options: androidx.core.app.ActivityOptionsCompat?) {
|
||||
dispatchResult(requestCode, android.net.Uri.fromFile(if (input is String) target else source))
|
||||
}
|
||||
}
|
||||
val owner = object : androidx.activity.result.ActivityResultRegistryOwner { override val activityResultRegistry = registry }
|
||||
compose.setContent { androidx.compose.runtime.CompositionLocalProvider(androidx.activity.compose.LocalActivityResultRegistryOwner provides owner) {
|
||||
DroidDeckTheme { InputSettingsPage({}) }
|
||||
} }
|
||||
compose.onNodeWithTag("input-profile-game").performScrollTo().performClick()
|
||||
compose.onNodeWithTag("input-part-primary").performScrollTo().performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.input_saved_layouts)).performScrollTo().performClick()
|
||||
compose.onNodeWithTag("layout-manage-${InputLibraries.OVERLAY}").performScrollTo().performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.screen_key_layout_export)).assertDoesNotExist()
|
||||
compose.onNodeWithText(context.getString(R.string.common_close)).performClick()
|
||||
compose.onNodeWithTag("input-layout-import").performScrollTo().performClick()
|
||||
compose.waitUntil(5_000) { InputLibraries.read(context).layout("game", InputRole.PRIMARY)!!.name == "Jump keys" }
|
||||
val imported = InputLibraries.read(context).layout("game", InputRole.PRIMARY)!!
|
||||
assertEquals(InputLayoutScreen.MAIN, imported.screen)
|
||||
assertEquals(InputAction.Keys(listOf(57)), InputLibraries.read(context).compile("game").elementAction(InputRole.PRIMARY, imported.elements.single().id, InputControl.A))
|
||||
compose.onNodeWithText(context.getString(R.string.input_saved_layouts)).performScrollTo().performClick()
|
||||
compose.onNodeWithTag("layout-manage-${imported.id}").performScrollTo().performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.screen_key_layout_export)).performClick()
|
||||
compose.waitUntil(5_000) { target.isFile && target.length() > 0 }
|
||||
assertEquals(source.readText().let { org.json.JSONObject(it).getString("name") }, org.json.JSONObject(target.readText()).getString("name"))
|
||||
assertEquals("KEY_SPACE", org.json.JSONObject(target.readText()).getJSONArray("elements").getJSONObject(0).getJSONArray("bindings").getString(0))
|
||||
}
|
||||
|
||||
@Test fun buttonSizeRegeneratesTheGamepadAndUndoesAsOneStep() {
|
||||
val library = InputLibraries.read(context)
|
||||
val layout = library.layout("game", InputRole.PRIMARY)!!
|
||||
assertTrue(OnScreenLayout.generated(layout))
|
||||
val defaults = InputLibraries.defaultPositions(context, library, layout)!!.first
|
||||
val (_, metrics) = InputLibraries.primaryDisplay(context)
|
||||
assertNotNull(OnScreenLayout.generatedSize(context, layout, metrics.widthPixels, metrics.heightPixels))
|
||||
compose.setContent { DroidDeckTheme { InputSurfaceDialog("game", {}, {}, role = InputRole.PRIMARY,
|
||||
layoutId = layout.id, bindingsId = library.profile("game").binding(InputRole.PRIMARY)) } }
|
||||
val scale = compose.onNodeWithTag("input-editor-scale")
|
||||
scale.assertTextEquals("100%")
|
||||
pressPlus(2)
|
||||
scale.assertTextEquals("110%")
|
||||
compose.onNodeWithTag("input-editor-tools").performClick()
|
||||
val slider = compose.onNodeWithTag("input-editor-scale").performScrollTo()
|
||||
slider.assert(SemanticsMatcher.expectValue(androidx.compose.ui.semantics.SemanticsProperties.StateDescription, "100%"))
|
||||
for (value in listOf(110f, 125f)) slider.performSemanticsAction(androidx.compose.ui.semantics.SemanticsActions.SetProgress) { it(value) }
|
||||
compose.onNodeWithText(context.getString(R.string.input_editor_undo)).performScrollTo().performClick()
|
||||
scale.assertTextEquals("100%")
|
||||
pressPlus(5)
|
||||
scale.assertTextEquals("125%")
|
||||
slider.assert(SemanticsMatcher.expectValue(androidx.compose.ui.semantics.SemanticsProperties.StateDescription, "100%"))
|
||||
slider.performSemanticsAction(androidx.compose.ui.semantics.SemanticsActions.SetProgress) { it(125f) }
|
||||
compose.onNodeWithText(context.getString(R.string.input_editor_done)).performScrollTo().performClick()
|
||||
compose.runOnIdle {
|
||||
val saved = InputLibraries.read(context).layouts.first { it.id == layout.id }
|
||||
assertFalse(OnScreenLayout.generated(saved))
|
||||
assertEquals(defaults.map { it.id }, saved.elements.map { it.id })
|
||||
assertTrue(saved.elements.first { it.id == "legacy:a" }.width > defaults.first { it.id == "legacy:a" }.width * 1.2f)
|
||||
assertEquals(1.25f, saved.scale)
|
||||
assertNotNull(OnScreenLayout.generatedSize(context, saved, metrics.widthPixels, metrics.heightPixels))
|
||||
assertNotEquals(layout.elements.first { it.id == "legacy:a" }.y, saved.elements.first { it.id == "legacy:a" }.y)
|
||||
}
|
||||
}
|
||||
|
||||
@Test @Config(qualifiers = "w833dp-h468dp-land-369dpi")
|
||||
fun sizeButtonsKeepAMovedFaceClusterInShape() {
|
||||
fun buttonSizeKeepsMovedGamepadGroupsInShape() {
|
||||
val face = setOf("legacy:a", "legacy:b", "legacy:x", "legacy:y")
|
||||
val original = InputLibraries.read(context)
|
||||
val gamepad = original.layout("game", InputRole.PRIMARY)!!
|
||||
val (defaults, aspect) = InputLibraries.defaultPositions(context, original, gamepad)!!
|
||||
val moved = gamepad.copy(elements = defaults.map { if (it.id in face) it.copy(x = it.x + .012f, y = it.y + .017f) else it }, aspect = aspect)
|
||||
val moved = gamepad.copy(elements = gamepad.elements.map { if (it.id in face) it.copy(x = it.x + .012f, y = it.y + .017f) else it })
|
||||
InputLibraries.update(context) { it.withLayout(moved) }
|
||||
val (_, metrics) = InputLibraries.primaryDisplay(context)
|
||||
assertNull(OnScreenLayout.generatedSize(context, moved, metrics.widthPixels, metrics.heightPixels))
|
||||
val library = InputLibraries.read(context)
|
||||
compose.setContent { DroidDeckTheme { InputSurfaceDialog("game", {}, {}, role = InputRole.PRIMARY,
|
||||
layoutId = moved.id, bindingsId = library.profile("game").binding(InputRole.PRIMARY)) } }
|
||||
pressPlus(5)
|
||||
compose.onNodeWithTag("input-editor-tools").performClick()
|
||||
compose.onNodeWithTag("input-editor-scale").performScrollTo().performSemanticsAction(androidx.compose.ui.semantics.SemanticsActions.SetProgress) { it(125f) }
|
||||
compose.onNodeWithText(context.getString(R.string.input_editor_done)).performScrollTo().performClick()
|
||||
compose.runOnIdle {
|
||||
val saved = InputLibraries.read(context).layouts.first { it.id == moved.id }
|
||||
val w = saved.aspect * 1000; val h = 1000f
|
||||
assertEquals(1.25f, saved.scale)
|
||||
val w = metrics.widthPixels; val h = metrics.heightPixels
|
||||
fun centre(id: String) = saved.elements.first { it.id == id }.let { (it.x + it.width / 2) * w to (it.y + it.height / 2) * h }
|
||||
val cross = face.associateWith(::centre)
|
||||
assertEquals(centre("legacy:y").first, centre("legacy:a").first, 1f)
|
||||
assertEquals(centre("legacy:x").second, centre("legacy:b").second, 1f)
|
||||
assertTrue("$cross", centre("legacy:y").second < centre("legacy:x").second && centre("legacy:x").second < centre("legacy:a").second)
|
||||
assertTrue("$cross", centre("legacy:x").first < centre("legacy:a").first && centre("legacy:a").first < centre("legacy:b").first)
|
||||
assertTrue(centre("legacy:y").second < centre("legacy:x").second && centre("legacy:x").second < centre("legacy:a").second)
|
||||
assertEquals(centre("legacy:a").second - centre("legacy:y").second, centre("legacy:b").first - centre("legacy:x").first, 1f)
|
||||
assertEquals(centre("legacy:up").first, centre("legacy:down").first, 1f)
|
||||
assertEquals(centre("legacy:left").second, centre("legacy:right").second, 1f)
|
||||
val before = moved.elements.first { it.id == "legacy:a" }
|
||||
assertTrue(saved.elements.first { it.id == "legacy:a" }.width > before.width * 1.2f)
|
||||
}
|
||||
|
||||
@@ -63,19 +63,6 @@ class InputSurfaceTouchTest {
|
||||
|
||||
private fun state() = JoyConPadTest.RecordingWriter.pads[0] ?: PadState()
|
||||
|
||||
@Test fun controlsTakeTheSizeTheyAreLaidOutAtEvenIfMeasuredAtAnother() {
|
||||
val element = InputSurfaceElement(InputControl.LT, .1f, .1f, .2f, .05f, kind = InputElementKind.TRIGGER, buttonShape = InputButtonShape.PILL)
|
||||
val surface = InputSurfaceView(context).apply { updateCustomLayout(listOf(element)) }
|
||||
surface.measure(View.MeasureSpec.makeMeasureSpec(1000, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(3000, View.MeasureSpec.EXACTLY))
|
||||
surface.layout(0, 0, 1000, 3000)
|
||||
val canvas = descendants(surface).first { it.tag == element }.parent as View
|
||||
canvas.layout(0, 0, 1000, 1000)
|
||||
val control = descendants(surface).first { it.tag == element }
|
||||
assertEquals(100, control.top)
|
||||
assertEquals(200, control.width)
|
||||
assertEquals(50, control.height)
|
||||
}
|
||||
|
||||
@Test fun aFingerSlidingBetweenButtonsMovesThePress() {
|
||||
touch(MotionEvent.ACTION_DOWN, 1 to (800f to 240f))
|
||||
assertTrue(state().isDown(PadState.A))
|
||||
@@ -147,23 +134,26 @@ class InputSurfaceTouchTest {
|
||||
touch(MotionEvent.ACTION_UP, 1 to (600f to 510f))
|
||||
assertTrue(events.isEmpty())
|
||||
show(a, b, stick)
|
||||
view.setPresentation(OnScreenControls.Hidden.BY_TAP)
|
||||
view.setQuickHidden(true)
|
||||
measure(view)
|
||||
assertFalse(view.takesTouchAt(450f, 510f))
|
||||
assertFalse(touch(MotionEvent.ACTION_DOWN, 1 to (450f to 510f)))
|
||||
assertTrue(events.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun hiddenControlsHideTheKeyboardShortcutUntilShownAgain() {
|
||||
view.setPresentation(OnScreenControls.Hidden.BY_CONTROLLER)
|
||||
@Test fun keyboardShortcutWorksWithHiddenPadAndButtonsOnly() {
|
||||
view.setQuickHidden(true)
|
||||
measure(view)
|
||||
assertFalse(view.takesTouchAt(800f, 240f))
|
||||
assertFalse(view.takesTouchAt(450f, 510f))
|
||||
view.setPresentation(null)
|
||||
measure(view)
|
||||
touch(MotionEvent.ACTION_DOWN, 1 to (450f to 510f))
|
||||
touch(MotionEvent.ACTION_UP, 1 to (450f to 510f))
|
||||
assertEquals(listOf("KEYBOARD:PRIMARY"), events)
|
||||
view.setButtonsOnly(true)
|
||||
measure(view)
|
||||
val (x, y) = centre(element(view, "builtin:keyboard"))
|
||||
assertFalse(view.takesTouchAt(800f, 240f))
|
||||
touch(MotionEvent.ACTION_DOWN, 1 to (x to y))
|
||||
touch(MotionEvent.ACTION_UP, 1 to (x to y))
|
||||
assertEquals(listOf("KEYBOARD:PRIMARY", "KEYBOARD:PRIMARY"), events)
|
||||
}
|
||||
|
||||
@Test fun hidingTheViewReleasesLatchedKeys() {
|
||||
@@ -191,14 +181,11 @@ class InputSurfaceTouchTest {
|
||||
touch(MotionEvent.ACTION_CANCEL, 1 to (800f to 240f), target = panel)
|
||||
}
|
||||
|
||||
@Test fun fixedSticksReachFullTiltInsideTheirRing() {
|
||||
@Test fun classicSticksTravelTheirFullRadius() {
|
||||
show(stick.copy(buttonShape = InputButtonShape.CIRCLE))
|
||||
val reach = (100f - 3 * context.resources.displayMetrics.density) * .62f
|
||||
touch(MotionEvent.ACTION_DOWN, 1 to (200f to 300f))
|
||||
touch(MotionEvent.ACTION_MOVE, 1 to (200f + reach / 2 to 300f))
|
||||
touch(MotionEvent.ACTION_MOVE, 1 to (250f to 300f))
|
||||
assertEquals(.5f, state().leftX, .01f)
|
||||
touch(MotionEvent.ACTION_MOVE, 1 to (200f + reach to 300f))
|
||||
assertEquals(1f, state().leftX, .01f)
|
||||
touch(MotionEvent.ACTION_MOVE, 1 to (300f to 300f))
|
||||
assertEquals(1f, state().leftX, .01f)
|
||||
touch(MotionEvent.ACTION_UP, 1 to (300f to 300f))
|
||||
@@ -222,15 +209,14 @@ class InputSurfaceTouchTest {
|
||||
}
|
||||
|
||||
@Test fun adaptiveSticksCaptureAroundThemAndTheLeftOneToTheEdge() {
|
||||
val left = InputSurfaceElement(InputControl.LS, .3f, .3f, .2f, .4f, floating = true)
|
||||
val right = InputSurfaceElement(InputControl.RS, .6f, .3f, .2f, .4f, floating = true)
|
||||
val left = InputSurfaceElement(InputControl.LS, .3f, .3f, .2f, .4f, hideWhenIdle = true)
|
||||
val right = InputSurfaceElement(InputControl.RS, .6f, .3f, .2f, .4f, hideWhenIdle = true)
|
||||
show(left, right)
|
||||
val limit = (100f - 3 * context.resources.displayMetrics.density) * 1.71f
|
||||
assertTrue(view.takesTouchAt(10f, 300f))
|
||||
assertTrue(view.takesTouchAt(10f, 300f + limit - 4f))
|
||||
assertFalse(view.takesTouchAt(10f, 300f + limit + 4f))
|
||||
assertTrue(view.takesTouchAt(990f, 300f))
|
||||
assertFalse(view.takesTouchAt(990f, 300f + limit + 4f))
|
||||
assertTrue(view.takesTouchAt(10f, 390f))
|
||||
assertFalse(view.takesTouchAt(10f, 420f))
|
||||
assertTrue(view.takesTouchAt(795f, 300f))
|
||||
assertFalse(view.takesTouchAt(815f, 300f))
|
||||
val missed = mutableListOf<Int>()
|
||||
view.onTouchMiss = { missed += it.getPointerId(0) }
|
||||
touch(MotionEvent.ACTION_DOWN, 1 to (50f to 300f))
|
||||
@@ -238,9 +224,9 @@ class InputSurfaceTouchTest {
|
||||
assertEquals(listOf(2), missed)
|
||||
touch(MotionEvent.ACTION_MOVE, 1 to (150f to 300f), 2 to (60f to 310f))
|
||||
assertTrue(state().leftX > .9f)
|
||||
show(left.copy(floating = false), right.copy(floating = false))
|
||||
show(left.copy(hideWhenIdle = false), right.copy(hideWhenIdle = false))
|
||||
assertFalse(view.takesTouchAt(10f, 300f))
|
||||
assertFalse(view.takesTouchAt(990f, 300f))
|
||||
assertFalse(view.takesTouchAt(815f, 300f))
|
||||
}
|
||||
|
||||
private fun element(root: View, id: String): View = descendants(root).first { (it.tag as? InputSurfaceElement)?.id == id }
|
||||
|
||||
@@ -55,12 +55,12 @@ class InputUiLayoutTest {
|
||||
}
|
||||
|
||||
@Test @Config(qualifiers = "w360dp-h800dp")
|
||||
fun phoneKeepsTheControllerPageAndRemappingReachable() {
|
||||
fun phoneKeepsLibraryNavigationAndProfileEditingReachable() {
|
||||
compose.setContent { root = LocalView.current; DroidDeckTheme { Surface { BoxWithConstraints {
|
||||
CompositionLocalProvider(LocalNarrowPane provides (maxWidth < 600.dp)) { InputSettingsPage({}) }
|
||||
} } } }
|
||||
compose.onNodeWithTag("osc-edit").performScrollTo().assertIsDisplayed()
|
||||
compose.onNodeWithTag("input-remap").performScrollTo().assertIsDisplayed().performClick()
|
||||
compose.onNodeWithTag("input-profile-desktop").performScrollTo().assertIsDisplayed().performClick()
|
||||
compose.onNodeWithTag("input-part-physical").performScrollTo().assertIsDisplayed().performClick()
|
||||
compose.onNodeWithTag("input-binding-a").performScrollTo().assertIsDisplayed().performClick()
|
||||
compose.onNodeWithTag("input-action-save").assertIsDisplayed()
|
||||
screenshot("phone-properties")
|
||||
@@ -75,10 +75,10 @@ class InputUiLayoutTest {
|
||||
}
|
||||
|
||||
@Test @Config(qualifiers = "w960dp-h600dp")
|
||||
fun largeScreenShowsTheControllerPageInTheExistingTheme() {
|
||||
fun largeScreenShowsTheProfileLibraryInTheExistingTheme() {
|
||||
compose.setContent { root = LocalView.current; DroidDeckTheme { Surface { InputSettingsPage({}) } } }
|
||||
compose.onNodeWithTag("osc-edit").assertIsDisplayed()
|
||||
screenshot("controller")
|
||||
compose.onNodeWithTag("input-profile-game").assertIsDisplayed()
|
||||
screenshot("profiles")
|
||||
}
|
||||
|
||||
@Test @Config(qualifiers = "w960dp-h600dp")
|
||||
@@ -108,11 +108,11 @@ class InputUiLayoutTest {
|
||||
}
|
||||
}
|
||||
compose.onNodeWithText(context.getString(R.string.setup_tab_controller)).performClick()
|
||||
compose.onNodeWithTag("osc-edit").assertIsDisplayed()
|
||||
compose.onAllNodesWithText(context.getString(R.string.osc_edit_layout)).assertCountEquals(1)
|
||||
compose.onNodeWithTag("input-profile-game").assertIsDisplayed()
|
||||
compose.onNodeWithText(context.getString(R.string.ctrl_layout)).assertDoesNotExist()
|
||||
screenshot("controller-tab")
|
||||
compose.onNodeWithTag("input-remap").performScrollTo().performClick()
|
||||
compose.onNodeWithTag("input-binding-a").assertExists()
|
||||
compose.onNodeWithTag("input-profile-game").performClick()
|
||||
compose.onNodeWithTag("input-part-physical").performScrollTo().performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.setup_tab_launcher)).assertIsDisplayed()
|
||||
screenshot("controller-physical")
|
||||
compose.runOnIdle { assertEquals(InputProfiles.AUTO, InputLibraries.read(context).selected) }
|
||||
|
||||
@@ -16,7 +16,6 @@ import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.ui.Modifier
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.input.ControllerPrefs
|
||||
import com.droiddeck.launcher.input.LegacyControllerPrefs
|
||||
import com.droiddeck.launcher.input.PadBridgeRoutingTest
|
||||
import com.droiddeck.launcher.input.PhysicalShortcuts
|
||||
import org.junit.Assert.*
|
||||
@@ -128,7 +127,7 @@ class PhysicalShortcutsDialogTest {
|
||||
}
|
||||
|
||||
@Test fun removalRestoresDefaultAndPreservesOtherAssignmentsAndControllerSettings() {
|
||||
LegacyControllerPrefs.setSelectSteam(context, true)
|
||||
ControllerPrefs.setSelectSteam(context, true)
|
||||
PhysicalShortcuts.assign(context, requireNotNull(PhysicalShortcuts.button(event(KeyEvent.KEYCODE_F1, KeyEvent.ACTION_DOWN))),
|
||||
PhysicalShortcuts.Action.STEAM)
|
||||
PhysicalShortcuts.assign(context, requireNotNull(PhysicalShortcuts.button(event(KeyEvent.KEYCODE_F2, KeyEvent.ACTION_DOWN))),
|
||||
|
||||
@@ -71,8 +71,11 @@ class SessionSecondScreenTest {
|
||||
|
||||
@Test fun steamMenuKeepsTheExistingTrackpadAndTerminal() = checkModes(steam = true)
|
||||
|
||||
@Test fun desktopQuickMenuChangesTheRunningDesktopLayout() = checkQuickSelection(steam = false, desktop = true, direct = true)
|
||||
|
||||
@Test fun steamQuickMenuLeavesTheDesktopSelectionAlone() = checkQuickSelection(steam = true, desktop = false, direct = false)
|
||||
|
||||
@Test fun directGameQuickMenuLeavesTheDesktopSelectionAlone() = checkQuickSelection(steam = false, desktop = false, direct = true)
|
||||
|
||||
@Test fun closingTheDockedDrawerKeepsTheSelectedControlsPanel() {
|
||||
SessionState.mode = SessionService.MODE_STEAM
|
||||
@@ -334,6 +337,43 @@ class SessionSecondScreenTest {
|
||||
compose.onNodeWithText(context.getString(R.string.mode_mic)).assertDoesNotExist()
|
||||
}
|
||||
|
||||
private fun checkQuickSelection(steam: Boolean, desktop: Boolean, direct: Boolean) {
|
||||
SessionState.mode = if (desktop) SessionService.MODE_DESKTOP else if (steam) SessionService.MODE_STEAM else SessionService.MODE_RUN
|
||||
val original = InputLibraries.update(context) { it.chooseLayout("desktop", InputRole.SECONDARY, InputLibraries.DECK) }
|
||||
val activity = Robolectric.buildActivity(SessionActivity::class.java).get()
|
||||
val display = activity.getSystemService(DisplayManager::class.java).getDisplay(Display.DEFAULT_DISPLAY)
|
||||
val panel = SecondScreenPresentation(activity, display, {}, {}, {})
|
||||
val open = androidx.compose.runtime.mutableStateOf(true)
|
||||
try {
|
||||
panel.show()
|
||||
panel.showMode(SecondScreenMode.CUSTOM_CONTROLS)
|
||||
compose.setContent {
|
||||
DroidDeckTheme {
|
||||
SessionDrawer(open.value, SessionDrawerPage.CONTROLLER, false, {},
|
||||
actions(steam, emptyList(), desktop = desktop, direct = direct,
|
||||
onInputSelection = { panel.refreshControls() }, onClose = { open.value = false }))
|
||||
}
|
||||
}
|
||||
compose.onNodeWithTag("setting-input-profile").performScrollTo().performClick()
|
||||
compose.onNodeWithText("Desktop").performScrollTo().performClick()
|
||||
compose.onNodeWithTag("input-profile-expand").performScrollTo().performClick()
|
||||
compose.onNodeWithTag("setting-input-part-SECONDARY").performScrollTo().performClick()
|
||||
compose.onNodeWithText("Trackpad + keyboard").performScrollTo().performClick()
|
||||
compose.onNode(hasContentDescription(context.getString(R.string.common_close)) and
|
||||
SemanticsMatcher.expectValue(androidx.compose.ui.semantics.SemanticsProperties.Role, androidx.compose.ui.semantics.Role.Button)).performClick()
|
||||
compose.runOnIdle {
|
||||
val updated = InputLibraries.read(context)
|
||||
assertEquals("desktop", updated.selection(desktop).profile)
|
||||
assertEquals(InputLibraries.TRACKPAD, updated.activeLayout(desktop, InputRole.SECONDARY)?.id)
|
||||
assertEquals(original.selection(!desktop), updated.selection(!desktop))
|
||||
assertEquals(original.profiles, updated.profiles)
|
||||
val controls = descendants(panel.window!!.decorView).filterIsInstance<InputSurfaceView>().single()
|
||||
val pads = descendants(controls).mapNotNull { it.tag as? InputSurfaceElement }.filter { it.kind == InputElementKind.TRACKPAD }.toList()
|
||||
assertEquals(1, pads.size)
|
||||
}
|
||||
} finally { panel.closeControls() }
|
||||
}
|
||||
|
||||
private fun checkModes(steam: Boolean) {
|
||||
SessionState.mode = if (steam) SessionService.MODE_STEAM else SessionService.MODE_DESKTOP
|
||||
val selected = mutableListOf<SecondScreenMode>()
|
||||
|
||||
@@ -1,350 +0,0 @@
|
||||
{
|
||||
"selections": {},
|
||||
"version": 14,
|
||||
"selected": "auto",
|
||||
"steam": "game",
|
||||
"desktop": "desktop",
|
||||
"profiles": [
|
||||
{
|
||||
"id": "game",
|
||||
"name": "Game",
|
||||
"base": "game",
|
||||
"parts": {
|
||||
"PHYSICAL": {"bindings": "game.physical"},
|
||||
"PRIMARY": {"bindings": "migrated.bindings.a2661227-4fb9-3bb6-912c-32cec93ecda2", "layout": "builtin.overlay"},
|
||||
"SECONDARY": {"bindings": "preset.deck", "layout": "builtin.deck"}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "desktop",
|
||||
"name": "Desktop",
|
||||
"base": "desktop",
|
||||
"parts": {
|
||||
"PHYSICAL": {"bindings": "desktop.physical"},
|
||||
"PRIMARY": {"bindings": "migrated.bindings.981daeb0-ccc6-3d40-88b7-c34b1fc35491", "layout": "builtin.overlay"},
|
||||
"SECONDARY": {"bindings": "preset.trackpad", "layout": "builtin.trackpad"}
|
||||
}
|
||||
}
|
||||
],
|
||||
"layouts": [
|
||||
{
|
||||
"id": "builtin.overlay",
|
||||
"name": "Gamepad",
|
||||
"template": "CUSTOM",
|
||||
"elements": [
|
||||
{"id": "legacy:up", "kind": "BUTTON", "control": "up", "name": "D-pad up", "x": 0.3682279586791992, "y": 0.46923303604125977, "width": 0.0935039296746254, "height": 0.16622920334339142, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "CIRCLE", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:right", "kind": "BUTTON", "control": "right", "name": "D-pad right", "x": 0.4461479187011719, "y": 0.6077573895454407, "width": 0.0935039296746254, "height": 0.16622920334339142, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "CIRCLE", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:down", "kind": "BUTTON", "control": "down", "name": "D-pad down", "x": 0.3682279586791992, "y": 0.7462816834449768, "width": 0.0935039296746254, "height": 0.16622920334339142, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "CIRCLE", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:left", "kind": "BUTTON", "control": "left", "name": "D-pad left", "x": 0.29030805826187134, "y": 0.6077573895454407, "width": 0.0935039296746254, "height": 0.16622920334339142, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "CIRCLE", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:ls", "kind": "STICK", "control": "ls", "name": "Left stick", "x": 0.12401574850082397, "y": 0.3353663980960846, "width": 0.1870078593492508, "height": 0.2659667432308197, "floating": true, "hideWhenIdle": true, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "CIRCLE", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:rs", "kind": "STICK", "control": "rs", "name": "Right stick", "x": 0.5102168917655945, "y": 0.5578886270523071, "width": 0.1870078593492508, "height": 0.2659667432308197, "floating": true, "hideWhenIdle": true, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "CIRCLE", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:a", "kind": "BUTTON", "control": "a", "name": "A", "x": 0.7170275449752808, "y": 0.5237594842910767, "width": 0.0935039296746254, "height": 0.16622920334339142, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "CIRCLE", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:b", "kind": "BUTTON", "control": "b", "name": "B", "x": 0.7949475049972534, "y": 0.38523516058921814, "width": 0.0935039296746254, "height": 0.16622920334339142, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "CIRCLE", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:x", "kind": "BUTTON", "control": "x", "name": "X", "x": 0.6391075849533081, "y": 0.38523516058921814, "width": 0.0935039296746254, "height": 0.16622920334339142, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "CIRCLE", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:y", "kind": "BUTTON", "control": "y", "name": "Y", "x": 0.7170275449752808, "y": 0.24671082198619843, "width": 0.0935039296746254, "height": 0.16622920334339142, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "CIRCLE", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:lb", "kind": "BUTTON", "control": "lb", "name": "L1", "x": 0.24559545516967773, "y": 0.0874890610575676, "width": 0.1084645614027977, "height": 0.1063866913318634, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "PILL", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:rb", "kind": "BUTTON", "control": "rb", "name": "R1", "x": 0.6459400057792664, "y": 0.0874890610575676, "width": 0.1084645614027977, "height": 0.1063866913318634, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "PILL", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:lt", "kind": "TRIGGER", "control": "lt", "name": "L2", "x": 0.11838088184595108, "y": 0.0874890610575676, "width": 0.1084645614027977, "height": 0.1063866913318634, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "PILL", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:rt", "kind": "TRIGGER", "control": "rt", "name": "R2", "x": 0.773154616355896, "y": 0.0874890610575676, "width": 0.1084645614027977, "height": 0.1063866913318634, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "PILL", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:select", "kind": "BUTTON", "control": "select", "name": "View / Select", "x": 0.40093502402305603, "y": 0.08527266979217529, "width": 0.06233595684170723, "height": 0.11081947386264801, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "CIRCLE", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:start", "kind": "BUTTON", "control": "start", "name": "Menu / Start", "x": 0.5367289781570435, "y": 0.08527266979217529, "width": 0.06233595684170723, "height": 0.11081947386264801, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "CIRCLE", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:guide", "kind": "BUTTON", "control": "guide", "name": "Steam / Guide", "x": 0.4220554232597351, "y": 0.02222222276031971, "width": 0.06856954842805862, "height": 0.12190141528844833, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "CIRCLE", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:qam", "kind": "BUTTON", "control": "qam", "name": "Quick access", "x": 0.5093749761581421, "y": 0.02222222276031971, "width": 0.06856954842805862, "height": 0.12190141528844833, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "CIRCLE", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "builtin:keyboard", "kind": "BUTTON", "control": "a", "name": "Keyboard", "x": 0.11249999701976776, "y": 0.855555534362793, "width": 0.05624999850988388, "height": 0.10000000149011612, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 1002, "image": "", "elementOpacity": 1, "buttonShape": "CIRCLE", "showLabel": true, "alwaysShown": false}
|
||||
],
|
||||
"tint": -15032321,
|
||||
"opacity": 100,
|
||||
"screen": "MAIN",
|
||||
"aspect": 1.7777777910232544,
|
||||
"scale": 1,
|
||||
"hidden": [],
|
||||
"origin": null
|
||||
},
|
||||
{
|
||||
"id": "builtin.deck",
|
||||
"name": "Deck grips + trackpads",
|
||||
"template": "CUSTOM",
|
||||
"elements": [
|
||||
{"id": "legacy:left-pad", "kind": "TRACKPAD", "control": "left-pad", "name": "Left trackpad", "x": 0.019999999552965164, "y": 0.019999999552965164, "width": 0.4699999988079071, "height": 0.7400000095367432, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "ROUNDED", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:right-pad", "kind": "TRACKPAD", "control": "right-pad", "name": "Right trackpad", "x": 0.5099999904632568, "y": 0.019999999552965164, "width": 0.4699999988079071, "height": 0.7400000095367432, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "ROUNDED", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:l4", "kind": "BUTTON", "control": "l4", "name": "L4", "x": 0.019999999552965164, "y": 0.7799999713897705, "width": 0.22499999403953552, "height": 0.20000000298023224, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "ROUNDED", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:l5", "kind": "BUTTON", "control": "l5", "name": "L5", "x": 0.26500001549720764, "y": 0.7799999713897705, "width": 0.22499999403953552, "height": 0.20000000298023224, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "ROUNDED", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:r5", "kind": "BUTTON", "control": "r5", "name": "R5", "x": 0.5099999904632568, "y": 0.7799999713897705, "width": 0.22499999403953552, "height": 0.20000000298023224, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "ROUNDED", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:r4", "kind": "BUTTON", "control": "r4", "name": "R4", "x": 0.7549999952316284, "y": 0.7799999713897705, "width": 0.22499999403953552, "height": 0.20000000298023224, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "ROUNDED", "showLabel": true, "alwaysShown": false}
|
||||
],
|
||||
"tint": null,
|
||||
"opacity": 100,
|
||||
"screen": "SECONDARY",
|
||||
"aspect": 0,
|
||||
"scale": 1,
|
||||
"hidden": [],
|
||||
"origin": null
|
||||
},
|
||||
{
|
||||
"id": "builtin.trackpad",
|
||||
"name": "Trackpad + keyboard",
|
||||
"template": "CUSTOM",
|
||||
"elements": [
|
||||
{"id": "legacy:right-pad", "kind": "TRACKPAD", "control": "right-pad", "name": "Right trackpad", "x": 0.019999999552965164, "y": 0.019999999552965164, "width": 0.9599999785423279, "height": 0.9599999785423279, "floating": true, "hideWhenIdle": false, "mouseGestures": true, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "ROUNDED", "showLabel": true, "alwaysShown": false}
|
||||
],
|
||||
"tint": null,
|
||||
"opacity": 100,
|
||||
"screen": "SECONDARY",
|
||||
"aspect": 0,
|
||||
"scale": 1,
|
||||
"hidden": [],
|
||||
"origin": null
|
||||
},
|
||||
{
|
||||
"id": "builtin.deck.gamepad",
|
||||
"name": "Deck gamepad",
|
||||
"template": "CUSTOM",
|
||||
"elements": [
|
||||
{"id": "legacy:lt", "kind": "TRIGGER", "control": "lt", "name": "L2", "x": 0.019999999552965164, "y": 0.019999999552965164, "width": 0.20000000298023224, "height": 0.11999999731779099, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "PILL", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:lb", "kind": "BUTTON", "control": "lb", "name": "L1", "x": 0.23999999463558197, "y": 0.019999999552965164, "width": 0.20000000298023224, "height": 0.11999999731779099, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "PILL", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:rb", "kind": "BUTTON", "control": "rb", "name": "R1", "x": 0.5600000023841858, "y": 0.019999999552965164, "width": 0.20000000298023224, "height": 0.11999999731779099, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "PILL", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:rt", "kind": "TRIGGER", "control": "rt", "name": "R2", "x": 0.7799999713897705, "y": 0.019999999552965164, "width": 0.20000000298023224, "height": 0.11999999731779099, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "PILL", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:ls", "kind": "STICK", "control": "ls", "name": "Left stick", "x": 0.019999999552965164, "y": 0.17000000178813934, "width": 0.4000000059604645, "height": 0.4000000059604645, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "ROUNDED", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:right-pad", "kind": "TRACKPAD", "control": "right-pad", "name": "Right trackpad", "x": 0.5799999833106995, "y": 0.5899999737739563, "width": 0.4000000059604645, "height": 0.38999998569488525, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "ROUNDED", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:up", "kind": "BUTTON", "control": "up", "name": "D-pad up", "x": 0.14000000059604645, "y": 0.6000000238418579, "width": 0.11999999731779099, "height": 0.11999999731779099, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "CIRCLE", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:left", "kind": "BUTTON", "control": "left", "name": "D-pad left", "x": 0.029999999329447746, "y": 0.7300000190734863, "width": 0.11999999731779099, "height": 0.11999999731779099, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "CIRCLE", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:right", "kind": "BUTTON", "control": "right", "name": "D-pad right", "x": 0.25, "y": 0.7300000190734863, "width": 0.11999999731779099, "height": 0.11999999731779099, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "CIRCLE", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:down", "kind": "BUTTON", "control": "down", "name": "D-pad down", "x": 0.14000000059604645, "y": 0.8600000143051147, "width": 0.11999999731779099, "height": 0.11999999731779099, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "CIRCLE", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:y", "kind": "BUTTON", "control": "y", "name": "Y", "x": 0.7200000286102295, "y": 0.17000000178813934, "width": 0.11999999731779099, "height": 0.11999999731779099, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "CIRCLE", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:x", "kind": "BUTTON", "control": "x", "name": "X", "x": 0.6100000143051147, "y": 0.30000001192092896, "width": 0.11999999731779099, "height": 0.11999999731779099, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "CIRCLE", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:b", "kind": "BUTTON", "control": "b", "name": "B", "x": 0.8299999833106995, "y": 0.30000001192092896, "width": 0.11999999731779099, "height": 0.11999999731779099, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "CIRCLE", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:a", "kind": "BUTTON", "control": "a", "name": "A", "x": 0.7200000286102295, "y": 0.4300000071525574, "width": 0.11999999731779099, "height": 0.11999999731779099, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "CIRCLE", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:select", "kind": "BUTTON", "control": "select", "name": "View / Select", "x": 0.41999998688697815, "y": 0.30000001192092896, "width": 0.07000000029802322, "height": 0.10000000149011612, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "PILL", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:start", "kind": "BUTTON", "control": "start", "name": "Menu / Start", "x": 0.5099999904632568, "y": 0.30000001192092896, "width": 0.07000000029802322, "height": 0.10000000149011612, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "PILL", "showLabel": true, "alwaysShown": false}
|
||||
],
|
||||
"tint": null,
|
||||
"opacity": 100,
|
||||
"screen": "SECONDARY",
|
||||
"aspect": 0,
|
||||
"scale": 1,
|
||||
"hidden": [],
|
||||
"origin": null
|
||||
},
|
||||
{
|
||||
"id": "builtin.deck.grips",
|
||||
"name": "Deck grips",
|
||||
"template": "CUSTOM",
|
||||
"elements": [
|
||||
{"id": "legacy:l4", "kind": "BUTTON", "control": "l4", "name": "L4", "x": 0.019999999552965164, "y": 0.019999999552965164, "width": 0.4699999988079071, "height": 0.4699999988079071, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "ROUNDED", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:l5", "kind": "BUTTON", "control": "l5", "name": "L5", "x": 0.019999999552965164, "y": 0.5099999904632568, "width": 0.4699999988079071, "height": 0.4699999988079071, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "ROUNDED", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:r4", "kind": "BUTTON", "control": "r4", "name": "R4", "x": 0.5099999904632568, "y": 0.019999999552965164, "width": 0.4699999988079071, "height": 0.4699999988079071, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "ROUNDED", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:r5", "kind": "BUTTON", "control": "r5", "name": "R5", "x": 0.5099999904632568, "y": 0.5099999904632568, "width": 0.4699999988079071, "height": 0.4699999988079071, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "ROUNDED", "showLabel": true, "alwaysShown": false}
|
||||
],
|
||||
"tint": null,
|
||||
"opacity": 100,
|
||||
"screen": "SECONDARY",
|
||||
"aspect": 0,
|
||||
"scale": 1,
|
||||
"hidden": [],
|
||||
"origin": null
|
||||
},
|
||||
{
|
||||
"id": "builtin.deck.left",
|
||||
"name": "Deck left trackpad",
|
||||
"template": "CUSTOM",
|
||||
"elements": [
|
||||
{"id": "legacy:left-pad", "kind": "TRACKPAD", "control": "left-pad", "name": "Left trackpad", "x": 0.019999999552965164, "y": 0.019999999552965164, "width": 0.9599999785423279, "height": 0.7400000095367432, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "ROUNDED", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:left-click", "kind": "BUTTON", "control": "left-click", "name": "Left trackpad click", "x": 0.019999999552965164, "y": 0.7799999713897705, "width": 0.9599999785423279, "height": 0.20000000298023224, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "ROUNDED", "showLabel": true, "alwaysShown": false}
|
||||
],
|
||||
"tint": null,
|
||||
"opacity": 100,
|
||||
"screen": "SECONDARY",
|
||||
"aspect": 0,
|
||||
"scale": 1,
|
||||
"hidden": [],
|
||||
"origin": null
|
||||
},
|
||||
{
|
||||
"id": "builtin.deck.right",
|
||||
"name": "Deck right trackpad",
|
||||
"template": "CUSTOM",
|
||||
"elements": [
|
||||
{"id": "legacy:right-pad", "kind": "TRACKPAD", "control": "right-pad", "name": "Right trackpad", "x": 0.019999999552965164, "y": 0.019999999552965164, "width": 0.9599999785423279, "height": 0.7400000095367432, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "ROUNDED", "showLabel": true, "alwaysShown": false},
|
||||
{"id": "legacy:right-click", "kind": "BUTTON", "control": "right-click", "name": "Right trackpad click", "x": 0.019999999552965164, "y": 0.7799999713897705, "width": 0.9599999785423279, "height": 0.20000000298023224, "floating": true, "hideWhenIdle": false, "mouseGestures": false, "toggle": false, "icon": 0, "image": "", "elementOpacity": 1, "buttonShape": "ROUNDED", "showLabel": true, "alwaysShown": false}
|
||||
],
|
||||
"tint": null,
|
||||
"opacity": 100,
|
||||
"screen": "SECONDARY",
|
||||
"aspect": 0,
|
||||
"scale": 1,
|
||||
"hidden": [],
|
||||
"origin": null
|
||||
}
|
||||
],
|
||||
"bindings": [
|
||||
{
|
||||
"id": "preset.deck",
|
||||
"name": "Deck grips + trackpads",
|
||||
"physical": false,
|
||||
"layout": "builtin.deck",
|
||||
"controls": {},
|
||||
"elements": {},
|
||||
"keys": [],
|
||||
"clicks": {}
|
||||
},
|
||||
{
|
||||
"id": "preset.trackpad",
|
||||
"name": "Trackpad + keyboard",
|
||||
"physical": false,
|
||||
"layout": "builtin.trackpad",
|
||||
"controls": {
|
||||
"ls": {"type": "pointer", "speed": 900},
|
||||
"rs": {"type": "scroll", "speed": 10, "horizontal": false},
|
||||
"a": {"type": "button", "code": 272},
|
||||
"b": {"type": "button", "code": 273},
|
||||
"x": {"type": "keys", "codes": [28]},
|
||||
"y": {"type": "keys", "codes": [1]},
|
||||
"up": {"type": "keys", "codes": [103]},
|
||||
"right": {"type": "keys", "codes": [106]},
|
||||
"down": {"type": "keys", "codes": [108]},
|
||||
"left": {"type": "keys", "codes": [105]},
|
||||
"lt": {"type": "button", "code": 273},
|
||||
"rt": {"type": "button", "code": 272},
|
||||
"lb": {"type": "keys", "codes": [29]},
|
||||
"rb": {"type": "keys", "codes": [56]},
|
||||
"select": {"type": "command", "command": "KEYBOARD"},
|
||||
"start": {"type": "command", "command": "MENU"},
|
||||
"left-pad": {"type": "scroll", "speed": 10, "horizontal": false},
|
||||
"right-pad": {"type": "pointer", "speed": 900},
|
||||
"left-click": {"type": "button", "code": 273},
|
||||
"right-click": {"type": "button", "code": 272}
|
||||
},
|
||||
"elements": {
|
||||
"legacy:right-pad": {"type": "pointer", "speed": 900}
|
||||
},
|
||||
"keys": [],
|
||||
"clicks": {
|
||||
"legacy:right-pad": {"type": "button", "code": 272}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "preset.deck.gamepad",
|
||||
"name": "Deck gamepad",
|
||||
"physical": false,
|
||||
"layout": "builtin.deck.gamepad",
|
||||
"controls": {},
|
||||
"elements": {},
|
||||
"keys": [],
|
||||
"clicks": {}
|
||||
},
|
||||
{
|
||||
"id": "preset.deck.grips",
|
||||
"name": "Deck grips",
|
||||
"physical": false,
|
||||
"layout": "builtin.deck.grips",
|
||||
"controls": {},
|
||||
"elements": {},
|
||||
"keys": [],
|
||||
"clicks": {}
|
||||
},
|
||||
{
|
||||
"id": "preset.deck.left",
|
||||
"name": "Deck left trackpad",
|
||||
"physical": false,
|
||||
"layout": "builtin.deck.left",
|
||||
"controls": {},
|
||||
"elements": {},
|
||||
"keys": [],
|
||||
"clicks": {}
|
||||
},
|
||||
{
|
||||
"id": "preset.deck.right",
|
||||
"name": "Deck right trackpad",
|
||||
"physical": false,
|
||||
"layout": "builtin.deck.right",
|
||||
"controls": {},
|
||||
"elements": {},
|
||||
"keys": [],
|
||||
"clicks": {}
|
||||
},
|
||||
{
|
||||
"id": "game.physical",
|
||||
"name": "Game / physical",
|
||||
"physical": true,
|
||||
"controls": {},
|
||||
"elements": {},
|
||||
"keys": [],
|
||||
"clicks": {}
|
||||
},
|
||||
{
|
||||
"id": "desktop.physical",
|
||||
"name": "Desktop / physical",
|
||||
"physical": true,
|
||||
"controls": {
|
||||
"ls": {"type": "pointer", "speed": 900},
|
||||
"rs": {"type": "scroll", "speed": 10, "horizontal": false},
|
||||
"a": {"type": "button", "code": 272},
|
||||
"b": {"type": "button", "code": 273},
|
||||
"x": {"type": "keys", "codes": [28]},
|
||||
"y": {"type": "keys", "codes": [1]},
|
||||
"up": {"type": "keys", "codes": [103]},
|
||||
"right": {"type": "keys", "codes": [106]},
|
||||
"down": {"type": "keys", "codes": [108]},
|
||||
"left": {"type": "keys", "codes": [105]},
|
||||
"lt": {"type": "button", "code": 273},
|
||||
"rt": {"type": "button", "code": 272},
|
||||
"lb": {"type": "keys", "codes": [29]},
|
||||
"rb": {"type": "keys", "codes": [56]},
|
||||
"select": {"type": "command", "command": "KEYBOARD"},
|
||||
"start": {"type": "command", "command": "MENU"},
|
||||
"left-pad": {"type": "scroll", "speed": 10, "horizontal": false},
|
||||
"right-pad": {"type": "pointer", "speed": 900},
|
||||
"left-click": {"type": "button", "code": 273},
|
||||
"right-click": {"type": "button", "code": 272}
|
||||
},
|
||||
"elements": {},
|
||||
"keys": [],
|
||||
"clicks": {}
|
||||
},
|
||||
{
|
||||
"id": "migrated.bindings.a2661227-4fb9-3bb6-912c-32cec93ecda2",
|
||||
"name": "Game / primary",
|
||||
"physical": false,
|
||||
"layout": "builtin.overlay",
|
||||
"controls": {},
|
||||
"elements": {
|
||||
"builtin:keyboard": {"type": "command", "command": "KEYBOARD"}
|
||||
},
|
||||
"keys": [],
|
||||
"clicks": {}
|
||||
},
|
||||
{
|
||||
"id": "migrated.bindings.981daeb0-ccc6-3d40-88b7-c34b1fc35491",
|
||||
"name": "Desktop / primary",
|
||||
"physical": false,
|
||||
"layout": "builtin.overlay",
|
||||
"controls": {
|
||||
"ls": {"type": "pointer", "speed": 900},
|
||||
"rs": {"type": "scroll", "speed": 10, "horizontal": false},
|
||||
"a": {"type": "button", "code": 272},
|
||||
"b": {"type": "button", "code": 273},
|
||||
"x": {"type": "keys", "codes": [28]},
|
||||
"y": {"type": "keys", "codes": [1]},
|
||||
"up": {"type": "keys", "codes": [103]},
|
||||
"right": {"type": "keys", "codes": [106]},
|
||||
"down": {"type": "keys", "codes": [108]},
|
||||
"left": {"type": "keys", "codes": [105]},
|
||||
"lt": {"type": "button", "code": 273},
|
||||
"rt": {"type": "button", "code": 272},
|
||||
"lb": {"type": "keys", "codes": [29]},
|
||||
"rb": {"type": "keys", "codes": [56]},
|
||||
"select": {"type": "command", "command": "KEYBOARD"},
|
||||
"start": {"type": "command", "command": "MENU"},
|
||||
"left-pad": {"type": "scroll", "speed": 10, "horizontal": false},
|
||||
"right-pad": {"type": "pointer", "speed": 900},
|
||||
"left-click": {"type": "button", "code": 273},
|
||||
"right-click": {"type": "button", "code": 272}
|
||||
},
|
||||
"elements": {
|
||||
"builtin:keyboard": {"type": "command", "command": "KEYBOARD"}
|
||||
},
|
||||
"keys": [],
|
||||
"clicks": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in new issue
Block a user