@@ -91,6 +91,23 @@ object PcProtocol {
9191 )
9292 }
9393
94+ fun pointerSpeedSet (
95+ id : String ,
96+ deviceId : String ,
97+ token : String ,
98+ timestamp : Long ,
99+ scalePercent : Double
100+ ): String {
101+ return authenticatedCommand(
102+ id = id,
103+ deviceId = deviceId,
104+ token = token,
105+ timestamp = timestamp,
106+ type = " pointer.speed.set" ,
107+ payload = JSONObject ().put(" scalePercent" , jsonNumber(scalePercent))
108+ )
109+ }
110+
94111 fun authenticatedCommand (
95112 id : String ,
96113 deviceId : String ,
@@ -114,6 +131,10 @@ object PcProtocol {
114131 return message.toString()
115132 }
116133
134+ private fun jsonNumber (value : Double ): Number {
135+ return if (value.isFinite() && value % 1.0 == 0.0 ) value.toInt() else value
136+ }
137+
117138 fun mouseMove (
118139 id : String ,
119140 deviceId : String ,
@@ -568,7 +589,8 @@ object PcProtocol {
568589 noAckMouseMove = capabilitiesJson?.optBoolean(" noAckMouseMove" , false ) ? : false ,
569590 noAckCommands = noAckCommands,
570591 supportedCommands = supportedCommands,
571- mouseRepeat = parseMouseRepeatCapabilities(capabilitiesJson) ? : return PcProtocolResponse .Invalid
592+ mouseRepeat = parseMouseRepeatCapabilities(capabilitiesJson) ? : return PcProtocolResponse .Invalid ,
593+ pointerSpeed = parsePointerSpeedCapabilities(capabilitiesJson) ? : return PcProtocolResponse .Invalid
572594 )
573595 val bounds = PcPointerBounds (
574596 x = boundsJson.optInt(" x" ),
@@ -626,6 +648,52 @@ object PcProtocol {
626648 )
627649 }
628650
651+ private fun parsePointerSpeedCapabilities (capabilitiesJson : JSONObject ? ): PcPointerSpeedCapabilities ? {
652+ val speedJson = capabilitiesJson?.opt(" pointerSpeed" ) ? : return PcPointerSpeedCapabilities ()
653+ if (speedJson !is JSONObject ) return null
654+ if (speedJson.has(" supported" ) && speedJson.opt(" supported" ) !is Boolean ) return null
655+ if (speedJson.has(" setSupported" ) && speedJson.opt(" setSupported" ) !is Boolean ) return null
656+
657+ val scalePercent = speedJson.optDouble(" scalePercent" , 100.0 )
658+ val minScalePercent = speedJson.optDouble(" minScalePercent" , 5.0 )
659+ val maxScalePercent = speedJson.optDouble(" maxScalePercent" , 225.0 )
660+ val stepPercent = speedJson.optDouble(" stepPercent" , 5.0 )
661+ val baseMoveDeltaValue = speedJson.opt(" baseMoveDelta" )
662+ val effectiveMoveDeltaValue = speedJson.opt(" effectiveMoveDelta" )
663+ if (baseMoveDeltaValue != null && baseMoveDeltaValue !is Number ) return null
664+ if (effectiveMoveDeltaValue != null && effectiveMoveDeltaValue !is Number ) return null
665+ val baseMoveDelta = baseMoveDeltaValue?.toInt() ? : 128
666+ val effectiveMoveDelta = effectiveMoveDeltaValue?.toInt() ? : baseMoveDelta
667+
668+ if (
669+ ! scalePercent.isFinite() ||
670+ ! minScalePercent.isFinite() ||
671+ ! maxScalePercent.isFinite() ||
672+ ! stepPercent.isFinite() ||
673+ scalePercent <= 0.0 ||
674+ minScalePercent <= 0.0 ||
675+ maxScalePercent < minScalePercent ||
676+ scalePercent < minScalePercent ||
677+ scalePercent > maxScalePercent ||
678+ stepPercent <= 0.0 ||
679+ baseMoveDelta <= 0 ||
680+ effectiveMoveDelta <= 0
681+ ) {
682+ return null
683+ }
684+
685+ return PcPointerSpeedCapabilities (
686+ supported = speedJson.optBoolean(" supported" , false ),
687+ setSupported = speedJson.optBoolean(" setSupported" , false ),
688+ scalePercent = scalePercent,
689+ minScalePercent = minScalePercent,
690+ maxScalePercent = maxScalePercent,
691+ stepPercent = stepPercent,
692+ baseMoveDelta = baseMoveDelta,
693+ effectiveMoveDelta = effectiveMoveDelta
694+ )
695+ }
696+
629697 private fun parseNoAckCommands (capabilitiesJson : JSONObject ? ): Set <String >? {
630698 if (capabilitiesJson == null || ! capabilitiesJson.has(" noAckCommands" )) return emptySet()
631699 val commandsJson = capabilitiesJson.opt(" noAckCommands" )
@@ -681,6 +749,7 @@ object PcProtocol {
681749 " connection.ping" ,
682750 " connection.disconnecting" ,
683751 " pointer.profile" ,
752+ " pointer.speed.set" ,
684753 " mouse.repeat.start" ,
685754 " mouse.repeat.stop" ,
686755 " keyboard.textStream.open" ,
0 commit comments