Add Game Space's Air Trigger actions, vibration and light effects (#3752)

Game Space's shoulder trigger settings have more than a button mapping.
The Air Triggers panel now offers the same options:

- Vibration when a trigger is touched.
- The shade Game Space draws on the screen edge under a touched trigger,
  red for the left trigger and blue for the right.
- The trigger LED effect: off, steady or pulse. DroidDeck sends the code
  RedMagic's lighting settings give that effect.
- Per trigger and layout: single tap holds the button while the trigger
  is touched (the previous behaviour), long press keeps it pressed until
  the next touch, and rapid fire clicks it while the trigger is held at
  Game Space's low, normal or high click frequency (2, 5 or 10 clicks a
  second).

Vibration, the shade and the LEDs follow the finger on the trigger, not
the clicks rapid fire sends. Long press and rapid fire press a toggle
button as a plain one, and on-screen buttons vibrate only for finger
presses.
This commit is contained in:
K11MCH1 authored and GitHub committed 2026-12-06 00:33:16 +09:00
1 parent b9f149b3c9
commit b63a72affb
40 files changed
+1035 -51

No files matched your search

@@ -104,6 +104,7 @@ import com.droiddeck.launcher.input.AirTrigger
import com.droiddeck.launcher.input.AirTriggerButtons
import com.droiddeck.launcher.input.AirTriggerInput
import com.droiddeck.launcher.input.AirTriggerPrefs
import com.droiddeck.launcher.input.AirTriggerSetup
import com.droiddeck.launcher.input.RedMagicAirTriggers
import com.droiddeck.launcher.input.PenStream
import com.droiddeck.launcher.input.PointerGestures
@@ -249,6 +250,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
private var airTriggerInput: AirTriggerInput? = null
private var airTriggersOpen = false
private var airTriggerMenu by mutableStateOf<com.droiddeck.launcher.ui.AirTriggerMenu?>(null)
private var airTriggerGlow: com.droiddeck.launcher.ui.AirTriggerGlow? = null
private var inputSettingsOpen by mutableStateOf(false)
@Volatile private var inputUsesLocalActions = false
private var inputUsesPointer = false
@@ -983,7 +985,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
padBridge = bridge
inputRouter = InputRouter(inputOutput).also { bridge.setInputRouter(it); DeckControls.setRouter(it); physicalInputBindings = com.droiddeck.launcher.input.PhysicalInputBindings(it) }
if (RedMagicAirTriggers.supported(this)) {
airTriggerInput = AirTriggerInput(bridge, ::holdOnScreen, RedMagicAirTriggers::light)
airTriggerInput = AirTriggerInput(bridge, ::holdOnScreen, ::airTriggerTouched)
RedMagicAirTriggers.restore(this)
}
refreshInputProfile()
@@ -1111,6 +1113,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
override fun onResolvePointerIcon(event: MotionEvent, pointerIndex: Int): android.view.PointerIcon? =
if (platformPointerShown == true) super.onResolvePointerIcon(event, pointerIndex) else null
}.apply { addView(sessionOverlay) })
if (airTriggerInput != null) airTriggerGlow = com.droiddeck.launcher.ui.AirTriggerGlow(this).also { root.addView(it) }
setContentView(root)
glassesScope.launch { Glasses.state.collect {
glasses = it
@@ -1955,6 +1958,21 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
AirTriggerPrefs.setButton(this@SessionActivity, primaryInputLayout?.id.orEmpty(), trigger, id)
refreshAirTriggers()
},
onAirTriggerAction = { trigger, action ->
AirTriggerPrefs.setAction(this@SessionActivity, primaryInputLayout?.id.orEmpty(), trigger, action)
refreshAirTriggers()
},
onAirTriggerRate = { trigger, rate ->
AirTriggerPrefs.setRate(this@SessionActivity, primaryInputLayout?.id.orEmpty(), trigger, rate)
refreshAirTriggers()
},
onAirTriggerVibration = { on -> AirTriggerPrefs.setVibration(this@SessionActivity, on); refreshAirTriggers() },
onAirTriggerScreenLight = { on -> AirTriggerPrefs.setScreenLight(this@SessionActivity, on); refreshAirTriggers() },
onAirTriggerLed = { led ->
AirTriggerPrefs.setLed(this@SessionActivity, led)
if (airTriggersOpen) RedMagicAirTriggers.open(this@SessionActivity)
refreshAirTriggers()
},
onControllerSize = { percent -> updateControllerPrefs { ControllerPrefs.setSize(this@SessionActivity, percent) } },
onControllerOpacity = { percent ->
ControllerPrefs.setOnScreenOpacity(this@SessionActivity, percent)
@@ -5154,16 +5172,27 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
private fun refreshAirTriggers() {
val input = airTriggerInput ?: return
val layout = primaryInputLayout
val layoutId = layout?.id.orEmpty()
val enabled = AirTriggerPrefs.enabled(this)
val chosen = AirTrigger.entries.associateWith { AirTriggerButtons.resolve(layout, it, AirTriggerPrefs.button(this, layout?.id.orEmpty(), it)) }
val chosen = AirTrigger.entries.associateWith {
AirTriggerSetup(AirTriggerButtons.resolve(layout, it, AirTriggerPrefs.button(this, layoutId, it)),
AirTriggerPrefs.action(this, layoutId, it), AirTriggerPrefs.rate(this, layoutId, it))
}
val active = enabled && resumed && !ended && !SessionState.suspended
input.configure(if (active) chosen else emptyMap())
if (active != airTriggersOpen) {
airTriggersOpen = active
if (active) RedMagicAirTriggers.open(this) else RedMagicAirTriggers.restore(this)
}
airTriggerMenu = com.droiddeck.launcher.ui.AirTriggerMenu(enabled, chosen.mapValues { it.value.id },
AirTriggerButtons.options(layout).map { it.id to it.name })
airTriggerMenu = com.droiddeck.launcher.ui.AirTriggerMenu(enabled, chosen.mapValues { it.value.element.id },
AirTriggerButtons.options(layout).map { it.id to it.name }, AirTriggerPrefs.vibration(this), AirTriggerPrefs.screenLight(this),
AirTriggerPrefs.led(this), chosen.mapValues { it.value.action }, chosen.mapValues { it.value.rate })
}
private fun airTriggerTouched(trigger: AirTrigger, down: Boolean) {
RedMagicAirTriggers.light(if (down) trigger.pressLight else trigger.releaseLight)
if (down && AirTriggerPrefs.vibration(this)) com.droiddeck.launcher.ui.ControllerHaptics.click(this)
airTriggerGlow?.show(trigger, down && AirTriggerPrefs.screenLight(this))
}
private fun tapQam() {
@@ -32,6 +32,26 @@ enum class AirTrigger(val keyCode: Int, val control: InputControl, val pressLigh
}
}
/** Game Space's single tap holds the button while the trigger is touched; its long press latches it until the next touch. */
enum class AirTriggerAction { TAP, LATCH, RAPID }
/** Game Space's rapid fire counts for its low, normal and high click frequency. */
enum class RapidFireRate(val clicksPerSecond: Int) { LOW(2), NORMAL(5), HIGH(10) }
/** Game Space's touch atmosphere lamp cases, by their name in RedMagic's shoulder light settings. */
enum class AirTriggerLed(val effect: String, val fallback: String) {
OFF("close", "02000000"), STEADY("steady", "02101000"), PULSE("pulse", "02102000")
}
data class AirTriggerSetup(
val element: InputSurfaceElement,
val action: AirTriggerAction = AirTriggerAction.TAP,
val rate: RapidFireRate = RapidFireRate.NORMAL,
) {
/** Long press and rapid fire decide when the button is let go, so they press a toggle button as a plain one. */
internal val target get() = if (action != AirTriggerAction.TAP && element.toggle) element.copy(toggle = false) else element
}
object AirTriggerButtons {
fun options(layout: SavedInputLayout?): List<InputSurfaceElement> {
val placed = layout?.let { (it.elements + it.rotated).distinctBy { element -> element.id } }.orEmpty()
@@ -49,6 +69,9 @@ object AirTriggerButtons {
object AirTriggerPrefs {
private const val FILE = "redmagic-air-triggers"
private const val ENABLED = "enabled"
private const val VIBRATION = "vibration"
private const val SCREEN_LIGHT = "screen-light"
private const val LED = "led"
internal const val OWNED = "distribute-owned"
fun prefs(context: Context): SharedPreferences = context.getSharedPreferences(FILE, Context.MODE_PRIVATE)
@@ -57,8 +80,24 @@ object AirTriggerPrefs {
fun button(context: Context, layoutId: String, trigger: AirTrigger): String? = prefs(context).getString(key(layoutId, trigger), null)
fun setButton(context: Context, layoutId: String, trigger: AirTrigger, elementId: String) =
prefs(context).edit().putString(key(layoutId, trigger), elementId).apply()
fun action(context: Context, layoutId: String, trigger: AirTrigger) = read(context, key(layoutId, trigger, "action"), AirTriggerAction.TAP)
fun setAction(context: Context, layoutId: String, trigger: AirTrigger, action: AirTriggerAction) =
prefs(context).edit().putString(key(layoutId, trigger, "action"), action.name).apply()
fun rate(context: Context, layoutId: String, trigger: AirTrigger) = read(context, key(layoutId, trigger, "rate"), RapidFireRate.NORMAL)
fun setRate(context: Context, layoutId: String, trigger: AirTrigger, rate: RapidFireRate) =
prefs(context).edit().putString(key(layoutId, trigger, "rate"), rate.name).apply()
fun vibration(context: Context) = prefs(context).getBoolean(VIBRATION, false)
fun setVibration(context: Context, on: Boolean) = prefs(context).edit().putBoolean(VIBRATION, on).apply()
fun screenLight(context: Context) = prefs(context).getBoolean(SCREEN_LIGHT, false)
fun setScreenLight(context: Context, on: Boolean) = prefs(context).edit().putBoolean(SCREEN_LIGHT, on).apply()
fun led(context: Context) = read(context, LED, AirTriggerLed.STEADY)
fun setLed(context: Context, led: AirTriggerLed) = prefs(context).edit().putString(LED, led.name).apply()
private fun key(layoutId: String, trigger: AirTrigger) = "${trigger.name.lowercase()}.$layoutId"
private inline fun <reified E : Enum<E>> read(context: Context, key: String, default: E): E =
prefs(context).getString(key, null)?.let { name -> enumValues<E>().firstOrNull { it.name == name } } ?: default
private fun key(layoutId: String, trigger: AirTrigger, setting: String? = null) =
listOfNotNull(trigger.name.lowercase(), setting).joinToString("-") + ".$layoutId"
}
/** Game Space's exported provider switches the triggers to plain F7/F8 keys without its panel, and needs no permission. */
@@ -100,15 +139,15 @@ object RedMagicAirTriggers {
if (!prefs.getBoolean(AirTriggerPrefs.OWNED, false)) return
lights.request(SHOULDER_LIGHT_ON)
// The light service drops every trigger light until an effect is set, which Game Space only does from its own view.
shoulderEffect(Settings.Global.getString(app.contentResolver, SHOULDER_SETTINGS))?.let(lights::setEffect)
lights.setEffect(shoulderEffect(Settings.Global.getString(app.contentResolver, SHOULDER_SETTINGS), AirTriggerPrefs.led(app)))
// Entering the scene turns the lights off; the release actions show the idle light picked in RedMagic's lighting settings.
AirTrigger.entries.forEach { lights.request(it.releaseLight) }
}
/** The trigger light effect the user picked in RedMagic's lighting settings, such as "02101000" for steady. */
internal fun shoulderEffect(settings: String?): String? = settings
?.let { runCatching { JSONObject(it).optString("selection") }.getOrNull() }
?.takeIf { it.length == 8 }
/** The code RedMagic's shoulder light settings give the effect, such as "02101000" for steady. */
internal fun shoulderEffect(settings: String?, led: AirTriggerLed): String = settings
?.let { runCatching { JSONObject(it).optJSONObject("shoulder_effects")?.optString(led.effect) }.getOrNull() }
?.takeIf { it.length == 8 } ?: led.fallback
/** Closes only what this app opened, so a distribute another app turned on stays on. Call on the main thread. */
fun restore(context: Context) {
@@ -175,19 +214,28 @@ private object ColorfulLights : TriggerLights {
class AirTriggerInput(
private val pad: PadBridge,
private val onScreen: (elementId: String, trigger: AirTrigger, held: Boolean, cancelled: Boolean) -> Boolean = { _, _, _, _ -> false },
private val light: (Int) -> Unit = {},
private val touched: (AirTrigger, Boolean) -> Unit = { _, _ -> },
private val handler: Handler = Handler(Looper.getMainLooper()),
) {
private val sources = EnumMap<AirTrigger, InputSurfaceSource>(AirTrigger::class.java)
private val setups = EnumMap<AirTrigger, AirTriggerSetup>(AirTrigger::class.java)
private val held = EnumSet.noneOf(AirTrigger::class.java)
private val pressed = EnumSet.noneOf(AirTrigger::class.java)
private val heldOnScreen = EnumMap<AirTrigger, String>(AirTrigger::class.java)
private val timers = EnumMap<AirTrigger, Runnable>(AirTrigger::class.java)
fun configure(elements: Map<AirTrigger, InputSurfaceElement>) {
fun configure(setups: Map<AirTrigger, AirTriggerSetup>) {
for (trigger in AirTrigger.entries) {
val element = elements[trigger]
if (sources[trigger]?.element == element) continue
heldOnScreen.remove(trigger)?.let { onScreen(it, trigger, false, true) }
sources.remove(trigger)?.close()
if (element != null) sources[trigger] = InputSurfaceSource(pad, InputRole.PRIMARY, element)
val setup = setups[trigger]
if (this.setups[trigger] == setup) continue
stop(trigger)
if (sources[trigger]?.element != setup?.target) {
pressed.remove(trigger)
heldOnScreen.remove(trigger)?.let { onScreen(it, trigger, false, true) }
sources.remove(trigger)?.close()
if (setup != null) sources[trigger] = InputSurfaceSource(pad, InputRole.PRIMARY, setup.target)
} else if (trigger in pressed) unpress(trigger, cancelled = true)
if (setup != null) this.setups[trigger] = setup else this.setups.remove(trigger)
}
}
@@ -200,29 +248,61 @@ class AirTriggerInput(
fun onKey(trigger: AirTrigger, action: Int, repeatCount: Int, enabled: Boolean): Boolean {
val source = sources[trigger]
when (action) {
KeyEvent.ACTION_DOWN -> if (source != null && enabled && repeatCount == 0 && held.add(trigger)) press(trigger, source)
KeyEvent.ACTION_UP -> if (held.remove(trigger)) { unpress(trigger, cancelled = false); return true }
KeyEvent.ACTION_DOWN -> if (source != null && enabled && repeatCount == 0 && held.add(trigger)) {
touched(trigger, true)
val setup = setups[trigger]
if (setup?.action == AirTriggerAction.LATCH && trigger in pressed) unpress(trigger, cancelled = false)
else if (trigger !in pressed) {
press(trigger, source)
if (setup?.action == AirTriggerAction.RAPID) rapid(trigger, 500L / setup.rate.clicksPerSecond)
}
}
KeyEvent.ACTION_UP -> if (held.remove(trigger)) {
touched(trigger, false)
if (setups[trigger]?.action != AirTriggerAction.LATCH) {
stop(trigger)
if (trigger in pressed) unpress(trigger, cancelled = false)
}
return true
}
}
return source != null
}
private fun rapid(trigger: AirTrigger, halfPeriod: Long) {
val tick = object : Runnable {
override fun run() {
if (trigger in pressed) unpress(trigger, cancelled = false) else sources[trigger]?.let { press(trigger, it) }
handler.postDelayed(this, halfPeriod)
}
}
timers[trigger] = tick
handler.postDelayed(tick, halfPeriod)
}
private fun stop(trigger: AirTrigger) {
timers.remove(trigger)?.let(handler::removeCallbacks)
}
private fun press(trigger: AirTrigger, source: InputSurfaceSource) {
if (onScreen(source.element.id, trigger, true, false)) {
pressed += trigger
if (source.element == setups[trigger]?.element && onScreen(source.element.id, trigger, true, false)) {
heldOnScreen[trigger] = source.element.id
// The router counts held keys, so a toggle latched while its button was hidden is released before the button takes over.
if (source.latched) source.release()
} else source.update(1f)
light(trigger.pressLight)
}
private fun unpress(trigger: AirTrigger, cancelled: Boolean) {
pressed -= trigger
heldOnScreen.remove(trigger)?.let { onScreen(it, trigger, false, cancelled) }
?: sources[trigger]?.let { if (cancelled) it.cancel() else it.update(0f) }
light(trigger.releaseLight)
}
fun release() {
held.toList().forEach { held.remove(it); unpress(it, cancelled = true) }
AirTrigger.entries.forEach(::stop)
held.toList().forEach { held.remove(it); touched(it, false) }
pressed.toList().forEach { unpress(it, cancelled = true) }
sources.values.forEach { it.release() }
}
@@ -230,5 +310,6 @@ class AirTriggerInput(
release()
sources.values.forEach { it.close() }
sources.clear()
setups.clear()
}
}
@@ -0,0 +1,62 @@
package com.droiddeck.launcher.ui
import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.LinearGradient
import android.graphics.Paint
import android.graphics.Shader
import android.view.View
import android.widget.FrameLayout
import com.droiddeck.launcher.input.AirTrigger
import java.util.EnumMap
import java.util.EnumSet
@SuppressLint("ViewConstructor")
class AirTriggerGlow(context: Context) : View(context) {
private val lit = EnumSet.noneOf(AirTrigger::class.java)
private val density = resources.displayMetrics.density
private val paints = EnumMap<AirTrigger, Paint>(AirTrigger::class.java)
init {
isClickable = false
isFocusable = false
importantForAccessibility = IMPORTANT_FOR_ACCESSIBILITY_NO
layoutParams = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)
val top = TOP_DP * density
for ((trigger, look) in mapOf(AirTrigger.LEFT to LEFT, AirTrigger.RIGHT to RIGHT)) {
val (color, fade) = look
paints[trigger] = Paint().apply {
shader = LinearGradient(0f, top, 0f, top + HEIGHT_DP * density,
fade.map { Color.argb(it, Color.red(color), Color.green(color), Color.blue(color)) }.toIntArray(),
STOPS, Shader.TileMode.CLAMP)
}
}
}
fun show(trigger: AirTrigger, on: Boolean) {
if (if (on) lit.add(trigger) else lit.remove(trigger)) invalidate()
}
override fun onDraw(canvas: Canvas) {
val width = WIDTH_DP * density
val margin = SIDE_DP * density
val top = TOP_DP * density
for (trigger in lit) {
val left = if (trigger == AirTrigger.LEFT) margin else this.width - margin - width
canvas.drawRect(left, top, left + width, top + HEIGHT_DP * density, paints.getValue(trigger))
}
}
private companion object {
// Game Space's tgk_*_top_pressed images and their landscape placement on a 2688 x 1216 RedMagic screen.
const val WIDTH_DP = 78f
const val HEIGHT_DP = 33f
const val SIDE_DP = 37f
const val TOP_DP = 2f
val STOPS = floatArrayOf(0f, 0.04f, 0.05f, 0.2f, 0.4f, 0.6f, 0.8f, 1f)
val LEFT = Color.rgb(230, 23, 57) to listOf(255, 255, 150, 102, 55, 36, 18, 0)
val RIGHT = Color.rgb(23, 91, 230) to listOf(255, 255, 151, 94, 41, 27, 14, 0)
}
}
@@ -24,7 +24,11 @@ object ControllerHaptics {
tick(context)
}
fun tick(context: Context) {
fun tick(context: Context) = vibrate(context, VibrationEffect.EFFECT_TICK, 10)
fun click(context: Context) = vibrate(context, VibrationEffect.EFFECT_CLICK, 20)
private fun vibrate(context: Context, predefined: Int, fallbackMs: Long) {
val vibrator = if (Build.VERSION.SDK_INT >= 31) {
context.getSystemService(VibratorManager::class.java)?.defaultVibrator
} else {
@@ -32,11 +36,11 @@ object ControllerHaptics {
} ?: return
if (!vibrator.hasVibrator()) return
if (Build.VERSION.SDK_INT >= 29) {
vibrator.vibrate(VibrationEffect.createPredefined(VibrationEffect.EFFECT_TICK))
vibrator.vibrate(VibrationEffect.createPredefined(predefined))
} else if (Build.VERSION.SDK_INT >= 26) {
vibrator.vibrate(VibrationEffect.createOneShot(10, VibrationEffect.DEFAULT_AMPLITUDE))
vibrator.vibrate(VibrationEffect.createOneShot(fallbackMs, VibrationEffect.DEFAULT_AMPLITUDE))
} else {
@Suppress("DEPRECATION") vibrator.vibrate(10)
@Suppress("DEPRECATION") vibrator.vibrate(fallbackMs)
}
}
}
@@ -495,7 +495,7 @@ class InputSurfaceView(
fun press(pointer: Int, pressed: Boolean, cancelled: Boolean = false) {
if (pressed) pointers.add(pointer) else pointers.remove(pointer)
set(pointers.isNotEmpty(), cancelled)
set(pointers.isNotEmpty(), cancelled, touch = pointer >= 0)
}
fun cancel() { pointers.clear(); set(false, cancelled = true); source?.release() }
@@ -507,10 +507,10 @@ class InputSurfaceView(
override fun onDetachedFromWindow() { cancel(); super.onDetachedFromWindow() }
private fun set(pressed: Boolean, cancelled: Boolean = false) {
private fun set(pressed: Boolean, cancelled: Boolean = false, touch: Boolean = true) {
if (down == pressed) return
down = pressed
if (pressed) feedback(this, HapticFeedbackConstants.VIRTUAL_KEY)
if (pressed && touch) feedback(this, HapticFeedbackConstants.VIRTUAL_KEY)
if (!pressed && cancelled) source?.cancel() else source?.update(if (pressed) 1f else 0f)
invalidate()
if (artwork != null && this in artworkDpad) customCanvas?.invalidate()
@@ -117,6 +117,9 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.droiddeck.launcher.HomeApp
import com.droiddeck.launcher.input.AirTrigger
import com.droiddeck.launcher.input.AirTriggerAction
import com.droiddeck.launcher.input.AirTriggerLed
import com.droiddeck.launcher.input.RapidFireRate
import com.droiddeck.launcher.input.ControllerPrefs
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.animateColorAsState
@@ -239,7 +242,11 @@ private class DrawerFocus {
fun forget(page: SessionDrawerPage) { last.remove(page) }
}
data class AirTriggerMenu(val enabled: Boolean, val selected: Map<AirTrigger, String>, val buttons: List<Pair<String, String>>)
data class AirTriggerMenu(
val enabled: Boolean, val selected: Map<AirTrigger, String>, val buttons: List<Pair<String, String>>,
val vibration: Boolean = false, val screenLight: Boolean = false, val led: AirTriggerLed = AirTriggerLed.STEADY,
val actions: Map<AirTrigger, AirTriggerAction> = emptyMap(), val rates: Map<AirTrigger, RapidFireRate> = emptyMap(),
)
class DrawerActions(
val steam: Boolean,
@@ -349,6 +356,11 @@ class DrawerActions(
val airTriggers: AirTriggerMenu? = null,
val onAirTriggers: (Boolean) -> Unit = {},
val onAirTriggerButton: (AirTrigger, String) -> Unit = { _, _ -> },
val onAirTriggerAction: (AirTrigger, AirTriggerAction) -> Unit = { _, _ -> },
val onAirTriggerRate: (AirTrigger, RapidFireRate) -> Unit = { _, _ -> },
val onAirTriggerVibration: (Boolean) -> Unit = {},
val onAirTriggerScreenLight: (Boolean) -> Unit = {},
val onAirTriggerLed: (AirTriggerLed) -> Unit = {},
val onSuspendPolicy: (String) -> Unit,
val onSteamDownloadsInBackground: (Boolean) -> Unit = {},
val onBackActionsInverted: (Boolean) -> Unit,
@@ -1391,15 +1403,94 @@ private fun AirTriggersPanel(host: MenuHost, t: AirTriggerMenu, a: DrawerActions
CompositionLocalProvider(LocalDrawerSections provides null) { SettingsGroup(stringResource(R.string.air_triggers_title)) {
ToggleRow(host, "air-triggers-toggle", stringResource(R.string.air_triggers_use), stringResource(R.string.air_triggers_use_hint), t.enabled,
chipModifier = track("air-triggers-toggle"), onChange = a.onAirTriggers)
ToggleRow(host, "air-triggers-vibration", stringResource(R.string.air_triggers_vibration), stringResource(R.string.air_triggers_vibration_hint),
t.vibration, enabled = t.enabled, chipModifier = track("air-triggers-vibration"), onChange = a.onAirTriggerVibration)
ToggleRow(host, "air-triggers-screen-light", stringResource(R.string.air_triggers_screen_light), stringResource(R.string.air_triggers_screen_light_hint),
t.screenLight, enabled = t.enabled, chipModifier = track("air-triggers-screen-light"), onChange = a.onAirTriggerScreenLight)
val leds = listOf(AirTriggerLed.OFF to R.string.air_triggers_led_off, AirTriggerLed.STEADY to R.string.air_triggers_led_steady,
AirTriggerLed.PULSE to R.string.air_triggers_led_pulse).map { (led, text) -> led to stringResource(text) }
ChoiceRow(host, "air-triggers-led", stringResource(R.string.air_triggers_led), null, leds, t.led,
enabled = t.enabled, chipModifier = track("air-triggers-led"), onPick = a.onAirTriggerLed)
for (trigger in AirTrigger.entries) {
val key = "air-trigger-${trigger.name.lowercase()}"
val label = stringResource(if (trigger == AirTrigger.LEFT) R.string.air_trigger_left else R.string.air_trigger_right)
val left = trigger == AirTrigger.LEFT
val label = stringResource(if (left) R.string.air_trigger_left else R.string.air_trigger_right)
ChoiceRow(host, key, label, stringResource(R.string.air_trigger_button_hint), t.buttons, t.selected.getValue(trigger),
enabled = t.enabled, chipModifier = track(key)) { a.onAirTriggerButton(trigger, it) }
AirTriggerActionRow(host, "$key-action", stringResource(if (left) R.string.air_trigger_left_action else R.string.air_trigger_right_action),
t.actions[trigger] ?: AirTriggerAction.TAP, t.rates[trigger] ?: RapidFireRate.NORMAL, t.enabled, track("$key-action"),
onAction = { a.onAirTriggerAction(trigger, it) }, onRate = { a.onAirTriggerRate(trigger, it) })
}
} }
}
@Composable
private fun AirTriggerActionRow(
host: MenuHost, key: String, label: String, action: AirTriggerAction, rate: RapidFireRate, enabled: Boolean, chipModifier: Modifier,
onAction: (AirTriggerAction) -> Unit, onRate: (RapidFireRate) -> Unit,
) {
val open = host.open == key
var rateOpen by remember { mutableStateOf(false) }
LaunchedEffect(open) { if (!open) rateOpen = false }
val actions = listOf(AirTriggerAction.TAP to R.string.air_trigger_action_tap, AirTriggerAction.LATCH to R.string.air_trigger_action_hold,
AirTriggerAction.RAPID to R.string.air_trigger_action_rapid).map { (value, text) -> value to stringResource(text) }
val rates = listOf(R.string.air_trigger_rate_low, R.string.air_trigger_rate_normal, R.string.air_trigger_rate_high).map { stringResource(it) }
val rapidLabel = actions.last().second
val frequency = stringResource(R.string.air_trigger_rapid_frequency)
SettingsRow(label, null, highlighted = open) { Box {
ValueChip(actions.first { it.first == action }.second, open, enabled, modifier = chipModifier.testTag("setting-$key")) {
host.open = if (open) null else key
}
AnchoredMenu(open, onDismiss = { if (host.open == key) host.open = null }, title = if (rateOpen) null else label) { first ->
val arrowFocus = remember { FocusRequester() }
val keyboard = LocalInputModeManager.current.inputMode == InputMode.Keyboard
var shown by remember { mutableStateOf(rateOpen) }
LaunchedEffect(rateOpen) {
if (shown == rateOpen) return@LaunchedEffect
shown = rateOpen
withFrameNanos { }
if (keyboard) runCatching { (if (rateOpen) first else arrowFocus).requestFocus() }
}
if (rateOpen) {
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth().padding(start = 10.dp)) {
Text(rapidLabel.uppercase(), fontSize = 12.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 1.5.sp,
color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.weight(1f))
MenuGlyphButton("✕", stringResource(R.string.common_close), Modifier.testTag("$key-rate-close")) { rateOpen = false }
}
ValueSlider(rate.ordinal, 0..RapidFireRate.entries.lastIndex, 1, true, frequency, { rates[it] },
modifier = Modifier.focusRequester(first).testTag("$key-rate")) { if (it != rate.ordinal) onRate(RapidFireRate.entries[it]) }
} else actions.forEachIndexed { index, (value, text) ->
val pick = { onAction(value); host.open = null }
if (value != AirTriggerAction.RAPID) MenuItem(text, checked = value == action, focusRequester = if (index == 0) first else null, onClick = pick)
else Row(verticalAlignment = Alignment.CenterVertically) {
MenuItem(text, checked = value == action, modifier = Modifier.weight(1f), onClick = pick)
MenuGlyphButton("›", stringResource(R.string.air_trigger_rapid_settings),
Modifier.focusRequester(arrowFocus).testTag("$key-rate-open")) { rateOpen = true }
}
}
}
} }
}
@Composable
private fun MenuGlyphButton(glyph: String, description: String, modifier: Modifier = Modifier, onClick: () -> Unit) {
val pal = LocalPalette.current
val src = remember { MutableInteractionSource() }
val hot = src.collectIsFocusedAsState().value || src.collectIsHoveredAsState().value
val shape = RoundedCornerShape(8.dp)
Box(
contentAlignment = Alignment.Center,
modifier = modifier.size(40.dp).clip(shape)
.background(if (hot) Color.White.copy(alpha = 0.07f) else Color.Transparent)
.glideBorder(hot, shape, pal.signal)
.hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, role = Role.Button, onClick = onClick)
.controllerConfirm(onClick = onClick)
.semantics { contentDescription = description },
) {
Text(glyph, fontSize = 18.sp, fontWeight = FontWeight.SemiBold, color = MaterialTheme.colorScheme.onBackground)
}
}
/** The pages kept inside More, and the way into arranging which pages sit on the strip and which here. */
@Composable
private fun DrawerMorePage(host: MenuHost, pages: List<SessionDrawerPage>, a: DrawerActions, onOpen: (SessionDrawerPage) -> Unit, onEdit: () -> Unit, track: (String) -> Modifier) {