mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 12:56:06 +00:00
fix: preserve shared input ownership and reset profile settings
This commit is contained in:
1 parent
3dd6aeef46
commit
6530faaf78
9 files changed
+80
-12
No files matched your search
@@ -12,6 +12,7 @@ object DeckControls {
|
||||
private var router: InputRouter? = null
|
||||
private val pads = ShortArray(4)
|
||||
private val pressure = ShortArray(2)
|
||||
private val touchOwners = arrayOfNulls<Source>(2)
|
||||
|
||||
@Synchronized
|
||||
fun setRouter(next: InputRouter?) {
|
||||
@@ -131,10 +132,15 @@ object DeckControls {
|
||||
pads.fill(0)
|
||||
for (source in sources) {
|
||||
mask = mask or source.mask
|
||||
for (side in 0..1) if (source.mask and (16 shl side) != 0) {
|
||||
pads[side * 2] = source.axes[side * 2]
|
||||
pads[side * 2 + 1] = source.axes[side * 2 + 1]
|
||||
}
|
||||
}
|
||||
for (side in 0..1) {
|
||||
val contact = 16 shl side
|
||||
val owner = touchOwners[side]?.takeIf { it.mask and contact != 0 }
|
||||
?: sources.firstOrNull { it.mask and contact != 0 }
|
||||
touchOwners[side] = owner
|
||||
if (owner == null) continue
|
||||
pads[side * 2] = owner.axes[side * 2]
|
||||
pads[side * 2 + 1] = owner.axes[side * 2 + 1]
|
||||
}
|
||||
pressure[0] = if (mask and 64 != 0) Short.MAX_VALUE else 0
|
||||
pressure[1] = if (mask and 128 != 0) Short.MAX_VALUE else 0
|
||||
|
||||
@@ -68,6 +68,7 @@ object InputProfiles {
|
||||
|
||||
fun resetAll(context: Context) {
|
||||
prefs(context).edit().clear().putBoolean("migrated", true).apply()
|
||||
InputSurfaceLayout.resetAll(context)
|
||||
}
|
||||
|
||||
private fun migrate(context: Context) {
|
||||
|
||||
@@ -12,6 +12,8 @@ data class InputSurfaceElement(val control: InputControl, val x: Float, val y: F
|
||||
object InputSurfaceLayout {
|
||||
private fun prefs(context: Context) = context.getSharedPreferences("input-surfaces", Context.MODE_PRIVATE)
|
||||
|
||||
fun resetAll(context: Context) { prefs(context).edit().clear().apply() }
|
||||
|
||||
fun defaults() = listOf(
|
||||
InputSurfaceElement(InputControl.LEFT_PAD, 0.02f, 0.02f, 0.46f, 0.65f),
|
||||
InputSurfaceElement(InputControl.RIGHT_PAD, 0.52f, 0.02f, 0.46f, 0.65f),
|
||||
|
||||
@@ -70,6 +70,7 @@ public final class PadBridge {
|
||||
private volatile boolean selectSteam;
|
||||
private volatile boolean builtinPad = true;
|
||||
private TouchRoute touchRoute;
|
||||
private boolean touchMouseActive;
|
||||
private final PadState routedTouch = new PadState();
|
||||
private boolean systemGuidePressed;
|
||||
private boolean systemQamPressed;
|
||||
@@ -464,6 +465,7 @@ public final class PadBridge {
|
||||
|
||||
public synchronized void setTouchRoute(TouchRoute route) {
|
||||
touchRoute = route;
|
||||
touchMouseActive = false;
|
||||
routedTouch.clear();
|
||||
}
|
||||
|
||||
@@ -762,22 +764,23 @@ public final class PadBridge {
|
||||
private void publish() {
|
||||
if (!builtinPad && !open && owners[0] == NO_CONTROLLER && partners[0] == NO_CONTROLLER) return;
|
||||
PadState output = physicalRoutes[0] == null ? state : physicalRoutes[0].route(state);
|
||||
boolean mouseRoute = (!touchSources.isEmpty() || touchMouseActive) && touchRoute != null && touchRoute.active();
|
||||
touchMouseActive = mouseRoute && !touchSources.isEmpty();
|
||||
if (mouseRoute) routedTouch.clear();
|
||||
if (!touchSources.isEmpty()) {
|
||||
combinedState.copyFrom(output);
|
||||
routedTouch.clear();
|
||||
boolean epic = touchRoute != null && touchRoute.active();
|
||||
for (TouchSource source : touchSources.values()) {
|
||||
PadState touch = source.route == null ? source.raw : source.route.route(source.raw);
|
||||
if (epic) {
|
||||
if (mouseRoute) {
|
||||
routedTouch.merge(touch);
|
||||
source.passthrough.clear();
|
||||
for (int button : ROUTED_PASS_THROUGH) source.passthrough.press(button, touch.isDown(button));
|
||||
combinedState.merge(source.passthrough);
|
||||
} else combinedState.merge(touch);
|
||||
}
|
||||
if (epic) touchRoute.accept(routedTouch);
|
||||
output = combinedState;
|
||||
}
|
||||
if (mouseRoute) touchRoute.accept(routedTouch);
|
||||
boolean guide = systemGuidePressed || qamChordActive || guideTapPressed;
|
||||
boolean routedQam = output.isDown(PadState.QAM);
|
||||
boolean routedQamStarted = routedQam && !routedQamPressed;
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.util.Log
|
||||
import com.droiddeck.launcher.core.DownloadSource
|
||||
import com.droiddeck.launcher.core.GameEnvironment
|
||||
import com.droiddeck.launcher.input.ControllerPrefs
|
||||
import com.droiddeck.launcher.input.InputProfiles
|
||||
import com.droiddeck.launcher.runtime.LinuxRuntime
|
||||
|
||||
object SettingsReset {
|
||||
@@ -41,6 +42,7 @@ object SettingsReset {
|
||||
val session = context.getSharedPreferences("session", Context.MODE_PRIVATE)
|
||||
session.edit().apply { session.all.keys.filter { isSessionSetting(it) }.forEach { remove(it) } }.commit()
|
||||
ControllerPrefs.resetAll(context)
|
||||
InputProfiles.resetAll(context)
|
||||
context.getSharedPreferences("app-ui", Context.MODE_PRIVATE).edit().clear().commit()
|
||||
context.getSharedPreferences("frame_gen", Context.MODE_PRIVATE).edit().clear().commit()
|
||||
context.getSharedPreferences("steam_touch", Context.MODE_PRIVATE).edit()
|
||||
|
||||
@@ -473,8 +473,7 @@ class DeckControlsPanel(
|
||||
) : HoldButton(context, label, null, { down -> pad.applyTouch(this@DeckControlsPanel, inputRole) { write(it, down) } }) {
|
||||
override fun onDetachedFromWindow() {
|
||||
pad.applyTouch(this@DeckControlsPanel, inputRole) { write(it, false) }
|
||||
deckSource.close()
|
||||
super.onDetachedFromWindow()
|
||||
super.onDetachedFromWindow()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,36 @@ class InputSourceOwnershipTest {
|
||||
private fun state() = JoyConPadTest.RecordingWriter.pads[0]!!
|
||||
@After fun close() { bridge.stop(); DeckControls.releaseAll(); DeckControls.setRouter(null) }
|
||||
|
||||
@Test fun removingLastTouchSurfaceReleasesLegacyMouseRoute() {
|
||||
val routed = PadState()
|
||||
bridge.setTouchRoute(object : PadBridge.TouchRoute {
|
||||
override fun active() = true
|
||||
override fun accept(state: PadState) { routed.copyFrom(state) }
|
||||
})
|
||||
val first = Any(); val second = Any()
|
||||
bridge.applyTouch(first, InputRole.PRIMARY) { it.press(PadState.A, true) }
|
||||
bridge.applyTouch(second, InputRole.SECONDARY) { it.press(PadState.A, true) }
|
||||
bridge.releaseTouch(first)
|
||||
assertTrue(routed.isDown(PadState.A))
|
||||
bridge.releaseTouch(second)
|
||||
assertFalse(routed.isDown(PadState.A))
|
||||
}
|
||||
|
||||
@Test fun nativeTrackpadKeepsItsOwnerUntilThatContactEnds() {
|
||||
val first = DeckControls.source(InputRole.PRIMARY)
|
||||
val second = DeckControls.source(InputRole.SECONDARY)
|
||||
try {
|
||||
first.setPad(false, true, .25f, .5f)
|
||||
val firstPosition = JoyConPadTest.RecordingWriter.deckPads.copyOf()
|
||||
second.setPad(false, true, -.75f, -.5f)
|
||||
assertArrayEquals(firstPosition, JoyConPadTest.RecordingWriter.deckPads)
|
||||
first.setPad(false, false)
|
||||
assertTrue(JoyConPadTest.RecordingWriter.deckPads[0] < 0)
|
||||
second.close()
|
||||
assertEquals(0, JoyConPadTest.RecordingWriter.grips and 16)
|
||||
} finally { first.close(); second.close() }
|
||||
}
|
||||
|
||||
@Test fun closingOneSurfaceDoesNotReleaseAnotherSurfaceOrPhysicalPad() {
|
||||
val a = Any(); val b = Any()
|
||||
bridge.applyExternal({ it.press(PadState.A, true) }, true)
|
||||
|
||||
@@ -203,11 +203,15 @@ class JoyConPadTest {
|
||||
companion object {
|
||||
val pads = HashMap<Int, PadState>()
|
||||
var grips = 0
|
||||
var deckPads = ShortArray(4)
|
||||
|
||||
@JvmStatic @Implementation fun __staticInitializer__() = Unit
|
||||
|
||||
@JvmStatic @Implementation
|
||||
fun writeDeckControls(slot: Int, controls: Int, pads: ShortArray, pressure: ShortArray) { grips = controls }
|
||||
fun writeDeckControls(slot: Int, controls: Int, pads: ShortArray, pressure: ShortArray) {
|
||||
grips = controls
|
||||
deckPads = pads.copyOf()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,12 @@ import android.content.Context
|
||||
import com.droiddeck.launcher.core.AppUiPrefs
|
||||
import com.droiddeck.launcher.gpu.FrameGen
|
||||
import com.droiddeck.launcher.input.ControllerPrefs
|
||||
import com.droiddeck.launcher.input.InputAction
|
||||
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.InputSurfaceLayout
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
@@ -20,7 +26,7 @@ class SettingsResetTest {
|
||||
private val session get() = prefs("session")
|
||||
|
||||
@Before fun clear() {
|
||||
listOf("session", "controller", "app-ui", "frame_gen", "steam_touch", "agent").forEach {
|
||||
listOf("session", "controller", "input-profiles", "input-surfaces", "app-ui", "frame_gen", "steam_touch", "agent").forEach {
|
||||
prefs(it).edit().clear().commit()
|
||||
}
|
||||
}
|
||||
@@ -92,6 +98,21 @@ class SettingsResetTest {
|
||||
assertEquals("a:1,2", prefs("steam_touch").getString("copiedLayout", null))
|
||||
}
|
||||
|
||||
@Test fun inputProfilesAndSurfacesResetWithoutRestoringLegacyMappings() {
|
||||
ControllerPrefs.setTarget(app, "a", "b")
|
||||
InputProfiles.select(app, InputProfile.DESKTOP)
|
||||
InputProfiles.save(app, InputProfile.defaults(InputProfile.GAME)
|
||||
.withBinding(InputRole.PHYSICAL, InputControl.A, InputAction.Disabled))
|
||||
InputSurfaceLayout.save(app, InputProfile.DESKTOP, emptyList())
|
||||
|
||||
assertTrue(SettingsReset.resetAll(app, gameProfiles = false))
|
||||
|
||||
assertEquals(InputProfiles.AUTO, InputProfiles.selection(app))
|
||||
assertEquals(InputProfile.defaults(InputProfile.GAME), InputProfiles.read(app, InputProfile.GAME))
|
||||
assertEquals(InputProfile.defaults(InputProfile.DESKTOP), InputProfiles.read(app, InputProfile.DESKTOP))
|
||||
assertEquals(InputSurfaceLayout.defaults(), InputSurfaceLayout.read(app, InputProfile.DESKTOP))
|
||||
}
|
||||
|
||||
@Test fun gameTextureFilteringIsKeptUnlessGameProfilesAreReset() {
|
||||
session.edit().putString("gameTextureFiltering", """{"440":{"anisotropy":16}}""").commit()
|
||||
SettingsReset.resetAll(app, gameProfiles = false)
|
||||
|
||||
Reference in new issue
Block a user