This commit is contained in:
loucass003 committed 2026-07-20 19:52:47 +02:00
1 parent 5c4c64e629
commit 9332ff8e02
25 files changed
+1116 -49

No files matched your search

@@ -16,6 +16,22 @@ import kotlinx.serialization.json.JsonNull
import kotlinx.serialization.json.JsonPrimitive
import kotlinx.serialization.json.jsonPrimitive
import solarxr_protocol.datatypes.BodyPart
import solarxr_protocol.rpc.KeybindId
object KeybindIdSerializer : KSerializer<KeybindId> {
override val descriptor = PrimitiveSerialDescriptor("KeybindId", PrimitiveKind.STRING)
override fun serialize(encoder: Encoder, value: KeybindId) {
(encoder as JsonEncoder).encodeJsonElement(JsonPrimitive(value.name))
}
override fun deserialize(decoder: Decoder): KeybindId {
val element = (decoder as JsonDecoder).decodeJsonElement()
// Falling back to a real keybind would silently turn an unknown entry into a duplicate
return KeybindId.entries.firstOrNull { it.name == element.jsonPrimitive.content }
?: KeybindId.NONE
}
}
object BodyPartSerializer : KSerializer<BodyPart?> {
@OptIn(ExperimentalSerializationApi::class)
@@ -16,6 +16,7 @@ import kotlinx.serialization.json.jsonPrimitive
import solarxr_protocol.datatypes.BodyPart
import solarxr_protocol.rpc.ArmsResetMode
import solarxr_protocol.rpc.FilteringType
import solarxr_protocol.rpc.KeybindId
private const val SETTINGS_CONFIG_VERSION = 2
@@ -91,6 +92,24 @@ data class ResetsConfig(
val lastMountingMethod: MountingMethods = MountingMethods.AUTOMATIC, // TODO
)
@Serializable
data class KeybindConfig(
@Serializable(with = KeybindIdSerializer::class)
val id: KeybindId,
/** Key combination, keys joined with '+' (e.g. "CTRL+ALT+SHIFT+Y") */
val binding: String,
/** Delay in seconds before the keybind triggers */
val delay: Float = 0f,
)
fun defaultKeybinds(): List<KeybindConfig> = listOf(
KeybindConfig(KeybindId.FULL_RESET, "CTRL+ALT+SHIFT+Y"),
KeybindConfig(KeybindId.YAW_RESET, "CTRL+ALT+SHIFT+U"),
KeybindConfig(KeybindId.MOUNTING_RESET, "CTRL+ALT+SHIFT+I"),
KeybindConfig(KeybindId.FEET_MOUNTING_RESET, "CTRL+ALT+SHIFT+P"),
KeybindConfig(KeybindId.PAUSE_TRACKING, "CTRL+ALT+SHIFT+O"),
)
// Used in SkeletonConfig
@Serializable
data class SkeletonTogglesConfig(
@@ -170,6 +189,7 @@ data class SettingsConfigState(
val skeletonConfig: SkeletonConfig = SkeletonConfig(),
val vrcOscConfig: VRCOSCConfig = VRCOSCConfig(),
val vmcConfig: VMCConfig = VMCConfig(),
val keybinds: List<KeybindConfig> = defaultKeybinds(),
)
private fun migrateSettingsConfig(json: JsonObject): JsonObject {
@@ -1,7 +1,10 @@
package dev.slimevr
import solarxr_protocol.rpc.KeybindSupport
data class FeatureFlags(
var steam: Boolean = false,
var skipCheckUdev: Boolean = false,
var udevRulesInstalled: Boolean? = null,
var keybindSupport: KeybindSupport = KeybindSupport.UNSUPPORTED,
)
@@ -24,6 +24,7 @@ object AppLogger {
val oscQuery = logger("OSCQuery")
val install = logger("Install")
val resets = logger("Resets")
val keybind = logger("Keybind")
val coroutines = noCoLogger("Coroutines")
init {
@@ -0,0 +1,58 @@
package dev.slimevr.solarxr
import dev.slimevr.config.KeybindConfig
import dev.slimevr.config.Settings
import dev.slimevr.config.SettingsActions
import dev.slimevr.config.defaultKeybinds
import solarxr_protocol.rpc.ChangeKeybindRequest
import solarxr_protocol.rpc.Keybind
import solarxr_protocol.rpc.KeybindId
import solarxr_protocol.rpc.KeybindRequest
import solarxr_protocol.rpc.KeybindResponse
private fun keybindNameId(id: KeybindId): String = id.name.lowercase().replace('_', '-')
private fun keybindConfigToProto(config: KeybindConfig): Keybind = Keybind(
keybindId = config.id,
keybindNameId = keybindNameId(config.id),
keybindValue = config.binding,
keybindDelay = config.delay,
)
class KeybindsBehaviour(
private val settings: Settings,
) : SolarXRBridgeBehaviour {
override fun observe(receiver: SolarXRBridge) {
receiver.rpcDispatcher.on<KeybindRequest> {
val keybinds = settings.context.state.value.data.keybinds
receiver.sendRpc(
KeybindResponse(
keybind = keybinds.map { keybindConfigToProto(it) },
defaultKeybinds = defaultKeybinds().map { keybindConfigToProto(it) },
support = receiver.appContext.featureFlags.keybindSupport,
),
)
}
receiver.rpcDispatcher.on<ChangeKeybindRequest> { req ->
val keybind = req.keybind ?: return@on
val id = keybind.keybindId?.takeUnless { it == KeybindId.NONE } ?: return@on
settings.context.dispatch(
SettingsActions.Update {
copy(
keybinds = keybinds.map {
if (it.id == id) {
it.copy(
binding = keybind.keybindValue ?: it.binding,
delay = keybind.keybindDelay ?: 0f,
)
} else {
it
}
},
)
},
)
}
}
}
@@ -86,6 +86,7 @@ class SolarXRBridge(
add(KnownTrackersBehaviour(appContext.config.settings))
add(BvhBehaviour(appContext.bvhManager))
add(InstalledInfoBehaviour())
add(KeybindsBehaviour(appContext.config.settings))
add(SessionCalibrationBehaviour(appContext.resetsManager))
}
@@ -1,5 +1,6 @@
package dev.slimevr.tracker
import dev.slimevr.AppLogger
import dev.slimevr.skeleton.SkeletonActions
import dev.slimevr.util.safeLaunch
import io.github.axisangles.ktmath.Quaternion
@@ -7,7 +8,6 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.distinctUntilChangedBy
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map
@@ -196,7 +196,7 @@ class TrackerTPSBehaviour : TrackerBehaviour {
receiver.context.dispatch(TrackerActions.Update { copy(tps = tps.toUShort()) })
mark = TimeSource.Monotonic.markNow()
} catch (e: Exception) {
dev.slimevr.AppLogger.coroutines.error(e, "Error in TrackerTPSBehaviour")
AppLogger.coroutines.error(e, "Error in TrackerTPSBehaviour")
}
}
}