mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 20:45:43 +00:00
Default to visible sticks and add live on-screen controls opacity (#3662)
Keep existing settings and touch targets unchanged. Let users dim the touch controls from 100 to 10 percent.
This commit is contained in:
1 parent
2aad4fbb1b
commit
ebb3bb6373
6 files changed
+110
-15
No files matched your search
@@ -993,6 +993,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
openDeckRing("activity created")
|
||||
bridge.setOnPlayerInput(::onPadInput)
|
||||
onScreenControls = OnScreenControls(this, bridge).also { controls ->
|
||||
controls.alpha = onScreenOpacityAlpha()
|
||||
controls.updateLayout(primaryInputLayout)
|
||||
controls.onTouchMiss = miss@{ event ->
|
||||
if (!gestureTouchStreamGate.accepts(GestureTouchStreamGate.Source.ON_SCREEN_CONTROLS, event)) return@miss
|
||||
@@ -1907,6 +1908,11 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
onWowChat = wowChat::choose,
|
||||
controller = controllerSettings,
|
||||
onControllerSize = { percent -> updateControllerPrefs { ControllerPrefs.setSize(this@SessionActivity, percent) } },
|
||||
onControllerOpacity = { percent ->
|
||||
ControllerPrefs.setOnScreenOpacity(this@SessionActivity, percent)
|
||||
controllerSettings = ControllerPrefs.read(this@SessionActivity)
|
||||
applyOnScreenOpacity()
|
||||
},
|
||||
onRumble = { on -> updateControllerPrefs { ControllerPrefs.setRumble(this@SessionActivity, on) } },
|
||||
onSteamMenu = if (SessionState.mode == SessionService.MODE_STEAM) ({ sendSteamGuide() }) else null,
|
||||
onQam = if (SessionState.mode == SessionService.MODE_STEAM) ({ triggerSteamQam() }) else null,
|
||||
@@ -2265,6 +2271,18 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
if (fieldKeyboardOnPrimary) hidePrimaryKeyboard()
|
||||
}
|
||||
|
||||
private fun onScreenOpacityAlpha() = ControllerPrefs.onScreenOpacity(this) / 100f
|
||||
|
||||
private fun applyOnScreenOpacity() {
|
||||
val alpha = onScreenOpacityAlpha()
|
||||
onScreenControls?.alpha = alpha
|
||||
bottomInputControls?.alpha = alpha
|
||||
unfoldedColumn?.alpha = alpha
|
||||
swappedInputSurface?.alpha = alpha
|
||||
secondScreenPresentation?.controlsView?.alpha = alpha
|
||||
steamTouchControls?.let { it.alpha = if (it.isEditing) 1f else alpha }
|
||||
}
|
||||
|
||||
private fun updateControllerPrefs(change: () -> Unit) {
|
||||
change()
|
||||
controllerSettings = ControllerPrefs.read(this)
|
||||
@@ -5135,6 +5153,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
if (panel == null) {
|
||||
panel = OnScreenControls(this, padBridge, dock).also { it.updateLayout(primaryInputLayout) }
|
||||
val column = android.widget.LinearLayout(this).apply {
|
||||
alpha = onScreenOpacityAlpha()
|
||||
orientation = android.widget.LinearLayout.VERTICAL
|
||||
addView(panel, android.widget.LinearLayout.LayoutParams(android.widget.LinearLayout.LayoutParams.MATCH_PARENT, 0, 1f))
|
||||
unfoldedKeys = com.droiddeck.launcher.ui.padKeysView(
|
||||
@@ -5980,7 +5999,11 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
val view = com.droiddeck.launcher.input.SteamTouchControls(this, device,
|
||||
onMenu = { drawerOpen = true }, onKeyboard = ::togglePcKeyboard)
|
||||
view.visibility = View.GONE
|
||||
view.onEditingChanged = { touchEditorChanged() }
|
||||
view.alpha = onScreenOpacityAlpha()
|
||||
view.onEditingChanged = { editing ->
|
||||
view.alpha = if (editing) 1f else onScreenOpacityAlpha()
|
||||
touchEditorChanged()
|
||||
}
|
||||
view.onOptions = { options ->
|
||||
steamTouchOptions = options
|
||||
applyTouchRouting()
|
||||
@@ -6085,6 +6108,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
if (bottom?.parent !== bottomRoot) {
|
||||
(bottom?.parent as? android.view.ViewGroup)?.removeView(bottom)
|
||||
bottom = OnScreenControls(bottomRoot.context, padBridge).also { view ->
|
||||
view.alpha = onScreenOpacityAlpha()
|
||||
view.onTouchMiss = { event -> onBottomGameTouch(event) }
|
||||
bottomRoot.addView(view, android.view.ViewGroup.LayoutParams(-1, -1))
|
||||
}
|
||||
@@ -6528,6 +6552,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
joyConVr?.refresh()
|
||||
onScreenControls?.reload()
|
||||
controllerSettings = ControllerPrefs.read(this)
|
||||
applyOnScreenOpacity()
|
||||
resumed = true
|
||||
boostGpuClock(panelOverGame)
|
||||
updateKeyboardRoute()
|
||||
@@ -7036,7 +7061,10 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
androidx.compose.runtime.key(profileLayout) {
|
||||
androidx.compose.ui.viewinterop.AndroidView(
|
||||
factory = { context -> com.droiddeck.launcher.ui.InputSurfaceView(context, padBridge, profileLayout?.elements.orEmpty(),
|
||||
surfaceStyle = profileLayout?.style ?: com.droiddeck.launcher.input.InputSurfaceStyle()).also { swappedInputSurface = it } },
|
||||
surfaceStyle = profileLayout?.style ?: com.droiddeck.launcher.input.InputSurfaceStyle()).also {
|
||||
it.alpha = onScreenOpacityAlpha()
|
||||
swappedInputSurface = it
|
||||
} },
|
||||
modifier = Modifier.fillMaxWidth().weight(1f),
|
||||
onRelease = { if (swappedInputSurface === it) swappedInputSurface = null },
|
||||
)
|
||||
|
||||
@@ -19,6 +19,7 @@ object ControllerPrefs {
|
||||
)
|
||||
|
||||
val opacities = listOf(40, 60, 80, 100)
|
||||
val onScreenOpacityRange = 10..100
|
||||
|
||||
val sizes = listOf(80, 85, 90, 95, 100, 105, 110, 115, 120, 125)
|
||||
|
||||
@@ -45,6 +46,7 @@ object ControllerPrefs {
|
||||
val size: Int,
|
||||
val stickClick: Boolean,
|
||||
val adaptiveSticks: Boolean,
|
||||
val onScreenOpacity: Int,
|
||||
val rumble: Boolean,
|
||||
val steamButton: Boolean,
|
||||
val qamButton: Boolean,
|
||||
@@ -66,7 +68,8 @@ object ControllerPrefs {
|
||||
opacity = p.getInt("opacity", 100).takeIf { it in opacities } ?: 100,
|
||||
size = p.getInt("size", 100).takeIf { it in sizes } ?: 100,
|
||||
stickClick = p.getBoolean("stickClick", true),
|
||||
adaptiveSticks = p.getBoolean("adaptiveSticks", true),
|
||||
adaptiveSticks = p.getBoolean("adaptiveSticks", false),
|
||||
onScreenOpacity = onScreenOpacity(context),
|
||||
rumble = rumbleEnabled(context),
|
||||
steamButton = p.getBoolean("steamButton", true),
|
||||
qamButton = p.getBoolean("qamButton", true),
|
||||
@@ -103,6 +106,13 @@ object ControllerPrefs {
|
||||
prefs(context).edit().putBoolean("stickClick", on).apply()
|
||||
}
|
||||
|
||||
fun onScreenOpacity(context: Context): Int =
|
||||
prefs(context).getInt("onScreenOpacity", 100).coerceIn(onScreenOpacityRange)
|
||||
|
||||
fun setOnScreenOpacity(context: Context, percent: Int) {
|
||||
prefs(context).edit().putInt("onScreenOpacity", percent.coerceIn(onScreenOpacityRange)).apply()
|
||||
}
|
||||
|
||||
fun setAdaptiveSticks(context: Context, on: Boolean) {
|
||||
prefs(context).edit().putBoolean("adaptiveSticks", on).apply()
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import androidx.compose.material.icons.outlined.Tune
|
||||
import androidx.lifecycle.setViewTreeLifecycleOwner
|
||||
import androidx.lifecycle.setViewTreeViewModelStoreOwner
|
||||
import androidx.savedstate.setViewTreeSavedStateRegistryOwner
|
||||
import com.droiddeck.launcher.input.ControllerPrefs
|
||||
import com.droiddeck.launcher.input.DeckPanel
|
||||
import com.droiddeck.launcher.input.KeyboardHost
|
||||
import com.droiddeck.launcher.input.PadBridge
|
||||
@@ -397,6 +398,7 @@ class SecondScreenPresentation(
|
||||
val layout = panelLayout(mode)
|
||||
val controls = InputSurfaceView(context, pad, layout?.elements.orEmpty(),
|
||||
surfaceStyle = layout?.style ?: com.droiddeck.launcher.input.InputSurfaceStyle())
|
||||
controls.alpha = ControllerPrefs.onScreenOpacity(context) / 100f
|
||||
controlsView = controls
|
||||
root.addView(controls, weightParams())
|
||||
attachKeyboard()
|
||||
|
||||
@@ -109,6 +109,7 @@ import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.droiddeck.launcher.HomeApp
|
||||
import com.droiddeck.launcher.input.ControllerPrefs
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.animateColorAsState
|
||||
import androidx.compose.animation.core.Spring
|
||||
@@ -331,6 +332,7 @@ class DrawerActions(
|
||||
val onEditSteamTouch: (() -> Unit)? = null,
|
||||
val controller: com.droiddeck.launcher.input.ControllerPrefs.Settings? = null,
|
||||
val onControllerSize: (Int) -> Unit = {},
|
||||
val onControllerOpacity: (Int) -> Unit = {},
|
||||
val onRumble: (Boolean) -> Unit = {},
|
||||
val onSuspendPolicy: (String) -> Unit,
|
||||
val onSteamDownloadsInBackground: (Boolean) -> Unit = {},
|
||||
@@ -747,6 +749,9 @@ private fun DrawerControllerPage(host: MenuHost, a: DrawerActions, padConnected:
|
||||
c?.let {
|
||||
SliderRow(stringResource(R.string.ctrl_size), null, it.size, 80..125, step = 5,
|
||||
format = { v -> "$v%" }, modifier = track("controller-size"), onChange = a.onControllerSize)
|
||||
SliderRow(stringResource(R.string.ctrl_opacity), null, it.onScreenOpacity, ControllerPrefs.onScreenOpacityRange, step = 5,
|
||||
format = { v -> "$v%" }, modifier = track("controller-opacity").testTag("controller-opacity"),
|
||||
onChange = a.onControllerOpacity)
|
||||
}
|
||||
a.adaptiveSticks?.let { adaptive ->
|
||||
ToggleRow(host, "adaptive-sticks", stringResource(R.string.ctrl_adaptive), null, adaptive,
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.droiddeck.launcher.input
|
||||
import android.content.Context
|
||||
import android.content.ContextWrapper
|
||||
import android.content.SharedPreferences
|
||||
import android.graphics.Rect
|
||||
import org.json.JSONObject
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Before
|
||||
@@ -428,23 +429,53 @@ class InputLibraryTest {
|
||||
assertTrue(left.width > left.height * 800f / 1200f && right.width > right.height * 800f / 1200f)
|
||||
}
|
||||
|
||||
@Test fun theFreshOverlayShowsBothSticksAtRestInEitherOrientation() {
|
||||
val overlay = InputLibraries.read(context).activeLayout(false, InputRole.PRIMARY)!!
|
||||
assertFalse(ControllerPrefs.read(context).adaptiveSticks)
|
||||
assertEquals(false, overlay.adaptiveSticks)
|
||||
for ((width, height) in listOf(1080 to 1920, 1920 to 1080)) {
|
||||
val sticks = OnScreenLayout.elements(context, overlay, width, height, Rect())
|
||||
.filter { it.kind == InputElementKind.STICK }
|
||||
assertEquals(setOf(InputControl.LS, InputControl.RS), sticks.map { it.control }.toSet())
|
||||
assertTrue(sticks.none { it.floating || it.hideWhenIdle })
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun anExistingAdaptivePreferenceStillAppliesWhenImportingAnOverlay() {
|
||||
ControllerPrefs.setAdaptiveSticks(context, true)
|
||||
val overlay = InputLibraries.read(context).activeLayout(false, InputRole.PRIMARY)!!
|
||||
assertEquals(true, overlay.adaptiveSticks)
|
||||
}
|
||||
|
||||
@Test fun onScreenOpacityDefaultsToFullAndClampsWithoutChangingLayoutStyle() {
|
||||
ControllerPrefs.setOpacity(context, 60)
|
||||
val layout = InputLibraries.read(context).activeLayout(false, InputRole.PRIMARY)!!
|
||||
assertEquals(100, ControllerPrefs.read(context).onScreenOpacity)
|
||||
for ((requested, expected) in listOf(0 to 10, 45 to 45, 101 to 100)) {
|
||||
ControllerPrefs.setOnScreenOpacity(context, requested)
|
||||
assertEquals(expected, ControllerPrefs.read(context).onScreenOpacity)
|
||||
assertEquals(60, ControllerPrefs.read(context).opacity)
|
||||
assertEquals(layout, InputLibraries.read(context).activeLayout(false, InputRole.PRIMARY))
|
||||
}
|
||||
}
|
||||
|
||||
@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)
|
||||
assertEquals(false, overlay.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))
|
||||
val enabled = InputLibraries.read(context)
|
||||
val changed = enabled.layouts.single { it.id == overlay.id }
|
||||
assertEquals(true, changed.adaptiveSticks)
|
||||
assertTrue(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 }, enabled.layouts.filter { it.id != overlay.id })
|
||||
assertNull(enabled.layouts.single { it.id == InputLibraries.DECK }.adaptiveSticks)
|
||||
assertTrue(InputLibraries.setAdaptiveSticks(context, overlay.id, false))
|
||||
assertEquals(false, 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, true))
|
||||
assertFalse(ControllerPrefs.read(context).adaptiveSticks)
|
||||
}
|
||||
|
||||
@Test fun savedGamepadsFromTheFirstUnifiedBuildGetTheRoundLookOnce() {
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.SessionActivity
|
||||
import com.droiddeck.launcher.gpu.FrameGen
|
||||
import com.droiddeck.launcher.gpu.Lossless
|
||||
import com.droiddeck.launcher.input.ControllerPrefs
|
||||
import com.droiddeck.launcher.input.SecondScreenDisplay
|
||||
import com.droiddeck.launcher.input.SecondScreenMode
|
||||
import com.droiddeck.launcher.input.PadBridgeRoutingTest
|
||||
@@ -93,6 +94,22 @@ class SessionSecondScreenTest {
|
||||
assertEquals(SecondScreenMode.CUSTOM_CONTROLS, selected)
|
||||
}
|
||||
|
||||
@Test fun onScreenOpacitySliderExposesTheRangeAndUpdatesTheLiveSetting() {
|
||||
val changed = mutableListOf<Int>()
|
||||
compose.setContent {
|
||||
DroidDeckTheme {
|
||||
SessionDrawer(true, SessionDrawerPage.CONTROLLER, false, {},
|
||||
actions(true, emptyList(), controller = ControllerPrefs.read(context), onOpacity = { changed += it }))
|
||||
}
|
||||
}
|
||||
val open = compose.runOnIdle { DrawerSectionState.isOpen("controller-osc") }
|
||||
if (!open) compose.onNodeWithTag("drawer-section-controller-osc").performScrollTo().performClick()
|
||||
val slider = compose.onNodeWithTag("controller-opacity").performScrollTo()
|
||||
slider.assertIsDisplayed().performSemanticsAction(androidx.compose.ui.semantics.SemanticsActions.SetProgress) { it(0f) }
|
||||
slider.performSemanticsAction(androidx.compose.ui.semantics.SemanticsActions.SetProgress) { it(45f) }
|
||||
assertEquals(listOf(10, 45), changed)
|
||||
}
|
||||
|
||||
@Test fun desktopWithoutASecondDisplayHasNoScreenPicker() {
|
||||
SessionState.mode = SessionService.MODE_DESKTOP
|
||||
compose.setContent {
|
||||
@@ -408,9 +425,11 @@ class SessionSecondScreenTest {
|
||||
micAvailable: Boolean = false, micEnabled: Boolean = false, onMic: (Boolean) -> Unit = {},
|
||||
desktop: Boolean = !steam, direct: Boolean = false, onInputSelection: (InputRole?) -> Unit = {},
|
||||
onClose: () -> Unit = {}, mode: SecondScreenMode = SecondScreenMode.NONE, gameSwap: Boolean = false,
|
||||
controller: ControllerPrefs.Settings? = null, onOpacity: (Int) -> Unit = {},
|
||||
select: (SecondScreenMode) -> Unit = {}) =
|
||||
DrawerActions(steam = steam, desktop = desktop, direct = direct, onInputSelection = onInputSelection,
|
||||
isHomeApp = false, androidApps = emptyList(), hudOn = false,
|
||||
controller = controller, onControllerOpacity = onOpacity,
|
||||
micAvailable = micAvailable, micEnabled = micEnabled, onMicEnabled = onMic,
|
||||
frameGen = FrameGen.Mode.OFF, lossless = Lossless.State.NONE, oscMode = "never",
|
||||
suspendPolicy = "auto", backActionsInverted = false,
|
||||
|
||||
Reference in new issue
Block a user