[RFC PATCH 1/5] input/hid: add horizontal pan to pointer event path

Soumyajyotii Ssarkar posted 5 patches 1 week, 4 days ago
[RFC PATCH 1/5] input/hid: add horizontal pan to pointer event path
Posted by Soumyajyotii Ssarkar 1 week, 4 days ago
Add support for horizontal wheel scrolling (pan) in the HID mouse
implementation. Extend the HIDPointerEvent structure with "pan" field
to track horizontal scroll deltas, similar to the existing 'dz' field
for vertical scrolling.

Map INPUT_BUTTON_WHEEL_LEFT and INPUT_BUTTON_WHEEL_RIGHT to pan delta
changes in the event handler. Integrate pan field handling into event
compression logic and queue management to ensure consistent behavior with
vertical wheel events.

This changes enables subsequent patches to implement
multiplier based scaling and protocol aware reporting for horizontal
scrolling.

Signed-off-by: Soumyajyotii Ssarkar <soumyajyotisarkar23@gmail.com>
---
 hw/input/hid.c         | 13 ++++++++++++-
 include/hw/input/hid.h |  1 +
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/hw/input/hid.c b/hw/input/hid.c
index de24cd0ef0..457dbb0096 100644
--- a/hw/input/hid.c
+++ b/hw/input/hid.c
@@ -152,6 +152,10 @@ static void hid_pointer_event(DeviceState *dev, QemuConsole *src,
                 e->dz--;
             } else if (btn->button == INPUT_BUTTON_WHEEL_DOWN) {
                 e->dz++;
+            } else if (btn->button == INPUT_BUTTON_WHEEL_LEFT) {
+                e->pan--;
+            } else if (btn->button == INPUT_BUTTON_WHEEL_RIGHT) {
+                e->pan++;
             }
         } else {
             e->buttons_state &= ~bmap[btn->button];
@@ -208,6 +212,8 @@ static void hid_pointer_sync(DeviceState *dev)
         }
         prev->dz += curr->dz;
         curr->dz = 0;
+        prev->pan += curr->pan;
+        curr->pan = 0;
     } else {
         /* prepare next (clear rel, copy abs + btns) */
         if (hs->kind == HID_MOUSE) {
@@ -218,6 +224,7 @@ static void hid_pointer_sync(DeviceState *dev)
             next->ydy = curr->ydy;
         }
         next->dz = 0;
+        next->pan = 0;
         next->buttons_state = curr->buttons_state;
         /* make current guest visible, notify guest */
         hs->n++;
@@ -357,7 +364,7 @@ void hid_pointer_activate(HIDState *hs)

 int hid_pointer_poll(HIDState *hs, uint8_t *buf, int len)
 {
-    int dx, dy, dz, l;
+    int dx, dy, dz, pan, l;
     int index;
     HIDPointerEvent *e;

@@ -381,9 +388,13 @@ int hid_pointer_poll(HIDState *hs, uint8_t *buf, int len)
     }
     dz = int_clamp(e->dz, -127, 127);
     e->dz -= dz;
+    pan = int_clamp(e->pan, -127, 127);
+    e->pan -= pan;
+

     if (hs->n &&
         !e->dz &&
+        !e->pan &&
         (hs->kind == HID_TABLET || (!e->xdx && !e->ydy))) {
         /* that deals with this event */
         QUEUE_INCR(hs->head);
diff --git a/include/hw/input/hid.h b/include/hw/input/hid.h
index 6a9d7bf466..1bb1778ee7 100644
--- a/include/hw/input/hid.h
+++ b/include/hw/input/hid.h
@@ -10,6 +10,7 @@
 typedef struct HIDPointerEvent {
     int32_t xdx, ydy; /* relative iff it's a mouse, otherwise absolute */
     int32_t dz, buttons_state;
+    int32_t pan;
 } HIDPointerEvent;

 #define QUEUE_LENGTH    16 /* should be enough for a triple-click */
--
2.53.0