mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 12:35:42 +00:00
fix(input): count the deck surface and check Steam Touch by visibility for tap suppression
This commit is contained in:
1 parent
9cb876e1e4
commit
8c3d6cfaad
4 files changed
+61
-14
No files matched your search
@@ -4081,11 +4081,11 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
}
|
||||
|
||||
private fun onScreenMouseButtonShown(): Boolean {
|
||||
if (steamTouchInUse) return false
|
||||
return listOfNotNull(unfoldedPanel, bottomInputControls, onScreenControls).any {
|
||||
it.visibility == View.VISIBLE && !it.isButtonsOnly &&
|
||||
inputProfile.hasMouseButton(InputRole.PRIMARY, it.shownElements())
|
||||
}
|
||||
if (steamTouchControls?.visibility == View.VISIBLE) return false
|
||||
val controls = listOfNotNull(unfoldedPanel, bottomInputControls, onScreenControls)
|
||||
.filter { it.visibility == View.VISIBLE && !it.isButtonsOnly }.map { it.shownElements() }
|
||||
val deck = listOfNotNull(unfoldedDeckSurface?.takeIf { it.visibility == View.VISIBLE }?.shownElements())
|
||||
return (controls + deck).any { inputProfile.hasMouseButton(InputRole.PRIMARY, it) }
|
||||
}
|
||||
|
||||
private val directTouchSink = object : DirectTouchHold.Touch {
|
||||
|
||||
@@ -80,19 +80,15 @@ class OnScreenControls(context: Context, pad: PadBridge?, val dock: OnScreenLayo
|
||||
}
|
||||
}
|
||||
|
||||
private fun requestedElements(): List<InputSurfaceElement> {
|
||||
fun shownElements() = surface.shownElements()
|
||||
|
||||
private fun render() {
|
||||
val elements = placed()
|
||||
return when {
|
||||
surface.updateCustomLayout(when {
|
||||
isPinnedOnly -> elements.filter { it.alwaysShown }
|
||||
isQuickHidden -> elements.filter { it.id == "builtin:keyboard" || it.alwaysShown }
|
||||
else -> elements
|
||||
}
|
||||
}
|
||||
|
||||
fun shownElements() = (layout?.style ?: InputSurfaceStyle()).shown(requestedElements())
|
||||
|
||||
private fun render() {
|
||||
surface.updateCustomLayout(requestedElements())
|
||||
})
|
||||
val style = layout?.style ?: InputSurfaceStyle()
|
||||
surface.updateStyle(style)
|
||||
quickToggle.tint = style.tint
|
||||
|
||||
@@ -158,6 +158,8 @@ class InputSurfaceView(
|
||||
}
|
||||
}
|
||||
|
||||
fun shownElements() = customLayout
|
||||
|
||||
fun releaseInputs() {
|
||||
val now = android.os.SystemClock.uptimeMillis()
|
||||
val cancel = MotionEvent.obtain(now, now, MotionEvent.ACTION_CANCEL, 0f, 0f, 0)
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.view.View
|
||||
import androidx.compose.runtime.MutableState
|
||||
import com.droiddeck.launcher.SessionActivity
|
||||
import com.droiddeck.launcher.ui.InputSurfaceView
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import com.droiddeck.launcher.session.SessionService
|
||||
import com.droiddeck.launcher.session.SessionState
|
||||
import java.nio.file.Files
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
@@ -64,6 +68,51 @@ class SessionTouchRoutingTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun pinnedMouseButtonSuppressesTapsAfterSteamTouchIsHiddenForTheKeyboard() {
|
||||
val controls = shownControls(button.copy(alwaysShown = true))
|
||||
field("inputProfile", InputProfile.defaults(InputProfile.DESKTOP))
|
||||
ReflectionHelpers.getField<MutableState<Boolean>>(activity, "steamTouchInUse\$delegate").value = true
|
||||
ReflectionHelpers.getField<MutableState<Boolean>>(activity, "pcKeyboardOpen\$delegate").value = true
|
||||
invoke("updateOnScreenControls")
|
||||
assertEquals(View.GONE, steam.visibility)
|
||||
assertEquals(View.VISIBLE, controls.visibility)
|
||||
assertTrue(mouseButtonShown())
|
||||
}
|
||||
|
||||
@Test fun visibleSteamTouchKeepsTapClicksAndGameBindingsHaveNoMouseButton() {
|
||||
shownControls(button)
|
||||
field("inputProfile", InputProfile.defaults(InputProfile.DESKTOP))
|
||||
assertFalse(mouseButtonShown())
|
||||
steam.visibility = View.GONE
|
||||
assertTrue(mouseButtonShown())
|
||||
field("inputProfile", InputProfile.defaults(InputProfile.GAME))
|
||||
assertFalse(mouseButtonShown())
|
||||
}
|
||||
|
||||
@Test fun mouseButtonOnTheDeckSurfaceSuppressesTapsOnlyWhileItIsShown() {
|
||||
steam.visibility = View.GONE
|
||||
field("inputProfile", InputProfile.defaults(InputProfile.DESKTOP))
|
||||
val deck = InputSurfaceView(activity, null, listOf(button), InputRole.PRIMARY)
|
||||
field("unfoldedDeckSurface", deck)
|
||||
assertTrue(mouseButtonShown())
|
||||
deck.visibility = View.GONE
|
||||
assertFalse(mouseButtonShown())
|
||||
deck.visibility = View.VISIBLE
|
||||
field("inputProfile", InputProfile.defaults(InputProfile.GAME))
|
||||
assertFalse(mouseButtonShown())
|
||||
}
|
||||
|
||||
private val button = InputSurfaceElement(InputControl.A, .7f, .3f, .2f, .3f)
|
||||
|
||||
private fun shownControls(vararg elements: InputSurfaceElement) = OnScreenControls(activity, null).apply {
|
||||
updateLayout(SavedInputLayout("test", "Test", elements.toList(), aspect = 1000f / 600f))
|
||||
measure(View.MeasureSpec.makeMeasureSpec(1000, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(600, View.MeasureSpec.EXACTLY))
|
||||
layout(0, 0, 1000, 600)
|
||||
visibility = View.VISIBLE
|
||||
field("onScreenControls", this)
|
||||
}
|
||||
|
||||
private fun mouseButtonShown() = invoke("onScreenMouseButtonShown") as Boolean
|
||||
private fun field(name: String, value: Any) = ReflectionHelpers.setField(activity, name, value)
|
||||
private fun invoke(name: String) = ReflectionHelpers.callInstanceMethod<Any?>(activity, name)
|
||||
}
|
||||
Reference in new issue
Block a user