feat(input): add absolute pointer and scroll
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"net"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -328,13 +329,52 @@ func TestApolloControlWireVectorAndTagFailure(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestApolloKeyboardInputWireVector(t *testing.T) {
|
||||
packet, err := encodeApolloInputEvent(InputEvent{Device: "keyboard", Code: 30, Pressed: true, Payload: []byte{2}})
|
||||
packets, err := encodeApolloInputEvent(InputEvent{Device: "keyboard", Code: 30, Pressed: true, Payload: []byte{2}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
const expected = "0000000a03000000001e00020000"
|
||||
if string(packet.payload) != string(mustDecodeHex(t, expected)) {
|
||||
t.Fatalf("keyboard packet = %x, want %s", packet.payload, expected)
|
||||
if len(packets) != 1 || string(packets[0].payload) != string(mustDecodeHex(t, expected)) {
|
||||
t.Fatalf("keyboard packets = %#v, want %s", packets, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApolloAbsoluteAndScrollInputWireVectors(t *testing.T) {
|
||||
// Independently implemented from the approved Apollo adc5c5a0 input.cpp
|
||||
// consumer and its moonlight-common-c c999436 Input.h/InputStream.c pin.
|
||||
absolute, err := encodeApolloInputEvent(InputEvent{Device: "mouse-absolute", Payload: []byte{0x04, 0xd2, 0x02, 0x37, 0x0a, 0x00, 0x05, 0xa0}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
const absoluteExpected = "0000000e0500000004d20237000009ff059f"
|
||||
if len(absolute) != 1 || absolute[0].channel != apolloChannelMouse || string(absolute[0].payload) != string(mustDecodeHex(t, absoluteExpected)) {
|
||||
t.Fatalf("absolute packets = %#v, want %s", absolute, absoluteExpected)
|
||||
}
|
||||
|
||||
scroll, err := encodeApolloInputEvent(InputEvent{Device: "mouse-scroll", Payload: []byte{0xff, 0x88, 0x00, 0x78}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
const verticalExpected = "0000000a0a000000ff88ff880000"
|
||||
const horizontalExpected = "00000006010000550078"
|
||||
if len(scroll) != 2 || scroll[0].channel != apolloChannelMouse || scroll[1].channel != apolloChannelMouse ||
|
||||
string(scroll[0].payload) != string(mustDecodeHex(t, verticalExpected)) || string(scroll[1].payload) != string(mustDecodeHex(t, horizontalExpected)) {
|
||||
t.Fatalf("scroll packets = %#v", scroll)
|
||||
}
|
||||
|
||||
zero, err := encodeApolloInputEvent(InputEvent{Device: "mouse-scroll", Payload: make([]byte, 4)})
|
||||
if err != nil || len(zero) != 0 {
|
||||
t.Fatalf("zero scroll packets = %#v, %v", zero, err)
|
||||
}
|
||||
|
||||
for _, payload := range [][]byte{
|
||||
{0, 0, 0, 0, 0, 1, 0, 2},
|
||||
{0, 0, 0, 0, 0x80, 0, 0, 2},
|
||||
{0, 0, 0, 0, 0, 2, 0x80, 0},
|
||||
} {
|
||||
if _, err := encodeApolloInputEvent(InputEvent{Device: "mouse-absolute", Payload: payload}); !errors.Is(err, ErrInputMalformed) {
|
||||
t.Fatalf("Apollo accepted unrepresentable absolute payload %x: %v", payload, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user