mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 12:56:06 +00:00
fix: the on-screen pad steps aside while Steam's or DroidDeck's keyboard is open (#1217)
This commit is contained in:
1 parent
b8b3ecf915
commit
862afdf0a9
6 files changed
+465
-9
No files matched your search
@@ -623,6 +623,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
onDispose { com.droiddeck.launcher.glasses.GlassesMenuMirror.setSessionMenuVisible(this@SessionActivity, false) }
|
||||
}
|
||||
androidx.compose.runtime.LaunchedEffect(drawerOpen, pcKeyboardOpen, achievementsOpen, pipUi) { updatePointerCapture() }
|
||||
androidx.compose.runtime.LaunchedEffect(pcKeyboardOpen, AgentGuest.steamKeyboard) { updateOnScreenControls() }
|
||||
androidx.compose.runtime.LaunchedEffect(picturePosition, SessionState.running, pipUi, cardboard.enabled) { applyGameAlignment() }
|
||||
DroidDeckTheme {
|
||||
if (pipUi) {
|
||||
@@ -2701,25 +2702,29 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
SessionState.mode != SessionService.MODE_DESKTOP
|
||||
}
|
||||
onScreenButtonsVisible = show
|
||||
val drawn = show && !keyboardCoversPad()
|
||||
if (steam != null) {
|
||||
if (controls.visibility == View.VISIBLE) { controls.releaseAll(); controls.visibility = View.GONE }
|
||||
if (!show) steam.releaseAll()
|
||||
steam.visibility = if (show) View.VISIBLE else View.GONE
|
||||
if (!drawn) steam.releaseAll()
|
||||
steam.visibility = if (drawn) View.VISIBLE else View.GONE
|
||||
com.droiddeck.launcher.input.SteamTouchDevice.current?.plugged = show
|
||||
applyTouchRouting()
|
||||
Log.i(TAG, "on-screen controls: Steam's touch controller " + if (show) "shown" else "hidden")
|
||||
Log.i(TAG, "on-screen controls: Steam's touch controller " + if (drawn) "shown" else "hidden")
|
||||
return
|
||||
}
|
||||
if (show == (controls.visibility == View.VISIBLE)) return
|
||||
if (!show) controls.releaseAll()
|
||||
controls.visibility = if (show) View.VISIBLE else View.GONE
|
||||
if (drawn == (controls.visibility == View.VISIBLE)) return
|
||||
if (!drawn) controls.releaseAll()
|
||||
controls.visibility = if (drawn) View.VISIBLE else View.GONE
|
||||
Log.i(TAG, "on-screen controls " + when {
|
||||
!show -> "hidden"
|
||||
!drawn -> "hidden"
|
||||
buttonsOnly -> "Steam + QAM"
|
||||
else -> "full pad"
|
||||
})
|
||||
}
|
||||
|
||||
private fun keyboardCoversPad() =
|
||||
SessionState.mode == SessionService.MODE_STEAM && (pcKeyboardOpen || AgentGuest.steamKeyboard)
|
||||
|
||||
private fun sendGuestKey(code: Int, down: Boolean) {
|
||||
if (down && pipUi) return
|
||||
if (down) guestKeysDown.add(code) else guestKeysDown.remove(code)
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.os.Handler
|
||||
import android.os.Looper
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import android.os.FileObserver
|
||||
import android.util.Log
|
||||
@@ -19,6 +20,8 @@ object AgentGuest {
|
||||
private val main by lazy { Handler(Looper.getMainLooper()) }
|
||||
var focusRevision by mutableIntStateOf(0)
|
||||
private set
|
||||
var steamKeyboard by mutableStateOf(false)
|
||||
private set
|
||||
private const val TAG = "AgentGuest"
|
||||
private const val POLL_MS = 50L
|
||||
private val lock = Any()
|
||||
@@ -32,6 +35,7 @@ object AgentGuest {
|
||||
observer?.stopWatching()
|
||||
observer = null
|
||||
lastFocusKey = null
|
||||
main.post { steamKeyboard = false }
|
||||
val dir = dir(context)
|
||||
dir.deleteRecursively()
|
||||
dir.mkdirs()
|
||||
@@ -43,6 +47,7 @@ object AgentGuest {
|
||||
SessionEvents.record("agent.ready", mapOf("pid" to it.optInt("pid"), "focus" to it.optBoolean("focus")))
|
||||
}
|
||||
"focus.json" -> readJson(File(dir, path))?.let(::recordFocus)
|
||||
"keyboard.json" -> readJson(File(dir, path))?.let { recordKeyboard(this, it) }
|
||||
}
|
||||
}
|
||||
}.also { it.startWatching() }
|
||||
@@ -53,9 +58,19 @@ object AgentGuest {
|
||||
synchronized(lock) {
|
||||
observer?.stopWatching()
|
||||
observer = null
|
||||
main.post { steamKeyboard = false }
|
||||
}
|
||||
}
|
||||
|
||||
private fun recordKeyboard(source: FileObserver, snapshot: JSONObject) {
|
||||
val showing = snapshot.optBoolean("steamKeyboard")
|
||||
synchronized(lock) {
|
||||
if (source !== observer) return
|
||||
main.post { steamKeyboard = showing }
|
||||
}
|
||||
SessionEvents.record("keyboard.changed", mapOf("steamKeyboard" to showing, "seq" to snapshot.optInt("seq")))
|
||||
}
|
||||
|
||||
private fun recordFocus(snapshot: JSONObject) {
|
||||
val fields = linkedMapOf<String, Any?>(
|
||||
"focusedApp" to snapshot.opt("focusedApp"),
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.os.Looper
|
||||
import android.view.View
|
||||
import androidx.compose.runtime.MutableState
|
||||
import com.droiddeck.launcher.SessionActivity
|
||||
import com.droiddeck.launcher.agent.AgentGuest
|
||||
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
|
||||
import org.robolectric.Robolectric
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.Shadows.shadowOf
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.util.ReflectionHelpers
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28], manifest = Config.NONE)
|
||||
class SessionKeyboardPadTest {
|
||||
private lateinit var activity: SessionActivity
|
||||
private lateinit var controls: OnScreenControls
|
||||
private val directory = Files.createTempDirectory("keyboard-pad").toFile()
|
||||
|
||||
@Before fun setUp() {
|
||||
activity = Robolectric.buildActivity(SessionActivity::class.java).get()
|
||||
activity.getSharedPreferences("session", 0).edit().clear().commit()
|
||||
SessionState.mode = SessionService.MODE_STEAM
|
||||
controls = OnScreenControls(activity, null).apply { visibility = View.GONE }
|
||||
ReflectionHelpers.setField(activity, "onScreenControls", controls)
|
||||
}
|
||||
|
||||
@After fun tearDown() {
|
||||
steamKeyboard(false)
|
||||
SteamTouchDevice.release()
|
||||
directory.deleteRecursively()
|
||||
SessionState.mode = SessionService.MODE_STEAM
|
||||
}
|
||||
|
||||
@Test fun padStepsAsideWhileEitherKeyboardIsUpInSteam() {
|
||||
SessionPrefs.setOscMode(activity, SessionPrefs.OSC_ALWAYS)
|
||||
update()
|
||||
assertEquals(View.VISIBLE, controls.visibility)
|
||||
steamKeyboard(true)
|
||||
update()
|
||||
assertEquals(View.GONE, controls.visibility)
|
||||
steamKeyboard(false)
|
||||
update()
|
||||
assertEquals(View.VISIBLE, controls.visibility)
|
||||
pcKeyboard(true)
|
||||
update()
|
||||
assertEquals(View.GONE, controls.visibility)
|
||||
pcKeyboard(false)
|
||||
update()
|
||||
assertEquals(View.VISIBLE, controls.visibility)
|
||||
}
|
||||
|
||||
@Test fun keyboardsLeaveThePadAloneOutsideSteam() {
|
||||
SessionState.mode = SessionService.MODE_DESKTOP
|
||||
SessionPrefs.setOscMode(activity, SessionPrefs.OSC_ALWAYS)
|
||||
steamKeyboard(true)
|
||||
pcKeyboard(true)
|
||||
update()
|
||||
assertEquals(View.VISIBLE, controls.visibility)
|
||||
}
|
||||
|
||||
@Test fun steamTouchControllerHidesAndHandsTouchBackWhileSteamsKeyboardIsUp() {
|
||||
SteamTouchDevice.prepare(directory)
|
||||
val steam = SteamTouchControls(activity, SteamTouchDevice.current!!, {}, {})
|
||||
ReflectionHelpers.setField(activity, "steamTouchControls", steam)
|
||||
ReflectionHelpers.setField(activity, "steamTouchOptions",
|
||||
SteamTouchConfig.Options(inputMode = SteamTouchConfig.INPUT_CONTROLLER))
|
||||
SessionPrefs.setTouchMode(activity, SessionPrefs.TOUCH_DIRECT)
|
||||
SessionPrefs.setOscMode(activity, SessionPrefs.OSC_STEAM_TOUCH)
|
||||
update()
|
||||
assertEquals(View.VISIBLE, steam.visibility)
|
||||
assertEquals(SessionPrefs.TOUCH_OFF, routedTouchMode())
|
||||
steamKeyboard(true)
|
||||
update()
|
||||
assertEquals(View.GONE, steam.visibility)
|
||||
assertTrue(SteamTouchDevice.current!!.plugged)
|
||||
assertEquals(SessionPrefs.TOUCH_DIRECT, routedTouchMode())
|
||||
steamKeyboard(false)
|
||||
update()
|
||||
assertEquals(View.VISIBLE, steam.visibility)
|
||||
assertEquals(SessionPrefs.TOUCH_OFF, routedTouchMode())
|
||||
}
|
||||
|
||||
@Test fun endingTheAgentForgetsSteamsKeyboard() {
|
||||
steamKeyboard(true)
|
||||
AgentGuest.stop()
|
||||
shadowOf(Looper.getMainLooper()).idle()
|
||||
assertFalse(AgentGuest.steamKeyboard)
|
||||
}
|
||||
|
||||
private fun update() = ReflectionHelpers.callInstanceMethod<Any?>(activity, "updateOnScreenControls")
|
||||
|
||||
private fun routedTouchMode() = ReflectionHelpers.getField<String>(activity, "routedTouchMode")
|
||||
|
||||
private fun pcKeyboard(open: Boolean) {
|
||||
ReflectionHelpers.getField<MutableState<Boolean>>(activity, "pcKeyboardOpen\$delegate").value = open
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
private fun steamKeyboard(showing: Boolean) {
|
||||
val field = AgentGuest::class.java.getDeclaredField("steamKeyboard\$delegate").apply { isAccessible = true }
|
||||
(field.get(AgentGuest) as MutableState<Boolean>).value = showing
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user