fix(input): add radial stick dead zone setting

This commit is contained in:
vitamin663-sys authored and GitHub committed 2026-11-05 10:53:15 -05:00
1 parent e879375ca4
commit 92a588ea16
44 files changed
+711 -53

No files matched your search

@@ -1544,6 +1544,7 @@ class FrontEndActivity : ComponentActivity() {
onStickClick = { on -> ControllerPrefs.setStickClick(this, on); refreshController() },
onAdaptiveSticks = { on -> ControllerPrefs.setAdaptiveSticks(this, on); refreshController() },
onRumble = { on -> ControllerPrefs.setRumble(this, on); refreshController() },
onDeadZone = { v -> ControllerPrefs.setDeadZone(this, v); refreshController() },
onSteamButton = { on -> ControllerPrefs.setSteamButton(this, on); refreshController() },
onQamButton = { on -> ControllerPrefs.setQamButton(this, on); refreshController() },
onKeyboardButton = { on -> ControllerPrefs.setKeyboardButton(this, on); refreshController() },
@@ -675,6 +675,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
}
val bridge = PadBridge(File(LinuxRuntime.sessionRoot(this), "dev/input"))
bridge.setStickDeadZone(ControllerPrefs.deadZone(this))
bridge.setSelectSteam(ControllerPrefs.read(this).selectSteam)
bridge.setBuiltinPad(SessionState.mode != SessionService.MODE_STEAM || SessionPrefs.builtinPad(this))
padBridge = bridge
@@ -4328,6 +4329,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
}
(getSystemService(INPUT_SERVICE) as? InputManager)
?.registerInputDeviceListener(deviceListener, Handler(Looper.getMainLooper()))
padBridge?.setStickDeadZone(ControllerPrefs.deadZone(this))
refreshSecondScreenDisplays()
if (SessionState.guestPid > 1) padBridge?.syncConnectedControllers()
joyConVr?.refresh()
@@ -1,5 +1,6 @@
package com.droiddeck.launcher.agent
import com.droiddeck.launcher.input.PadBridge
import com.droiddeck.launcher.input.PadState
import com.droiddeck.launcher.session.SessionState
import com.droiddeck.launcher.wayland.WaylandCompositor
@@ -143,9 +144,10 @@ object AgentInput {
val right = request.optString("stick", "left") == "right"
val x = request.optDouble("x", 0.0).toFloat().coerceIn(-1f, 1f)
val y = request.optDouble("y", 0.0).toFloat().coerceIn(-1f, 1f)
bridge.applyTouch { if (right) { it.rightX = x; it.rightY = y } else { it.leftX = x; it.leftY = y } }
val stickWrite = if (right) PadBridge.RIGHT_STICK else PadBridge.LEFT_STICK
bridge.applyTouch(stickWrite) { if (right) { it.rightX = x; it.rightY = y } else { it.leftX = x; it.leftY = y } }
hold(request, 300)
bridge.applyTouch { if (right) { it.rightX = 0f; it.rightY = 0f } else { it.leftX = 0f; it.leftY = 0f } }
bridge.applyTouch(stickWrite) { if (right) { it.rightX = 0f; it.rightY = 0f } else { it.leftX = 0f; it.leftY = 0f } }
return JSONObject().put("stick", if (right) "right" else "left")
}
@@ -22,6 +22,9 @@ object ControllerPrefs {
val sizes = listOf(80, 90, 100, 110, 125)
val deadZones = listOf(0, 5, 8, 12, 15, 20, 25)
const val DEFAULT_DEAD_ZONE_PERCENT = 12
val mappable = listOf(
"a" to R.string.ctrl_button_a, "b" to R.string.ctrl_button_b, "x" to R.string.ctrl_button_x, "y" to R.string.ctrl_button_y,
"lb" to R.string.ctrl_button_lb, "rb" to R.string.ctrl_button_rb, "lt" to R.string.ctrl_button_lt, "rt" to R.string.ctrl_button_rt,
@@ -51,6 +54,7 @@ object ControllerPrefs {
val snap: Boolean,
val customLayout: Boolean,
val mapping: Map<String, String>,
val deadZone: Int,
)
internal fun prefs(context: Context) = context.getSharedPreferences("controller", Context.MODE_PRIVATE)
@@ -72,6 +76,7 @@ object ControllerPrefs {
snap = p.getBoolean("snap", true),
customLayout = p.all.keys.any { it.startsWith("layout.") },
mapping = mappable.associate { (id, _) -> id to target(context, id) },
deadZone = deadZone(context),
)
}
@@ -109,6 +114,13 @@ object ControllerPrefs {
fun rumbleEnabled(context: Context): Boolean = prefs(context).getBoolean("rumble", true)
fun deadZone(context: Context): Int =
prefs(context).getInt("deadZone", DEFAULT_DEAD_ZONE_PERCENT).takeIf { it in deadZones } ?: DEFAULT_DEAD_ZONE_PERCENT
fun setDeadZone(context: Context, percent: Int) {
prefs(context).edit().putInt("deadZone", percent).apply()
}
fun setRumble(context: Context, on: Boolean) {
prefs(context).edit().putBoolean("rumble", on).apply()
}
@@ -549,6 +549,7 @@ class OnScreenControls(
control.ax = if (adaptive) event.getX(index) else control.cx
control.ay = if (adaptive) event.getY(index) else control.cy
control.drag(event.getX(index), event.getY(index))
control.dirty = true
}
if (SessionPrefs.lowLatency(context)) requestUnbufferedDispatch(event)
apply()
@@ -721,7 +722,10 @@ class OnScreenControls(
bridge.setSystemButtons(controls.any { it.id == "guide" && it.pressedBy != -1 }, qamHeld)
} else {
bridge.setSystemButtons(false, qamHeld)
bridge.applyTouch { state ->
val stickWrites = controls.filter { it.stick >= 0 && it.dirty }.fold(0) { mask, control ->
mask or if (control.stick == 0) PadBridge.LEFT_STICK else PadBridge.RIGHT_STICK
}
bridge.applyTouch(stickWrites) { state ->
val used = HashSet<String>()
val held = HashSet<String>()
for (control in controls) {
@@ -17,7 +17,10 @@ import java.util.concurrent.atomic.AtomicIntegerArray;
public final class PadBridge {
private static final String TAG = "PadBridge";
public static final int SLOTS = 4;
public static final int LEFT_STICK = 1;
public static final int RIGHT_STICK = 2;
private static final float DEAD_ZONE = 0.12f;
private float stickDeadZone = DEAD_ZONE;
private static final int[] JOYSTICK_AXES = {
MotionEvent.AXIS_X, MotionEvent.AXIS_Y, MotionEvent.AXIS_Z, MotionEvent.AXIS_RZ,
MotionEvent.AXIS_RX, MotionEvent.AXIS_RY,
@@ -52,6 +55,8 @@ public final class PadBridge {
private volatile java.util.function.IntPredicate excluded = id -> false;
private final FakeInputWriter[] playerWriters = new FakeInputWriter[SLOTS];
private final PadState[] playerStates = new PadState[SLOTS];
private final float[][] rawSticks = new float[SLOTS][4];
private final int[] retainedSticks = new int[SLOTS];
private final PadState effectiveState = new PadState();
private final PadState homeGuideReport = new PadState();
private final Handler mainHandler = new Handler(Looper.getMainLooper());
@@ -150,7 +155,7 @@ public final class PadBridge {
chordButtonPressed = false;
qamChordGeneration++;
chordHandler.removeCallbacksAndMessages(null);
state.clear();
clearPlayerState(0);
publish();
}
@@ -177,7 +182,7 @@ public final class PadBridge {
playerWriters[slot].destroy();
playerWriters[slot] = null;
}
if (playerStates[slot] != null) playerStates[slot].clear();
clearPlayerState(slot);
}
systemGuidePressed = false;
systemQamPressed = false;
@@ -187,7 +192,7 @@ public final class PadBridge {
qamTapPressed = false;
qamChordGeneration++;
if (open) {
state.clear();
clearPlayerState(0);
writer.writePad(state);
writer.close();
open = false;
@@ -353,6 +358,65 @@ public final class PadBridge {
return true;
}
public synchronized void setStickDeadZone(int percent) {
float value = Math.max(0, Math.min(25, percent)) / 100f;
if (stickDeadZone == value) return;
stickDeadZone = value;
for (int slot = 0; slot < SLOTS; slot++) {
if (retainedSticks[slot] == 0) continue;
int owner = owners[slot], partner = partners[slot];
if (owner != NO_CONTROLLER && (InputDevice.getDevice(owner) == null || excluded.test(owner))) leave(slot, owner);
if (partner != NO_CONTROLLER && (InputDevice.getDevice(partner) == null || excluded.test(partner))) leave(slot, partner);
if (retainedSticks[slot] == 0) continue;
projectSticks(slot);
publish(slot);
}
}
private void retainStick(int slot, int side, float x, float y) {
rawSticks[slot][side * 2] = x;
rawSticks[slot][side * 2 + 1] = y;
retainedSticks[slot] |= 1 << side;
}
private void projectSticks(int slot) {
PadState pad = stateFor(slot);
for (int side = 0; side < 2; side++) {
if ((retainedSticks[slot] & (1 << side)) == 0) continue;
float x = rawSticks[slot][side * 2];
float y = rawSticks[slot][side * 2 + 1];
boolean centred = inStickDeadZone(x, y, stickDeadZone);
if (side == JoyCon.LEFT) {
pad.leftX = centred ? 0f : x;
pad.leftY = centred ? 0f : y;
} else {
pad.rightX = centred ? 0f : x;
pad.rightY = centred ? 0f : y;
}
}
}
private void clearPlayerState(int slot) {
stateFor(slot).clear();
retainedSticks[slot] = 0;
Arrays.fill(rawSticks[slot], 0f);
}
private void mutateState(java.util.function.Consumer<PadState> mutation) {
float lx = state.leftX, ly = state.leftY, rx = state.rightX, ry = state.rightY;
mutation.accept(state);
if (state.leftX != lx || state.leftY != ly) retainedSticks[0] &= ~1;
if (state.rightX != rx || state.rightY != ry) retainedSticks[0] &= ~2;
}
static boolean inStickDeadZone(float x, float y, float deadZone) {
return x * x + y * y < deadZone * deadZone;
}
private static boolean hasChordStickInput(float x, float y) {
return Math.max(Math.abs(x), Math.abs(y)) >= DEAD_ZONE;
}
public synchronized boolean onMotionEvent(MotionEvent event) {
if (!isControllerMotionEvent(event) || excluded.test(event.getDeviceId())) return false;
if (event.getAction() != MotionEvent.ACTION_MOVE) return false;
@@ -366,25 +430,24 @@ public final class PadBridge {
int side = JoyCon.side(device);
if (side >= 0) {
int[] stick = JoyCon.stickAxes(side, device, event.getSource());
float x = axis(event, stick[0]);
float y = axis(event, stick[1]);
if (side == JoyCon.LEFT) {
pad.leftX = x;
pad.leftY = y;
} else {
pad.rightX = x;
pad.rightY = y;
}
if (x != 0f || y != 0f) noteChordInput(slot);
float x = event.getAxisValue(stick[0]);
float y = event.getAxisValue(stick[1]);
boolean chordStickInput = hasChordStickInput(x, y);
retainStick(slot, side, x, y);
projectSticks(slot);
if (chordStickInput) noteChordInput(slot);
if (Math.max(Math.abs(x), Math.abs(y)) > 0.5f) notePlayerInput();
publish(slot);
return true;
}
pad.leftX = axis(event, MotionEvent.AXIS_X);
pad.leftY = axis(event, MotionEvent.AXIS_Y);
float lx = event.getAxisValue(MotionEvent.AXIS_X);
float ly = event.getAxisValue(MotionEvent.AXIS_Y);
boolean wired = wiredXboxLayout(event);
pad.rightX = rightX(event, wired);
pad.rightY = rightY(event, wired);
float rx = event.getAxisValue(wired ? MotionEvent.AXIS_RX : MotionEvent.AXIS_Z);
float ry = event.getAxisValue(wired ? MotionEvent.AXIS_RY : MotionEvent.AXIS_RZ);
retainStick(slot, JoyCon.LEFT, lx, ly);
retainStick(slot, JoyCon.RIGHT, rx, ry);
projectSticks(slot);
int source = event.getSource();
float lt = 0f;
float rt = 0f;
@@ -406,7 +469,7 @@ public final class PadBridge {
pad.up = hatY < -0.5f;
pad.down = hatY > 0.5f;
}
if (pad.leftX != 0f || pad.leftY != 0f || pad.rightX != 0f || pad.rightY != 0f
if (hasChordStickInput(lx, ly) || hasChordStickInput(rx, ry)
|| lt > 0f || rt > 0f || pad.up || pad.right || pad.down || pad.left) noteChordInput(slot);
if (Math.max(Math.max(Math.abs(pad.leftX), Math.abs(pad.leftY)), Math.max(Math.abs(pad.rightX), Math.abs(pad.rightY))) > 0.5f
|| lt > 0.5f || rt > 0.5f || pad.up || pad.right || pad.down || pad.left) {
@@ -434,6 +497,10 @@ public final class PadBridge {
}
public synchronized void applyTouch(java.util.function.Consumer<PadState> mutation) {
applyTouch(0, mutation);
}
public synchronized void applyTouch(int stickWrites, java.util.function.Consumer<PadState> mutation) {
if (!builtinPad) return;
if (touchRoute != null && touchRoute.active()) {
mutation.accept(routedTouch);
@@ -453,7 +520,8 @@ public final class PadBridge {
return;
}
routedTouch.clear();
mutation.accept(state);
retainedSticks[0] &= ~stickWrites;
mutateState(mutation);
activeControllerId = NO_CONTROLLER;
slotControllers.set(0, NO_CONTROLLER);
notePlayerInput();
@@ -463,7 +531,7 @@ public final class PadBridge {
}
public synchronized void applyExternal(java.util.function.Consumer<PadState> mutation, boolean changed) {
mutation.accept(state);
mutateState(mutation);
if (changed) {
activeControllerId = NO_CONTROLLER;
notePlayerInput();
@@ -490,11 +558,11 @@ public final class PadBridge {
routedTouch.clear();
backQamPressed = false;
releaseBackPaddles();
state.clear();
clearPlayerState(0);
publish();
for (int slot = 1; slot < SLOTS; slot++) {
clearPlayerState(slot);
if (playerWriters[slot] == null) continue;
playerStates[slot].clear();
publish(slot);
}
}
@@ -534,7 +602,7 @@ public final class PadBridge {
if (!homeGuidePressed) return;
clearBackQamWrites();
homeGuidePressed = false;
state.clear();
clearPlayerState(0);
publish();
}
@@ -557,7 +625,7 @@ public final class PadBridge {
writeBackQamReport(modifier, modifierAt);
}
if (!pressed && !backQamPressed && !homeGuidePressed) {
backQamAxesBlocked = hasAxes(state);
backQamAxesBlocked = hasQamAxes();
if (!backQamWrites.isEmpty()) {
PadState neutral = new PadState();
neutral.copyFrom(lastWrittenReport);
@@ -573,7 +641,7 @@ public final class PadBridge {
if (!backQamPressed && backQamWrites.isEmpty()) return;
clearBackQamWrites();
backQamPressed = false;
state.clear();
clearPlayerState(0);
publish();
}
@@ -609,15 +677,18 @@ public final class PadBridge {
}
private void writePad(PadState report) {
if (backQamAxesBlocked && !hasAxes(state)) backQamAxesBlocked = false;
if (backQamAxesBlocked && !hasQamAxes()) backQamAxesBlocked = false;
long at = android.os.SystemClock.uptimeMillis();
if (backQamPressed || homeGuidePressed || !backQamWrites.isEmpty()) at += backQamDelayMs;
writeBackQamReport(report, at);
}
private static boolean hasAxes(PadState pad) {
return pad.leftX != 0f || pad.leftY != 0f || pad.rightX != 0f || pad.rightY != 0f
|| pad.leftTrigger != 0f || pad.rightTrigger != 0f;
private boolean hasQamAxes() {
boolean left = (retainedSticks[0] & 1) != 0
? hasChordStickInput(rawSticks[0][0], rawSticks[0][1]) : state.leftX != 0f || state.leftY != 0f;
boolean right = (retainedSticks[0] & 2) != 0
? hasChordStickInput(rawSticks[0][2], rawSticks[0][3]) : state.rightX != 0f || state.rightY != 0f;
return left || right || state.leftTrigger != 0f || state.rightTrigger != 0f;
}
private static void clearAxes(PadState pad) {
@@ -727,7 +798,7 @@ public final class PadBridge {
slotJoyCons.set(slot * 2 + 1 - side, owner.getId());
if (slot == firstPlayerSlot()) releaseBackPaddles();
if (slot == 0) clearBackQamWrites();
stateFor(slot).clear();
clearPlayerState(slot);
if (slot == 0) publish();
Log.i(TAG, "\"" + device.getName() + "\" (id " + id + ") joins \"" + owner.getName() + "\" as player " + (slot + 1));
return slot;
@@ -775,7 +846,7 @@ public final class PadBridge {
if (slotControllers.get(slot) == id) slotControllers.set(slot, owners[slot]);
if (activeControllerId == id) activeControllerId = owners[slot];
if (slot == firstPlayerSlot()) releaseBackPaddles();
stateFor(slot).clear();
clearPlayerState(slot);
publish(slot);
}
@@ -793,11 +864,11 @@ public final class PadBridge {
if (slot == homeGuideSlot) homeGuideSlot = -1;
if (slot == firstPlayerSlot()) releaseBackPaddles();
if (slot == 0) {
state.clear();
clearPlayerState(0);
publish();
return;
}
playerStates[slot].clear();
clearPlayerState(slot);
if (playerWriters[slot] != null) {
playerWriters[slot].destroy();
playerWriters[slot] = null;
@@ -886,14 +957,6 @@ public final class PadBridge {
&& device.getMotionRange(MotionEvent.AXIS_RZ, event.getSource()) != null;
}
public static float rightX(MotionEvent event, boolean wired) {
return axis(event, wired ? MotionEvent.AXIS_RX : MotionEvent.AXIS_Z);
}
public static float rightY(MotionEvent event, boolean wired) {
return axis(event, wired ? MotionEvent.AXIS_RY : MotionEvent.AXIS_RZ);
}
public static float leftTrigger(MotionEvent event, boolean wired) {
if (wired) return Math.max(0f, Math.min(1f, (event.getAxisValue(MotionEvent.AXIS_Z) + 1f) / 2f));
float value = event.getAxisValue(MotionEvent.AXIS_LTRIGGER);
@@ -906,8 +969,4 @@ public final class PadBridge {
return value != 0f ? value : event.getAxisValue(MotionEvent.AXIS_GAS);
}
private static float axis(MotionEvent event, int axis) {
float value = event.getAxisValue(axis);
return Math.abs(value) < DEAD_ZONE ? 0f : value;
}
}
@@ -90,8 +90,8 @@ class PadMouse(private val listener: Listener, private val clock: () -> Long = S
val wired = wiredLayout.getOrPut(event.deviceId) { PadBridge.wiredXboxLayout(event) }
sticks.leftX = event.getAxisValue(MotionEvent.AXIS_X)
sticks.leftY = event.getAxisValue(MotionEvent.AXIS_Y)
sticks.rightX = PadBridge.rightX(event, wired)
sticks.rightY = PadBridge.rightY(event, wired)
sticks.rightX = scrollAxis(event, if (wired) MotionEvent.AXIS_RX else MotionEvent.AXIS_Z)
sticks.rightY = scrollAxis(event, if (wired) MotionEvent.AXIS_RY else MotionEvent.AXIS_RZ)
if (hasTriggerAxes(event)) {
sticks.leftTrigger = PadBridge.leftTrigger(event, wired)
sticks.rightTrigger = PadBridge.rightTrigger(event, wired)
@@ -295,6 +295,7 @@ class PadMouse(private val listener: Listener, private val clock: () -> Long = S
}
companion object {
private const val SCROLL_AXIS_DEAD_ZONE = 0.12f
private const val DEAD_ZONE = 0.15f
private const val STICK_NAVIGATE = 0.5f
private const val REPEAT_FIRST_MS = 300L
@@ -348,6 +349,9 @@ class PadMouse(private val listener: Listener, private val clock: () -> Long = S
return scaled * scaled / length
}
private fun scrollAxis(event: MotionEvent, axis: Int): Float =
event.getAxisValue(axis).let { if (abs(it) < SCROLL_AXIS_DEAD_ZONE) 0f else it }
private fun source(deviceId: Int, kind: Int): Int = deviceId * 2 + kind
@@ -25,6 +25,7 @@ class ControllerActions(
val onStickClick: (Boolean) -> Unit,
val onAdaptiveSticks: (Boolean) -> Unit,
val onRumble: (Boolean) -> Unit,
val onDeadZone: (Int) -> Unit,
val onSteamButton: (Boolean) -> Unit,
val onQamButton: (Boolean) -> Unit,
val onKeyboardButton: (Boolean) -> Unit,
@@ -69,6 +70,7 @@ fun ColumnScope.ControllerRows(host: MenuHost, oscMode: String, c: ControllerPre
ToggleRow(host, "controller-stick-click", stringResource(R.string.ctrl_stick_click), stringResource(R.string.ctrl_stick_click_hint), c.stickClick, onChange = a.onStickClick)
ToggleRow(host, "controller-adaptive", stringResource(R.string.ctrl_adaptive), stringResource(R.string.ctrl_adaptive_hint), c.adaptiveSticks, onChange = a.onAdaptiveSticks)
ToggleRow(host, "controller-rumble", stringResource(R.string.ctrl_rumble), null, c.rumble, onChange = a.onRumble)
ChoiceRow(host, "controller-dead-zone", stringResource(R.string.ctrl_dead_zone), null, ControllerPrefs.deadZones.map { it to stringResource(R.string.ctrl_percent, it) }, c.deadZone, onPick = a.onDeadZone)
ToggleRow(host, "controller-steam", stringResource(R.string.ctrl_steam_button), null, c.steamButton, onChange = a.onSteamButton)
ToggleRow(host, "controller-qam", stringResource(R.string.ctrl_qam_button), null, c.qamButton, onChange = a.onQamButton)
ToggleRow(host, "controller-keyboard", stringResource(R.string.ctrl_keyboard_button), null, c.keyboardButton, onChange = a.onKeyboardButton)
@@ -479,7 +479,7 @@ class DeckControlsPanel(
private fun move(dx: Float, dy: Float, r: Float) {
knobX = dx
knobY = dy
pad.applyTouch { s ->
pad.applyTouch(if (right) PadBridge.RIGHT_STICK else PadBridge.LEFT_STICK) { s ->
if (right) { s.rightX = dx / r; s.rightY = dy / r } else { s.leftX = dx / r; s.leftY = dy / r }
}
invalidate()
+1
View File
@@ -1130,6 +1130,7 @@
<string name="ctrl_stick_click_hint">انقر مرتين مع الاستمرار على عصا للحصول على L3 أو R3</string>
<string name="ctrl_adaptive">عصي تكيّفية</string>
<string name="ctrl_rumble">اهتزاز اللعبة</string>
<string name="ctrl_dead_zone">المنطقة الميتة لعصا التحكم</string>
<string name="ctrl_steam_button">زر Steam</string>
<string name="ctrl_qam_button">زر QAM</string>
<string name="ctrl_keyboard_button">زر لوحة المفاتيح</string>
@@ -1139,6 +1139,7 @@
<string name="ctrl_stick_click_hint">Toca dos veces y mantén un stick para L3 o R3</string>
<string name="ctrl_adaptive">Sticks adaptables</string>
<string name="ctrl_rumble">Vibración en juegos</string>
<string name="ctrl_dead_zone">Zona muerta de la palanca</string>
<string name="ctrl_steam_button">Botón Steam</string>
<string name="ctrl_qam_button">Botón QAM</string>
<string name="ctrl_keyboard_button">Botón de teclado</string>
+1
View File
@@ -1106,6 +1106,7 @@
<string name="ctrl_stick_click_hint">Докоснете двукратно и задръжте стик за L3 или R3</string>
<string name="ctrl_adaptive">Адаптивни стикове</string>
<string name="ctrl_rumble">Вибрация от играта</string>
<string name="ctrl_dead_zone">Мъртва зона на стика</string>
<string name="ctrl_steam_button">Бутон Steam</string>
<string name="ctrl_qam_button">Бутон QAM</string>
<string name="ctrl_keyboard_button">Бутон за клавиатура</string>
+1
View File
@@ -1118,6 +1118,7 @@
<string name="ctrl_stick_click_hint">Dvojitým dotykem a podržením páčky aktivujete L3 nebo R3</string>
<string name="ctrl_adaptive">Adaptivní páčky</string>
<string name="ctrl_rumble">Vibrace ve hře</string>
<string name="ctrl_dead_zone">Mrtvá zóna páčky</string>
<string name="ctrl_steam_button">Tlačítko Steam</string>
<string name="ctrl_qam_button">Tlačítko QAM</string>
<string name="ctrl_keyboard_button">Tlačítko klávesnice</string>
+1
View File
@@ -1106,6 +1106,7 @@
<string name="ctrl_stick_click_hint">Dobbelttryk og hold en stick nede for L3 eller R3</string>
<string name="ctrl_adaptive">Adaptive styrepinde</string>
<string name="ctrl_rumble">Spilvibration</string>
<string name="ctrl_dead_zone">Dødzone for styrepind</string>
<string name="ctrl_steam_button">Steam-knap</string>
<string name="ctrl_qam_button">QAM-knap</string>
<string name="ctrl_keyboard_button">Tastaturknap</string>
+1
View File
@@ -1098,6 +1098,7 @@
<string name="ctrl_stick_click_hint">Doppeltippen und Stick halten für L3 oder R3</string>
<string name="ctrl_adaptive">Adaptive Sticks</string>
<string name="ctrl_rumble">Spielvibration</string>
<string name="ctrl_dead_zone">Stick-Totzone</string>
<string name="ctrl_steam_button">Steam-Taste</string>
<string name="ctrl_qam_button">QAM-Taste</string>
<string name="ctrl_keyboard_button">Tastatur-Taste</string>
+1
View File
@@ -1106,6 +1106,7 @@
<string name="ctrl_stick_click_hint">Πατήστε δύο φορές και κρατήστε έναν μοχλό για L3 ή R3</string>
<string name="ctrl_adaptive">Προσαρμοστικοί μοχλοί</string>
<string name="ctrl_rumble">Κραδασμός παιχνιδιού</string>
<string name="ctrl_dead_zone">Νεκρή ζώνη μοχλού</string>
<string name="ctrl_steam_button">Κουμπί Steam</string>
<string name="ctrl_qam_button">Κουμπί QAM</string>
<string name="ctrl_keyboard_button">Κουμπί πληκτρολογίου</string>
+1
View File
@@ -1112,6 +1112,7 @@
<string name="ctrl_stick_click_hint">Toca dos veces y mantén un stick para L3 o R3</string>
<string name="ctrl_adaptive">Sticks adaptables</string>
<string name="ctrl_rumble">Vibración en juegos</string>
<string name="ctrl_dead_zone">Zona muerta de la palanca</string>
<string name="ctrl_steam_button">Botón Steam</string>
<string name="ctrl_qam_button">Botón QAM</string>
<string name="ctrl_keyboard_button">Botón de teclado</string>
+1
View File
@@ -1106,6 +1106,7 @@
<string name="ctrl_stick_click_hint">Kaksoisnapauta ja pidä sauvaa pohjassa saadaksesi L3:n tai R3:n</string>
<string name="ctrl_adaptive">Mukautuvat sauvat</string>
<string name="ctrl_rumble">Pelin tärinä</string>
<string name="ctrl_dead_zone">Ohjaussauvan kuollut alue</string>
<string name="ctrl_steam_button">Steam-painike</string>
<string name="ctrl_qam_button">QAM-painike</string>
<string name="ctrl_keyboard_button">Näppäimistöpainike</string>
+1
View File
@@ -1112,6 +1112,7 @@
<string name="ctrl_stick_click_hint">Double-cliquez et maintenez le joystick pour déclencher L3 ou R3</string>
<string name="ctrl_adaptive">Joystick adaptatif</string>
<string name="ctrl_rumble">Vibration du jeu</string>
<string name="ctrl_dead_zone">Zone morte du stick</string>
<string name="ctrl_steam_button">Bouton Steam</string>
<string name="ctrl_qam_button">Bouton QAM</string>
<string name="ctrl_keyboard_button">Bouton clavier</string>
+1
View File
@@ -1106,6 +1106,7 @@
<string name="ctrl_stick_click_hint">L3 या R3 के लिए किसी स्टिक को डबल-टैप करके दबाए रखें</string>
<string name="ctrl_adaptive">एडैप्टिव स्टिक</string>
<string name="ctrl_rumble">गेम वाइब्रेशन</string>
<string name="ctrl_dead_zone">स्टिक का डेड ज़ोन</string>
<string name="ctrl_steam_button">Steam बटन</string>
<string name="ctrl_qam_button">QAM बटन</string>
<string name="ctrl_keyboard_button">कीबोर्ड बटन</string>
+1
View File
@@ -1106,6 +1106,7 @@
<string name="ctrl_stick_click_hint">Koppintson duplán, és tartsa lenyomva a kart az L3 vagy R3 érdekében</string>
<string name="ctrl_adaptive">Adaptív karok</string>
<string name="ctrl_rumble">Játékvibráció</string>
<string name="ctrl_dead_zone">Kar holtzónája</string>
<string name="ctrl_steam_button">Steam gomb</string>
<string name="ctrl_qam_button">QAM gomb</string>
<string name="ctrl_keyboard_button">Billentyűzet gomb</string>
+1
View File
@@ -1100,6 +1100,7 @@
<string name="ctrl_stick_click_hint">Ketuk dua kali dan tahan sebuah stik untuk L3 atau R3</string>
<string name="ctrl_adaptive">Stik adaptif</string>
<string name="ctrl_rumble">Getaran gim</string>
<string name="ctrl_dead_zone">Zona mati stik</string>
<string name="ctrl_steam_button">Tombol Steam</string>
<string name="ctrl_qam_button">Tombol QAM</string>
<string name="ctrl_keyboard_button">Tombol keyboard</string>
+1
View File
@@ -1104,6 +1104,7 @@
<string name="ctrl_stick_click_hint">Tocca due volte e tieni premuta una levetta per L3 o R3</string>
<string name="ctrl_adaptive">Levette adattive</string>
<string name="ctrl_rumble">Vibrazione di gioco</string>
<string name="ctrl_dead_zone">Zona morta dello stick</string>
<string name="ctrl_steam_button">Tasto Steam</string>
<string name="ctrl_qam_button">Tasto QAM</string>
<string name="ctrl_keyboard_button">Tasto tastiera</string>
+1
View File
@@ -1100,6 +1100,7 @@
<string name="ctrl_stick_click_hint">スティックをダブルタップして長押しすると、L3またはR3がトリガーされます</string>
<string name="ctrl_adaptive">アダプティブスティック</string>
<string name="ctrl_rumble">ゲームの振動</string>
<string name="ctrl_dead_zone">スティックのデッドゾーン</string>
<string name="ctrl_steam_button">Steamボタン</string>
<string name="ctrl_qam_button">QAMボタン</string>
<string name="ctrl_keyboard_button">キーボードボタン</string>
+1
View File
@@ -1100,6 +1100,7 @@
<string name="ctrl_stick_click_hint">스틱을 두 번 탭한 후 길게 누르면 L3 또는 R3이 입력됩니다</string>
<string name="ctrl_adaptive">적응형 스틱</string>
<string name="ctrl_rumble">게임 진동</string>
<string name="ctrl_dead_zone">스틱 데드존</string>
<string name="ctrl_steam_button">Steam 버튼</string>
<string name="ctrl_qam_button">QAM 버튼</string>
<string name="ctrl_keyboard_button">키보드 버튼</string>
+1
View File
@@ -1100,6 +1100,7 @@
<string name="ctrl_stick_click_hint">Ketik dua kali dan tahan stik untuk L3 atau R3</string>
<string name="ctrl_adaptive">Stik adaptif</string>
<string name="ctrl_rumble">Getaran permainan</string>
<string name="ctrl_dead_zone">Zon mati kayu bedik</string>
<string name="ctrl_steam_button">Butang Steam</string>
<string name="ctrl_qam_button">Butang QAM</string>
<string name="ctrl_keyboard_button">Butang papan kekunci</string>
+1
View File
@@ -1106,6 +1106,7 @@
<string name="ctrl_stick_click_hint">Dobbelttrykk og hold en stikke for L3 eller R3</string>
<string name="ctrl_adaptive">Adaptive stikker</string>
<string name="ctrl_rumble">Spillvibrasjon</string>
<string name="ctrl_dead_zone">Dødsone for styrespak</string>
<string name="ctrl_steam_button">Steam-knapp</string>
<string name="ctrl_qam_button">QAM-knapp</string>
<string name="ctrl_keyboard_button">Tastatur-knapp</string>
+1
View File
@@ -1106,6 +1106,7 @@
<string name="ctrl_stick_click_hint">Dubbeltik en houd een stick ingedrukt voor L3 of R3</string>
<string name="ctrl_adaptive">Adaptieve sticks</string>
<string name="ctrl_rumble">Trillen in games</string>
<string name="ctrl_dead_zone">Dode zone van stick</string>
<string name="ctrl_steam_button">Steam-knop</string>
<string name="ctrl_qam_button">QAM-knop</string>
<string name="ctrl_keyboard_button">Toetsenbordknop</string>
+1
View File
@@ -1118,6 +1118,7 @@
<string name="ctrl_stick_click_hint">Dotknij dwukrotnie i przytrzymaj gałkę, aby uzyskać L3 lub R3</string>
<string name="ctrl_adaptive">Adaptacyjne gałki</string>
<string name="ctrl_rumble">Wibracje gry</string>
<string name="ctrl_dead_zone">Martwa strefa drążka</string>
<string name="ctrl_steam_button">Przycisk Steam</string>
<string name="ctrl_qam_button">Przycisk QAM</string>
<string name="ctrl_keyboard_button">Przycisk klawiatury</string>
@@ -1104,6 +1104,7 @@
<string name="ctrl_stick_click_hint">Toque duas vezes num analógico e mantenha para L3 ou R3</string>
<string name="ctrl_adaptive">Analógicos adaptáveis</string>
<string name="ctrl_rumble">Vibração do jogo</string>
<string name="ctrl_dead_zone">Zona morta do manípulo</string>
<string name="ctrl_steam_button">Botão Steam</string>
<string name="ctrl_qam_button">Botão QAM</string>
<string name="ctrl_keyboard_button">Botão do teclado</string>
+1
View File
@@ -1104,6 +1104,7 @@
<string name="ctrl_stick_click_hint">Toque duas vezes e segure um analógico para L3 ou R3</string>
<string name="ctrl_adaptive">Analógicos adaptáveis</string>
<string name="ctrl_rumble">Vibração do jogo</string>
<string name="ctrl_dead_zone">Zona morta do analógico</string>
<string name="ctrl_steam_button">Botão Steam</string>
<string name="ctrl_qam_button">Botão QAM</string>
<string name="ctrl_keyboard_button">Botão do teclado</string>
+1
View File
@@ -1112,6 +1112,7 @@
<string name="ctrl_stick_click_hint">Apasă de două ori și ține apăsată o manșă pentru L3 sau R3</string>
<string name="ctrl_adaptive">Manșe adaptive</string>
<string name="ctrl_rumble">Vibrații de joc</string>
<string name="ctrl_dead_zone">Zonă moartă a manetei</string>
<string name="ctrl_steam_button">Butonul Steam</string>
<string name="ctrl_qam_button">Butonul QAM</string>
<string name="ctrl_keyboard_button">Butonul tastaturii</string>
+1
View File
@@ -1118,6 +1118,7 @@
<string name="ctrl_stick_click_hint">Дважды нажмите и удерживайте стик для L3 или R3</string>
<string name="ctrl_adaptive">Адаптивные стики</string>
<string name="ctrl_rumble">Вибрация в играх</string>
<string name="ctrl_dead_zone">Мёртвая зона стика</string>
<string name="ctrl_steam_button">Кнопка Steam</string>
<string name="ctrl_qam_button">Кнопка QAM</string>
<string name="ctrl_keyboard_button">Кнопка клавиатуры</string>
+1
View File
@@ -1106,6 +1106,7 @@
<string name="ctrl_stick_click_hint">Dubbeltryck och håll en spak för L3 eller R3</string>
<string name="ctrl_adaptive">Adaptiva spakar</string>
<string name="ctrl_rumble">Spelvibration</string>
<string name="ctrl_dead_zone">Styrspakens dödzon</string>
<string name="ctrl_steam_button">Steam-knappen</string>
<string name="ctrl_qam_button">QAM-knappen</string>
<string name="ctrl_keyboard_button">Tangentbordsknappen</string>
+1
View File
@@ -1100,6 +1100,7 @@
<string name="ctrl_stick_click_hint">แตะสองครั้งแล้วกดสติ๊กค้างไว้สำหรับ L3 หรือ R3</string>
<string name="ctrl_adaptive">สติ๊กแบบปรับอัตโนมัติ</string>
<string name="ctrl_rumble">การสั่นของเกม</string>
<string name="ctrl_dead_zone">เดดโซนของแอนะล็อกสติ๊ก</string>
<string name="ctrl_steam_button">ปุ่ม Steam</string>
<string name="ctrl_qam_button">ปุ่ม QAM</string>
<string name="ctrl_keyboard_button">ปุ่มแป้นพิมพ์</string>
+1
View File
@@ -1098,6 +1098,7 @@
<string name="ctrl_stick_click_hint">L3 veya R3 için bir çubuğa çift dokunup basılı tutun</string>
<string name="ctrl_adaptive">Uyarlanabilir çubuklar</string>
<string name="ctrl_rumble">Oyun titreşimi</string>
<string name="ctrl_dead_zone">Çubuk ölü bölgesi</string>
<string name="ctrl_steam_button">Steam düğmesi</string>
<string name="ctrl_qam_button">QAM düğmesi</string>
<string name="ctrl_keyboard_button">Klavye düğmesi</string>
+1
View File
@@ -1118,6 +1118,7 @@
<string name="ctrl_stick_click_hint">Двічі торкніться і затримайте стик, щоб отримати L3 або R3</string>
<string name="ctrl_adaptive">Адаптивні стики</string>
<string name="ctrl_rumble">Вібрація гри</string>
<string name="ctrl_dead_zone">Мертва зона стіка</string>
<string name="ctrl_steam_button">Кнопка Steam</string>
<string name="ctrl_qam_button">Кнопка QAM</string>
<string name="ctrl_keyboard_button">Кнопка клавіатури</string>
+1
View File
@@ -1100,6 +1100,7 @@
<string name="ctrl_stick_click_hint">Chạm hai lần và giữ một cần để dùng L3 hoặc R3</string>
<string name="ctrl_adaptive">Cần thích ứng</string>
<string name="ctrl_rumble">Rung khi chơi game</string>
<string name="ctrl_dead_zone">Vùng chết của cần điều khiển</string>
<string name="ctrl_steam_button">Nút Steam</string>
<string name="ctrl_qam_button">Nút QAM</string>
<string name="ctrl_keyboard_button">Nút bàn phím</string>
@@ -1184,6 +1184,7 @@
<string name="ctrl_stick_click_hint">双击并按住摇杆可触发 L3 或 R3</string>
<string name="ctrl_adaptive">自适应摇杆</string>
<string name="ctrl_rumble">游戏震动</string>
<string name="ctrl_dead_zone">摇杆死区</string>
<string name="ctrl_steam_button">Steam 按钮</string>
<string name="ctrl_qam_button">QAM 按钮</string>
<string name="ctrl_keyboard_button">键盘按钮</string>
@@ -1100,6 +1100,7 @@
<string name="ctrl_stick_click_hint">在搖桿上輕按兩下並按住,即可觸發 L3 或 R3</string>
<string name="ctrl_adaptive">自動調整搖桿</string>
<string name="ctrl_rumble">遊戲震動</string>
<string name="ctrl_dead_zone">搖桿死區</string>
<string name="ctrl_steam_button">Steam 按鈕</string>
<string name="ctrl_qam_button">QAM 按鈕</string>
<string name="ctrl_keyboard_button">鍵盤按鈕</string>
@@ -1100,6 +1100,7 @@
<string name="ctrl_stick_click_hint">點兩下並按住搖桿可觸發 L3 或 R3</string>
<string name="ctrl_adaptive">自適應搖桿</string>
<string name="ctrl_rumble">遊戲震動</string>
<string name="ctrl_dead_zone">搖桿死區</string>
<string name="ctrl_steam_button">Steam 按鈕</string>
<string name="ctrl_qam_button">QAM 按鈕</string>
<string name="ctrl_keyboard_button">鍵盤按鈕</string>
+1
View File
@@ -1198,6 +1198,7 @@
<string name="ctrl_stick_click_hint">Double-tap and hold a stick for L3 or R3</string>
<string name="ctrl_adaptive">Adaptive sticks</string>
<string name="ctrl_rumble">Game vibration</string>
<string name="ctrl_dead_zone">Stick dead zone</string>
<string name="ctrl_steam_button">Steam button</string>
<string name="ctrl_qam_button">QAM button</string>
<string name="ctrl_keyboard_button">Keyboard button</string>
@@ -440,13 +440,79 @@ class PadBridgeQamTest {
assertFalse(pad().isDown(PadState.GUIDE))
}
@Test fun zeroDeadZoneDriftDoesNotKeepAxesBlockedAfterBackRelease() {
val device = controller()
bridge.setStickDeadZone(0)
motion(device, MotionEvent.AXIS_X, 0.01f)
bridge.setBackQamPressed(true)
advanceTime()
bridge.setBackQamPressed(false)
advanceTime()
motion(device, MotionEvent.AXIS_X, 0.5f)
assertEquals(0.5f, pad().leftX)
}
@Test fun circularDiagonalDriftDoesNotKeepAxesBlockedAfterBackRelease() {
val device = controller()
motion(device, MotionEvent.AXIS_X to 0.09f, MotionEvent.AXIS_Y to 0.09f)
bridge.setBackQamPressed(true)
advanceTime()
bridge.setBackQamPressed(false)
advanceTime()
motion(device, MotionEvent.AXIS_X, 0.5f)
assertEquals(0.5f, pad().leftX)
}
@Test fun changingPreferenceDoesNotBypassARequiredPhysicalNeutralReturn() {
val device = controller()
bridge.setStickDeadZone(25)
motion(device, MotionEvent.AXIS_X, 0.2f)
bridge.setBackQamPressed(true)
advanceTime()
bridge.setBackQamPressed(false)
advanceTime()
bridge.setStickDeadZone(0)
assertEquals(0f, pad().leftX)
motion(device, MotionEvent.AXIS_X, 0.05f)
motion(device, MotionEvent.AXIS_X, 0.5f)
assertEquals(0.5f, pad().leftX)
}
@Test fun smallVirtualStickInputStillRequiresItsOriginalNeutralRelease() {
bridge.applyExternal({ it.leftX = 0.01f }, true)
bridge.setBackQamPressed(true)
advanceTime()
bridge.setBackQamPressed(false)
advanceTime()
bridge.applyExternal({ it.leftX = 0.5f }, true)
assertEquals(0f, pad().leftX)
bridge.applyExternal({ it.leftX = 0f }, true)
bridge.applyExternal({ it.leftX = 0.5f }, true)
assertEquals(0.5f, pad().leftX)
}
@Test fun smallTriggerInputStillRequiresItsOriginalNeutralRelease() {
bridge.applyExternal({ it.leftTrigger = 0.01f }, true)
bridge.setBackQamPressed(true)
advanceTime()
bridge.setBackQamPressed(false)
advanceTime()
bridge.applyExternal({ it.leftTrigger = 0.5f }, true)
assertEquals(0f, pad().leftTrigger)
bridge.applyExternal({ it.leftTrigger = 0f }, true)
bridge.applyExternal({ it.leftTrigger = 0.5f }, true)
assertEquals(0.5f, pad().leftTrigger)
}
private fun key(device: InputDevice, code: Int, action: Int = KeyEvent.ACTION_DOWN, repeat: Int = 0, scan: Int = 0) =
KeyEvent(0L, 0L, action, code, repeat, 0, device.id, scan, 0, InputDevice.SOURCE_GAMEPAD)
private fun motion(device: InputDevice, axis: Int, value: Float) {
private fun motion(device: InputDevice, axis: Int, value: Float) = motion(device, axis to value)
private fun motion(device: InputDevice, vararg values: Pair<Int, Float>) {
val event = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_MOVE, 1,
arrayOf(MotionEvent.PointerProperties().apply { id = 0 }),
arrayOf(MotionEvent.PointerCoords().apply { setAxisValue(axis, value) }),
arrayOf(MotionEvent.PointerCoords().apply { for ((axis, value) in values) setAxisValue(axis, value) }),
0, 0, 1f, 1f, device.id, 0, InputDevice.SOURCE_JOYSTICK, 0)
try { assertTrue(bridge.onMotionEvent(event)) } finally { event.recycle() }
}
@@ -0,0 +1,473 @@
package com.droiddeck.launcher.input
import android.hardware.input.InputManager
import android.os.Looper
import android.util.SparseArray
import android.view.InputDevice
import android.view.KeyEvent
import android.view.MotionEvent
import java.nio.file.Files
import java.time.Duration
import org.junit.After
import org.junit.Assert.*
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.Shadows.shadowOf
import org.robolectric.annotation.Config
import org.robolectric.shadows.InputDeviceBuilder
import org.robolectric.util.ReflectionHelpers
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [34], manifest = Config.NONE, instrumentedPackages = ["com.droiddeck.launcher.input.FakeInputWriter"],
shadows = [PadBridgeRoutingTest.RegisteredKeyEvent::class, PadBridgeRoutingTest.RegisteredMotionEvent::class,
JoyConPadTest.RecordingWriter::class])
class StickDeadZoneTest {
private val context get() = RuntimeEnvironment.getApplication()
private val directory = Files.createTempDirectory("stick-dead-zone").toFile()
private lateinit var bridge: PadBridge
@Before fun start() {
ControllerPrefs.prefs(context).edit().clear().commit()
JoyConPadTest.RecordingWriter.pads.clear()
bridge = PadBridge(directory)
assertTrue(bridge.start())
}
@After fun stop() {
bridge.stop()
ControllerPrefs.prefs(context).edit().clear().commit()
directory.deleteRecursively()
}
@Test fun preferencesDefaultToTwelveAndPersistZero() {
assertEquals(12, ControllerPrefs.read(context).deadZone)
assertEquals(listOf(0, 5, 8, 12, 15, 20, 25), ControllerPrefs.deadZones)
ControllerPrefs.setDeadZone(context, 0)
assertEquals(0, ControllerPrefs.read(context).deadZone)
}
@Test fun invalidPreferencesFallBackAndResetRestoresDefault() {
ControllerPrefs.setDeadZone(context, 99)
assertEquals(12, ControllerPrefs.deadZone(context))
ControllerPrefs.setDeadZone(context, 25)
ControllerPrefs.resetAll(context)
assertEquals(12, ControllerPrefs.deadZone(context))
}
@Test fun changingDeadZonePreservesOfficialShortcutsAndControllerSettings() {
val button = PhysicalShortcuts.Button("test-pad", "Test pad", KeyEvent.KEYCODE_BUTTON_MODE, 0)
val binding = PhysicalShortcuts.Binding(button, PhysicalShortcuts.Action.QAM)
PhysicalShortcuts.assign(context, button, binding.action)
ControllerPrefs.setTarget(context, "a", "b")
ControllerPrefs.setRumble(context, false)
for (percent in ControllerPrefs.deadZones) {
ControllerPrefs.setDeadZone(context, percent)
val settings = ControllerPrefs.read(context)
assertEquals(percent, settings.deadZone)
assertEquals(listOf(binding), PhysicalShortcuts.read(context))
assertEquals("b", settings.mapping["a"])
assertFalse(settings.rumble)
}
}
@Test fun assigningAnOfficialShortcutPreservesDeadZone() {
ControllerPrefs.setDeadZone(context, 25)
PhysicalShortcuts.assign(context,
PhysicalShortcuts.Button("test-pad", "Test pad", KeyEvent.KEYCODE_BUTTON_MODE, 0),
PhysicalShortcuts.Action.STEAM)
assertEquals(25, ControllerPrefs.read(context).deadZone)
}
@Test fun defaultSuppressesBothAxesInsideTheCircle() {
motion(device(), MotionEvent.AXIS_X to 0.05f, MotionEvent.AXIS_Y to -0.06f)
assertEquals(0f, pad().leftX)
assertEquals(0f, pad().leftY)
}
@Test fun diagonalOutsideTheCircleIsNotLostToAnAxisCross() {
motion(device(), MotionEvent.AXIS_X to 0.09f, MotionEvent.AXIS_Y to -0.09f)
assertEquals(0.09f, pad().leftX)
assertEquals(-0.09f, pad().leftY)
}
@Test fun smallCrossAxisMotionSurvivesWhenTheStickIsHeldOver() {
motion(device(), MotionEvent.AXIS_X to 0.6f, MotionEvent.AXIS_Y to 0.02f)
assertEquals(0.6f, pad().leftX)
assertEquals(0.02f, pad().leftY)
}
@Test fun zeroDisablesFilteringForBothSticks() {
bridge.setStickDeadZone(0)
motion(device(), MotionEvent.AXIS_X to 0.01f, MotionEvent.AXIS_Y to -0.02f,
MotionEvent.AXIS_Z to 0.03f, MotionEvent.AXIS_RZ to -0.04f)
assertEquals(0.01f, pad().leftX)
assertEquals(-0.02f, pad().leftY)
assertEquals(0.03f, pad().rightX)
assertEquals(-0.04f, pad().rightY)
}
@Test fun changingTheSettingAffectsTheExistingBridge() {
val device = device()
bridge.setStickDeadZone(25)
motion(device, MotionEvent.AXIS_X to 0.2f, MotionEvent.AXIS_Z to 0.4f)
assertEquals(0f, pad().leftX)
assertEquals(0.4f, pad().rightX)
bridge.setStickDeadZone(0)
assertEquals(0.2f, pad().leftX)
assertEquals(0.4f, pad().rightX)
}
@Test fun changingPreferenceReprojectsAllSticksWithoutAnotherMotionEvent() {
motion(device(), MotionEvent.AXIS_X to 0.2f, MotionEvent.AXIS_Y to 0.02f,
MotionEvent.AXIS_Z to 0.03f, MotionEvent.AXIS_RZ to -0.04f)
bridge.setStickDeadZone(25)
assertEquals(0f, pad().leftX)
assertEquals(0f, pad().rightY)
bridge.setStickDeadZone(0)
assertEquals(0.2f, pad().leftX)
assertEquals(0.02f, pad().leftY)
assertEquals(0.03f, pad().rightX)
assertEquals(-0.04f, pad().rightY)
}
@Test fun preferenceChangesReprojectEveryPlayer() {
motion(device(id = 61), MotionEvent.AXIS_X to 0.2f)
motion(device(id = 62), MotionEvent.AXIS_Z to -0.2f)
bridge.setStickDeadZone(25)
assertEquals(0f, pad().leftX)
assertEquals(0f, requireNotNull(JoyConPadTest.RecordingWriter.pads[1]).rightX)
bridge.setStickDeadZone(0)
assertEquals(0.2f, pad().leftX)
assertEquals(-0.2f, requireNotNull(JoyConPadTest.RecordingWriter.pads[1]).rightX)
}
@Test fun preferenceChangesReprojectBothHalvesOfAJoyConPair() {
val left = device(joyCon = true, id = 61)
val right = device(joyCon = true, id = 62, rightJoyCon = true)
motion(left)
motion(right)
motion(left, MotionEvent.AXIS_X to 0.2f)
motion(right, MotionEvent.AXIS_RX to -0.2f)
bridge.setStickDeadZone(25)
assertEquals(0f, pad().leftX)
assertEquals(0f, pad().rightX)
bridge.setStickDeadZone(0)
assertEquals(0.2f, pad().leftX)
assertEquals(-0.2f, pad().rightX)
}
@Test fun preferenceChangesDoNotReplaceTouchStickInput() {
motion(device(), MotionEvent.AXIS_X to 0.2f, MotionEvent.AXIS_Z to -0.2f)
bridge.applyTouch { it.leftX = 0.8f }
bridge.setStickDeadZone(25)
assertEquals(0.8f, pad().leftX)
assertEquals(0f, pad().rightX)
bridge.setStickDeadZone(0)
assertEquals(0.8f, pad().leftX)
assertEquals(-0.2f, pad().rightX)
}
@Test fun explicitZeroTouchWriteDiscardsFilteredPhysicalLeftStick() {
motion(device(), MotionEvent.AXIS_X to 0.05f, MotionEvent.AXIS_Z to -0.05f)
bridge.applyTouch(PadBridge.LEFT_STICK) { it.leftX = 0f; it.leftY = 0f }
bridge.setStickDeadZone(0)
assertEquals(0f, pad().leftX)
assertEquals(-0.05f, pad().rightX)
}
@Test fun explicitZeroTouchWriteDiscardsFilteredPhysicalRightStick() {
motion(device(), MotionEvent.AXIS_X to 0.05f, MotionEvent.AXIS_Z to -0.05f)
bridge.applyTouch(PadBridge.RIGHT_STICK) { it.rightX = 0f; it.rightY = 0f }
bridge.setStickDeadZone(0)
assertEquals(0.05f, pad().leftX)
assertEquals(0f, pad().rightX)
}
@Test fun routedTouchStickWritesKeepSeparatePhysicalInput() {
motion(device(), MotionEvent.AXIS_X to 0.05f)
bridge.setTouchRoute(object : PadBridge.TouchRoute {
override fun active() = true
override fun accept(state: PadState) { assertEquals(0f, state.leftX) }
})
bridge.applyTouch(PadBridge.LEFT_STICK) { it.leftX = 0f; it.leftY = 0f }
bridge.setStickDeadZone(0)
assertEquals(0.05f, pad().leftX)
}
@Test fun touchButtonOnlyWritesKeepFilteredPhysicalSticks() {
motion(device(), MotionEvent.AXIS_X to 0.05f)
bridge.applyTouch { it.press(PadState.A, true) }
bridge.setStickDeadZone(0)
assertEquals(0.05f, pad().leftX)
assertTrue(pad().isDown(PadState.A))
}
@Test fun preferenceChangesDoNotReplaceExternalStickInput() {
motion(device(), MotionEvent.AXIS_X to 0.2f, MotionEvent.AXIS_Z to -0.2f)
bridge.applyExternal({ it.rightX = 0.8f }, true)
bridge.setStickDeadZone(25)
assertEquals(0f, pad().leftX)
assertEquals(0.8f, pad().rightX)
}
@Test fun buttonAndTriggerMutationsKeepPhysicalSticksReprojectable() {
motion(device(), MotionEvent.AXIS_X to 0.2f)
bridge.applyExternal({ it.leftTrigger = 0.7f; it.press(PadState.X, true) }, true)
bridge.setStickDeadZone(25)
assertEquals(0f, pad().leftX)
assertEquals(0.7f, pad().leftTrigger)
assertTrue(pad().isDown(PadState.X))
bridge.setStickDeadZone(0)
assertEquals(0.2f, pad().leftX)
}
@Test fun releaseAllDiscardsEvenPreviouslyFilteredRawMotion() {
motion(device(), MotionEvent.AXIS_X to 0.05f)
bridge.releaseAll()
bridge.setStickDeadZone(0)
assertEquals(0f, pad().leftX)
}
@Test fun aDisconnectedControllerDoesNotReturnOnPreferenceChange() {
val device = device()
motion(device, MotionEvent.AXIS_X to 0.2f)
bridge.onDeviceRemoved(device.id)
bridge.setStickDeadZone(0)
assertEquals(0f, pad().leftX)
}
@Test fun pairingDoesNotRestoreAnOldJoyConPosition() {
val left = device(joyCon = true, id = 61)
val right = device(joyCon = true, id = 62, rightJoyCon = true)
motion(left, MotionEvent.AXIS_X to 0.2f)
motion(right)
bridge.setStickDeadZone(0)
assertEquals(0f, pad().leftX)
}
@Test fun aControllerRemovedWhileInactiveDoesNotReturnOnPreferenceChange() {
val device = device()
motion(device, MotionEvent.AXIS_X to 0.05f)
val manager = ReflectionHelpers.callStaticMethod<Any>(Class.forName("android.hardware.input.InputManagerGlobal"), "getInstance")
ReflectionHelpers.getField<SparseArray<InputDevice>>(manager, "mInputDevices").remove(device.id)
assertNull(InputDevice.getDevice(device.id))
bridge.setStickDeadZone(0)
assertEquals(0f, pad().leftX)
}
@Test fun excludedControllerInputIsNotRestoredOnPreferenceChange() {
val device = device()
motion(device, MotionEvent.AXIS_X to 0.2f)
bridge.setExcluded { it == device.id }
bridge.setStickDeadZone(0)
assertEquals(0f, pad().leftX)
}
@Test fun preferenceChangesDoNotGenerateChordInput() {
motion(device(), MotionEvent.AXIS_X to 0.2f)
var notifications = 0
bridge.setOnChordInput { notifications++ }
bridge.setStickDeadZone(25)
bridge.setStickDeadZone(0)
assertEquals(0, notifications)
}
@Test fun aStoppedBridgeDoesNotRepublishOldInput() {
motion(device(), MotionEvent.AXIS_X to 0.2f)
bridge.stop()
JoyConPadTest.RecordingWriter.pads.clear()
bridge.setStickDeadZone(0)
assertTrue(JoyConPadTest.RecordingWriter.pads.isEmpty())
}
@Test fun theBoundaryPassesThroughWithoutRescaling() {
assertFalse(PadBridge.inStickDeadZone(0.12f, 0f, 0.12f))
motion(device(), MotionEvent.AXIS_X to 0.12f)
assertEquals(0.12f, pad().leftX)
}
@Test fun wiredXboxKeepsItsRightStickAndSignedTriggerAxes() {
bridge.setStickDeadZone(0)
motion(device(wired = true), MotionEvent.AXIS_RX to 0.02f, MotionEvent.AXIS_RY to -0.03f,
MotionEvent.AXIS_Z to -1f, MotionEvent.AXIS_RZ to 1f)
assertEquals(0.02f, pad().rightX)
assertEquals(-0.03f, pad().rightY)
assertEquals(0f, pad().leftTrigger)
assertEquals(1f, pad().rightTrigger)
}
@Test fun joyConUsesTheSelectedDeadZone() {
bridge.setStickDeadZone(0)
motion(device(joyCon = true), MotionEvent.AXIS_X to 0.01f, MotionEvent.AXIS_Y to -0.02f)
assertEquals(0.01f, pad().leftX)
assertEquals(-0.02f, pad().leftY)
}
@Test fun stickSettingDoesNotChangeMouseAxisHelpers() {
bridge.setStickDeadZone(0)
for (wired in listOf(false, true)) {
var horizontal = 0f
var vertical = 0f
val mouse = PadMouse(object : PadMouse.Listener {
override fun active() = true
override fun onScrollStart() {}
override fun onScroll(dx: Float, dy: Float) { horizontal += dx; vertical += dy }
override fun onKey(evdev: Int, pressed: Boolean) {}
override fun onKeyboard() {}
override fun onNavigate() {}
override fun scrollSpeed() = 2000f
}) { 1000L }
val event = if (wired) event(device(wired = true, id = 62), MotionEvent.AXIS_RX to 0.02f,
MotionEvent.AXIS_RY to 0.6f, MotionEvent.AXIS_Z to -1f, MotionEvent.AXIS_RZ to -1f)
else event(device(), MotionEvent.AXIS_Z to 0.02f, MotionEvent.AXIS_RZ to 0.6f)
try {
assertTrue(mouse.onMotion(event))
mouse.step(0.1f)
assertEquals(0f, horizontal)
assertTrue(vertical > 0f)
} finally { event.recycle(); mouse.reset() }
}
}
@Test fun zeroDeadZoneDriftDoesNotConsumeBackTap() {
val (taps, presses) = backTapWithMotion(device(), MotionEvent.AXIS_X to 0.01f)
assertEquals(0.01f, pad().leftX)
assertEquals(listOf(false), taps)
assertTrue(presses.isEmpty())
}
@Test fun zeroDeadZoneJoyConDriftDoesNotConsumeBackTap() {
val (taps, presses) = backTapWithMotion(device(joyCon = true), MotionEvent.AXIS_X to 0.01f)
assertEquals(0.01f, pad().leftX)
assertEquals(listOf(false), taps)
assertTrue(presses.isEmpty())
}
@Test fun diagonalInsideTheLegacyChordGuardDoesNotConsumeBackTap() {
val (taps, presses) = backTapWithMotion(device(), MotionEvent.AXIS_X to 0.09f, MotionEvent.AXIS_Y to 0.09f)
assertEquals(0.09f, pad().leftX)
assertEquals(0.09f, pad().leftY)
assertEquals(listOf(false), taps)
assertTrue(presses.isEmpty())
}
@Test fun intentionalMotionOnEitherStickStillMakesABackChord() {
val device = device()
for (axis in intArrayOf(MotionEvent.AXIS_X, MotionEvent.AXIS_Z)) {
val (taps, presses) = backTapWithMotion(device, axis to 0.5f)
assertTrue(taps.isEmpty())
assertEquals(listOf(true, false), presses)
}
}
@Test fun higherGameDeadZoneDoesNotDisableExistingBackChords() {
val (taps, presses) = backTapWithMotion(device(), MotionEvent.AXIS_X to 0.2f, deadZone = 25)
assertEquals(0f, pad().leftX)
assertTrue(taps.isEmpty())
assertEquals(listOf(true, false), presses)
}
@Test fun higherGameDeadZoneDoesNotDisableExistingJoyConBackChords() {
val (taps, presses) = backTapWithMotion(device(joyCon = true), MotionEvent.AXIS_X to 0.2f, deadZone = 25)
assertEquals(0f, pad().leftX)
assertTrue(taps.isEmpty())
assertEquals(listOf(true, false), presses)
}
private fun backTapWithMotion(device: InputDevice, vararg axes: Pair<Int, Float>, deadZone: Int = 0): Pair<List<Boolean>, List<Boolean>> {
val taps = mutableListOf<Boolean>()
val presses = mutableListOf<Boolean>()
val input = BackQamInput(presses::add, taps::add)
bridge.setStickDeadZone(deadZone)
bridge.setOnChordInput(input::onChordInput)
assertTrue(input.onKeyEvent(KeyEvent(0, 100, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK,
0, 0, device.id, 0), true))
motion(device, *axes)
assertTrue(input.onKeyEvent(KeyEvent(0, 100, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK,
0, 0, device.id, 0), true))
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(500))
return taps to presses
}
@Test fun neutralScreenStickPressClearsRetainedPhysicalInput() {
val device = device()
for (adaptive in listOf(false, true)) {
ControllerPrefs.setAdaptiveSticks(context, adaptive)
ControllerPrefs.setLayout(context, 1200, 800, mapOf("ls" to (0.45f to 0.5f), "rs" to (0.55f to 0.5f)))
for (id in listOf("ls", "rs")) {
motion(device, MotionEvent.AXIS_X to 0.6f, MotionEvent.AXIS_Z to 0.7f)
val view = OnScreenControls(context, bridge)
view.layout(0, 0, 1200, 800)
val controls = ReflectionHelpers.getField<List<Any>>(view, "controls")
val control = controls.first { ReflectionHelpers.getField<String>(it, "id") == id }
val x = ReflectionHelpers.getField<Float>(control, "cx")
val y = ReflectionHelpers.getField<Float>(control, "cy")
val down = MotionEvent.obtain(1000, 1000, MotionEvent.ACTION_DOWN, x, y, 0)
try { assertTrue(view.onTouchEvent(down)) } finally { down.recycle() }
assertFalse(ReflectionHelpers.getField<Boolean>(control, "dirty"))
assertEquals(0f, if (id == "ls") pad().leftX else pad().rightX, 0f)
assertTrue((if (id == "ls") pad().rightX else pad().leftX) > 0f)
bridge.setStickDeadZone(25)
assertEquals(0f, if (id == "ls") pad().leftX else pad().rightX, 0f)
motion(device, MotionEvent.AXIS_X to 0.6f, MotionEvent.AXIS_Z to 0.7f)
val button = controls.first { ReflectionHelpers.getField<String>(it, "id") == "a" }
val bx = ReflectionHelpers.getField<Float>(button, "cx")
val by = ReflectionHelpers.getField<Float>(button, "cy")
fun buttonTouch(action: Int, time: Long) {
val event = MotionEvent.obtain(1000, time, action or (1 shl MotionEvent.ACTION_POINTER_INDEX_SHIFT), 2,
arrayOf(MotionEvent.PointerProperties().apply { this.id = 0; toolType = MotionEvent.TOOL_TYPE_FINGER },
MotionEvent.PointerProperties().apply { this.id = 1; toolType = MotionEvent.TOOL_TYPE_FINGER }),
arrayOf(MotionEvent.PointerCoords().apply { this.x = x; this.y = y },
MotionEvent.PointerCoords().apply { this.x = bx; this.y = by }),
0, 0, 1f, 1f, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0)
try { assertTrue(view.onTouchEvent(event)) } finally { event.recycle() }
}
buttonTouch(MotionEvent.ACTION_POINTER_DOWN, 1030)
assertTrue(pad().isDown(PadState.A))
assertEquals(0.6f, pad().leftX, 0f)
assertEquals(0.7f, pad().rightX, 0f)
buttonTouch(MotionEvent.ACTION_POINTER_UP, 1060)
assertFalse(pad().isDown(PadState.A))
bridge.setStickDeadZone(12)
assertEquals(0.6f, pad().leftX, 0f)
assertEquals(0.7f, pad().rightX, 0f)
val up = MotionEvent.obtain(1000, 1100, MotionEvent.ACTION_UP, x, y, 0)
try { assertTrue(view.onTouchEvent(up)) } finally { up.recycle() }
}
}
}
private fun pad() = requireNotNull(JoyConPadTest.RecordingWriter.pads[0])
private fun motion(device: InputDevice, vararg axes: Pair<Int, Float>) {
val event = event(device, *axes)
try { assertTrue(bridge.onMotionEvent(event)) } finally { event.recycle() }
}
private fun event(device: InputDevice, vararg axes: Pair<Int, Float>): MotionEvent {
val coords = MotionEvent.PointerCoords().apply { for ((axis, value) in axes) setAxisValue(axis, value) }
return MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_MOVE, 1,
arrayOf(MotionEvent.PointerProperties().apply { id = 0 }), arrayOf(coords),
0, 0, 1f, 1f, device.id, 0, InputDevice.SOURCE_JOYSTICK, 0)
}
private fun device(wired: Boolean = false, joyCon: Boolean = false, id: Int = 61, rightJoyCon: Boolean = false): InputDevice {
val builder = InputDeviceBuilder.newBuilder().setId(id)
.setName(if (joyCon) if (rightJoyCon) "Joy-Con (R)" else "Joy-Con (L)" else "dead-zone pad")
.setDescriptor("dead-zone-pad-$id").setExternal(true)
.setSources(InputDevice.SOURCE_GAMEPAD or InputDevice.SOURCE_JOYSTICK)
.setKeyboardType(InputDevice.KEYBOARD_TYPE_NON_ALPHABETIC)
.setVendorId(if (joyCon) 0x057e else if (wired) 0x20d6 else 0)
.setProductId(if (joyCon) if (rightJoyCon) 0x2007 else 0x2006 else if (wired) 0x2063 else 0)
for (axis in intArrayOf(MotionEvent.AXIS_X, MotionEvent.AXIS_Y, MotionEvent.AXIS_Z,
MotionEvent.AXIS_RZ, MotionEvent.AXIS_RX, MotionEvent.AXIS_RY)) {
builder.addMotionRange(axis, InputDevice.SOURCE_JOYSTICK, -1f, 1f, 0f, 0f, 0f)
}
return builder.build().also {
shadowOf(context.getSystemService(InputManager::class.java)).addInputDevice(it)
}
}
}