mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
fix(input): add radial stick dead zone setting
This commit is contained in:
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()
|
||||
|
||||
Reference in new issue
Block a user