mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +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()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user