mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 05:16:01 +00:00
Fix desktop profile selection and simplify default touch layouts
This commit is contained in:
1 parent
08526f8283
commit
c2d7765619
16 files changed
+265
-88
No files matched your search
@@ -0,0 +1,36 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.graphics.Paint
|
||||
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 org.robolectric.annotation.GraphicsMode
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [34])
|
||||
@GraphicsMode(GraphicsMode.Mode.NATIVE)
|
||||
class InputButtonIconsTest {
|
||||
@Test fun commandSymbolsRenderUsingTheButtonTintAndHaveReadableNames() {
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
for (code in listOf(InputButtonIcons.MENU, InputButtonIcons.KEYBOARD, InputButtonIcons.STEAM, InputButtonIcons.QUICK_ACCESS)) {
|
||||
val drawable = InputButtonIcons.drawable(context, code)
|
||||
assertNotNull(drawable)
|
||||
assertNotEquals(code.toString(), InputButtonIcons.label(context, code))
|
||||
val bitmap = Bitmap.createBitmap(64, 64, Bitmap.Config.ARGB_8888)
|
||||
try {
|
||||
val paint = Paint(Paint.ANTI_ALIAS_FLAG).apply { color = Color.GREEN }
|
||||
assertTrue(InputButtonIcons.draw(Canvas(bitmap), code, 32f, 32f, 48f, paint, drawable))
|
||||
val pixels = IntArray(64 * 64)
|
||||
bitmap.getPixels(pixels, 0, 64, 0, 0, 64, 64)
|
||||
assertTrue(pixels.count { Color.alpha(it) > 0 } > 30)
|
||||
assertTrue(pixels.filter { Color.alpha(it) > 0 }.all { Color.green(it) > 0 && Color.red(it) == 0 && Color.blue(it) == 0 })
|
||||
} finally { bitmap.recycle() }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,69 @@ class InputLibraryTest {
|
||||
for (name in listOf("input-profiles", "input-surfaces", "controller")) context.getSharedPreferences(name, Context.MODE_PRIVATE).edit().clear().commit()
|
||||
}
|
||||
|
||||
@Test fun freshLibraryHasOnlyTheMainGamepadAndTwoLowerScreenLayouts() {
|
||||
val library = InputLibraries.read(context)
|
||||
assertEquals(listOf("game", "desktop"), library.profiles.map { it.id })
|
||||
assertEquals(setOf(InputLibraries.OVERLAY, InputLibraries.DECK, InputLibraries.TRACKPAD), library.layouts.map { it.id }.toSet())
|
||||
assertEquals(6, library.bindings.size)
|
||||
assertEquals(InputLibraries.DECK, library.activeLayout(false, InputRole.SECONDARY)?.id)
|
||||
assertEquals(InputLibraries.TRACKPAD, library.activeLayout(true, InputRole.SECONDARY)?.id)
|
||||
assertEquals(InputAction.Pointer(), library.compileActive(true).action(InputRole.PHYSICAL, InputControl.LS))
|
||||
assertEquals(InputAction.Native(), library.compileActive(false).action(InputRole.PHYSICAL, InputControl.LS))
|
||||
|
||||
val desktop = library.activeLayout(true, InputRole.SECONDARY)!!
|
||||
val pad = desktop.elements.single { it.kind == InputElementKind.TRACKPAD }
|
||||
assertTrue(pad.mouseGestures)
|
||||
assertEquals(3, desktop.elements.size)
|
||||
assertEquals(InputAction.Pointer(), library.compileActive(true).elementAction(InputRole.SECONDARY, pad.id, pad.control))
|
||||
assertEquals(InputAction.MouseButton(272), library.compileActive(true).elementClickAction(InputRole.SECONDARY, pad))
|
||||
val game = library.activeLayout(false, InputRole.SECONDARY)!!
|
||||
assertEquals(9, game.elements.size)
|
||||
assertEquals(setOf(InputControl.LEFT_PAD, InputControl.RIGHT_PAD), game.elements.filter { it.kind == InputElementKind.TRACKPAD }.map { it.control }.toSet())
|
||||
for (control in listOf(InputControl.L4, InputControl.L5, InputControl.R4, InputControl.R5)) {
|
||||
val element = game.elements.single { it.control == control }
|
||||
assertEquals(InputAction.Native(), library.compileActive(false).elementAction(InputRole.SECONDARY, element.id, element.control))
|
||||
}
|
||||
for ((isDesktop, commands) in listOf(true to listOf(InputCommand.MENU, InputCommand.KEYBOARD),
|
||||
false to listOf(InputCommand.STEAM, InputCommand.QUICK_ACCESS, InputCommand.MENU))) {
|
||||
val elements = library.activeLayout(isDesktop, InputRole.SECONDARY)!!.elements.filter { it.id.startsWith("command:") }
|
||||
assertEquals(commands.map { InputAction.Command(it) }, elements.map { library.compileActive(isDesktop).elementAction(InputRole.SECONDARY, it.id, it.control) })
|
||||
assertTrue(elements.all { InputButtonIcons.has(it.icon) && it.icon > 255 })
|
||||
}
|
||||
assertEquals(library, InputLibraries.decode(InputLibraries.encode(library)))
|
||||
}
|
||||
|
||||
@Test fun legacyLowerScreenBindingsKeepTheirOriginalControlsWithoutSavedGeometry() {
|
||||
prefs.edit().putBoolean("migrated", true).putString("profile.game",
|
||||
"""{"version":1,"bindings":[{"role":"SECONDARY","control":"a","action":{"type":"keys","codes":[57]}}]}""").commit()
|
||||
val library = InputLibraries.read(context)
|
||||
assertEquals(InputSurfaceLayout.defaults(), library.layout("game", InputRole.SECONDARY)?.elements)
|
||||
assertEquals(InputAction.Keys(listOf(57)), library.compile("game").elementAction(InputRole.SECONDARY, "legacy:a", InputControl.A))
|
||||
}
|
||||
|
||||
@Test fun existingLibrariesKeepTheirSavedLayoutsBindingsAndSelections() {
|
||||
var original = InputLibraries.read(context).duplicateProfile("desktop", "Browser", "browser")
|
||||
val layout = SavedInputLayout("builtin.left-pad", "My left pad", InputSurfaceLayout.defaults(), screen = InputLayoutScreen.SECONDARY)
|
||||
original = original.withLayout(layout).withPreset(SavedInputBindings("preset.left-pad", "My left pad", false, layout.id,
|
||||
controls = mapOf(InputControl.LEFT_PAD to InputAction.Pointer(700f))))
|
||||
.selectProfile(true, "browser").selectPart(true, InputRole.SECONDARY, "preset.left-pad").validate()
|
||||
val raw = org.json.JSONObject(InputLibraries.encode(original)).put("version", 6).toString()
|
||||
prefs.edit().putString("library", raw).commit()
|
||||
assertEquals(original, InputLibraries.read(context))
|
||||
assertEquals(original, InputLibraries.read(context))
|
||||
}
|
||||
|
||||
@Test fun resettingDefaultActionsKeepsTheMenuAndKeyboardCommands() {
|
||||
val library = InputLibraries.read(context)
|
||||
for (id in listOf("game", "desktop")) {
|
||||
val reset = library.resetProfile(id).validate()
|
||||
for (element in library.layout(id, InputRole.SECONDARY)!!.elements.filter { it.id.startsWith("command:") }) {
|
||||
assertEquals(library.compile(id).elementAction(InputRole.SECONDARY, element.id, element.control),
|
||||
reset.compile(id).elementAction(InputRole.SECONDARY, element.id, element.control))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun migrationPreservesExistingBindingsGeometryAndActiveSelection() {
|
||||
prefs.edit().putString("selected", "desktop").putBoolean("migrated", true)
|
||||
.putString("profile.desktop", """{"version":1,"bindings":[{"role":"PHYSICAL","control":"a","action":{"type":"keys","codes":[29,33]}}]}""").commit()
|
||||
@@ -238,10 +301,10 @@ class InputLibraryTest {
|
||||
}
|
||||
|
||||
@Test fun activeQuickPartsCannotBeDeletedAndInvalidCombinationsAreRejected() {
|
||||
val library = InputLibraries.read(context).selectPart(false, InputRole.SECONDARY, InputStockLayouts.RIGHT)
|
||||
assertThrows(IllegalArgumentException::class.java) { library.removeBindings(InputStockLayouts.RIGHT) }
|
||||
assertThrows(IllegalArgumentException::class.java) { library.removeLayout("builtin.right-pad") }
|
||||
assertThrows(IllegalArgumentException::class.java) { library.selectPart(false, InputRole.PHYSICAL, InputStockLayouts.RIGHT).validate() }
|
||||
val library = InputLibraries.read(context).selectPart(false, InputRole.SECONDARY, InputStockLayouts.TRACKPAD)
|
||||
assertThrows(IllegalArgumentException::class.java) { library.removeBindings(InputStockLayouts.TRACKPAD) }
|
||||
assertThrows(IllegalArgumentException::class.java) { library.removeLayout(InputLibraries.TRACKPAD) }
|
||||
assertThrows(IllegalArgumentException::class.java) { library.selectPart(false, InputRole.PHYSICAL, InputStockLayouts.TRACKPAD).validate() }
|
||||
assertThrows(IllegalArgumentException::class.java) { library.selectProfile(false, "missing").validate() }
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,11 @@ 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(mapOf(InputRole.PRIMARY to mapOf("builtin:keyboard" to InputAction.Command(InputCommand.KEYBOARD))), profile.elements)
|
||||
assertEquals(mapOf(
|
||||
InputRole.PRIMARY to mapOf("builtin:keyboard" to InputAction.Command(InputCommand.KEYBOARD)),
|
||||
InputRole.SECONDARY to mapOf("command:0" to InputAction.Command(InputCommand.MENU),
|
||||
"command:2" to InputAction.Command(InputCommand.STEAM), "command:3" to InputAction.Command(InputCommand.QUICK_ACCESS)),
|
||||
), profile.elements)
|
||||
}
|
||||
|
||||
@Test fun layoutsPersistIndependentOfBindingsAndStayInsideScreen() {
|
||||
|
||||
@@ -36,6 +36,20 @@ class InputSettingsTest {
|
||||
context.getSharedPreferences("controller", Context.MODE_PRIVATE).edit().clear().commit()
|
||||
}
|
||||
|
||||
@Test fun commandSymbolsAreSelectableForAnyCustomButton() {
|
||||
val element = mutableStateOf(InputSurfaceElement(InputControl.A, .1f, .1f, .2f, .2f, name = "Custom button"))
|
||||
compose.setContent { DroidDeckTheme {
|
||||
androidx.compose.foundation.layout.Column { InputElementProperties(element.value) { element.value = it } }
|
||||
} }
|
||||
var current = context.getString(R.string.input_button_text)
|
||||
for (code in listOf(InputButtonIcons.MENU, InputButtonIcons.KEYBOARD, InputButtonIcons.STEAM, InputButtonIcons.QUICK_ACCESS)) {
|
||||
compose.onNodeWithText(current).performClick()
|
||||
current = InputButtonIcons.label(context, code)
|
||||
compose.onNodeWithText(current).performScrollTo().performClick()
|
||||
compose.runOnIdle { assertEquals(code, element.value.icon) }
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun steamAndDesktopQuickSettingsOpenTheSameInputLibrary() {
|
||||
val mode = mutableStateOf(SessionService.MODE_STEAM)
|
||||
var opened = 0
|
||||
@@ -63,10 +77,10 @@ class InputSettingsTest {
|
||||
compose.onNodeWithTag("setting-input-part-PHYSICAL").assertExists()
|
||||
compose.onNodeWithTag("setting-input-part-PRIMARY").assertExists()
|
||||
compose.onNodeWithTag("setting-input-part-SECONDARY").performClick()
|
||||
compose.onNodeWithText("Left Deck trackpad").performScrollTo().performClick()
|
||||
compose.onNodeWithText("Deck grips + trackpads").performScrollTo().performClick()
|
||||
compose.runOnIdle {
|
||||
val changed = InputLibraries.read(context)
|
||||
assertEquals(InputStockLayouts.LEFT, changed.activePart(true, InputRole.SECONDARY).bindings)
|
||||
assertEquals(InputStockLayouts.DECK, changed.activePart(true, InputRole.SECONDARY).bindings)
|
||||
assertEquals(original.profiles, changed.profiles)
|
||||
assertEquals(original.compileActive(false), changed.compileActive(false))
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.droiddeck.launcher.session.SessionState
|
||||
import org.junit.After
|
||||
import com.droiddeck.launcher.input.InputLibraries
|
||||
import com.droiddeck.launcher.input.InputRole
|
||||
import com.droiddeck.launcher.input.InputElementKind
|
||||
import com.droiddeck.launcher.input.InputSurfaceElement
|
||||
import com.droiddeck.launcher.input.InputSurfaceStyle
|
||||
import com.droiddeck.launcher.input.InputControl
|
||||
@@ -70,6 +71,12 @@ 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
|
||||
var closes = 0
|
||||
@@ -301,6 +308,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>()
|
||||
@@ -325,9 +369,11 @@ class SessionSecondScreenTest {
|
||||
|
||||
private fun actions(steam: Boolean, displays: List<SecondScreenDisplay>,
|
||||
micAvailable: Boolean = false, micEnabled: Boolean = false, onMic: (Boolean) -> Unit = {},
|
||||
desktop: Boolean = !steam, direct: Boolean = false, onInputSelection: (InputRole?) -> Unit = {},
|
||||
onClose: () -> Unit = {},
|
||||
select: (SecondScreenMode) -> Unit = {}) =
|
||||
DrawerActions(steam = steam, isHomeApp = false, androidApps = emptyList(), hudOn = false,
|
||||
DrawerActions(steam = steam, desktop = desktop, direct = direct, onInputSelection = onInputSelection,
|
||||
isHomeApp = false, androidApps = emptyList(), hudOn = false,
|
||||
micAvailable = micAvailable, micEnabled = micEnabled, onMicEnabled = onMic,
|
||||
frameGen = FrameGen.Mode.OFF, lossless = Lossless.State.NONE, oscMode = "never",
|
||||
onScreenButtonsVisible = false, suspendPolicy = "auto", backActionsInverted = false,
|
||||
|
||||
Reference in new issue
Block a user