Implement protocol-aware mouse report output to support both boot
protocol (protocol 0) and report protocol (protocol 1).
Boot protocol: 4-byte reports (button, dx, dy, dz)
Report protocol: 6-byte reports with report ID 0x01 + pan byte
Both modes now support the 'pan' field for horizontal scrolling. The
distinction ensures correct behavior across different guest operating
systems and their HID implementations.
Signed-off-by: Soumyajyotii Ssarkar <soumyajyotisarkar23@gmail.com>
---
hw/input/hid.c | 44 +++++++++++++++++++++++++++++++++-----------
1 file changed, 33 insertions(+), 11 deletions(-)
diff --git a/hw/input/hid.c b/hw/input/hid.c
index 457dbb0096..d0b7af7c13 100644
--- a/hw/input/hid.c
+++ b/hw/input/hid.c
@@ -403,20 +403,42 @@ int hid_pointer_poll(HIDState *hs, uint8_t *buf, int len)
/* Appears we have to invert the wheel direction */
dz = 0 - dz;
+ pan = 0 - pan;
l = 0;
switch (hs->kind) {
case HID_MOUSE:
- if (len > l) {
- buf[l++] = e->buttons_state;
- }
- if (len > l) {
- buf[l++] = dx;
- }
- if (len > l) {
- buf[l++] = dy;
- }
- if (len > l) {
- buf[l++] = dz;
+ if (hs->protocol == 0) {
+ if (len > l) {
+ buf[l++] = e->buttons_state;
+ }
+ if (len > l) {
+ buf[l++] = dx;
+ }
+ if (len > l) {
+ buf[l++] = dy;
+ }
+ if (len > l) {
+ buf[l++] = dz;
+ }
+ } else {
+ if (len > l) {
+ buf[l++] = 0x01;
+ }
+ if (len > l) {
+ buf[l++] = e->buttons_state;
+ }
+ if (len > l) {
+ buf[l++] = dx;
+ }
+ if (len > l) {
+ buf[l++] = dy;
+ }
+ if (len > l) {
+ buf[l++] = dz;
+ }
+ if (len > l) {
+ buf[l++] = pan;
+ }
}
break;
--
2.53.0