feat(protocol): negotiate display and native input
This commit is contained in:
@@ -27,8 +27,9 @@ func evaluate(_ kind: String, _ input: String) -> String {
|
||||
guard let sequence = Int(values["sequence"] ?? ""), sequence > 0, values["correlation_id"] != nil else { return "invalid:required" }
|
||||
return "valid"
|
||||
case "tunnel":
|
||||
if ["1", "0", "-1"].contains(values["offered"] ?? "") && values["feature"] == "control.v1" { return "valid" }
|
||||
return values["feature"] == "control.v1" ? "invalid:unsupported_version" : "invalid:unsupported_feature"
|
||||
let registered = ["control.v1", "display.request.v1", "input.absolute.v1", "input.scroll.v1"].contains(values["feature"] ?? "")
|
||||
if ["1", "0", "-1"].contains(values["offered"] ?? "") && registered { return "valid" }
|
||||
return registered ? "invalid:unsupported_version" : "invalid:unsupported_feature"
|
||||
case "datagram": return classifyDatagram(values["hex"] ?? "")
|
||||
case "gateway_input": return classifyGatewayInput(values["hex"] ?? "")
|
||||
case "gateway_feedback": return classifyGatewayFeedback(values["hex"] ?? "")
|
||||
@@ -82,6 +83,14 @@ func classifyGatewayInput(_ encoded: String) -> String {
|
||||
guard body[0] <= 15 else { return "invalid:field" }
|
||||
guard body[1] != 0 || body[2] != 0 || body.dropFirst(3).allSatisfy({ $0 == 0 }) else { return "invalid:field" }
|
||||
return "valid"
|
||||
case 6:
|
||||
guard body.count == 8 else { return "invalid:length" }
|
||||
let x = Int(body[0]) * 256 + Int(body[1])
|
||||
let y = Int(body[2]) * 256 + Int(body[3])
|
||||
let width = Int(body[4]) * 256 + Int(body[5])
|
||||
let height = Int(body[6]) * 256 + Int(body[7])
|
||||
return width > 0 && height > 0 && x < width && y < height ? "valid" : "invalid:field"
|
||||
case 7: return body.count == 4 ? "valid" : "invalid:length"
|
||||
default: return "invalid:kind"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user