qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Brad Jorsch <anomie@users.sourceforge.net>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 4/5] Add a horizontal wheel to the USB mouse and tablet
Date: Tue,  4 May 2010 12:56:40 -0400	[thread overview]
Message-ID: <1272992201-26911-5-git-send-email-anomie@users.sourceforge.net> (raw)
In-Reply-To: <1272992201-26911-1-git-send-email-anomie@users.sourceforge.net>

Adjust the USB report descriptors to indicate that the mouse and tablet
have horizontal wheels, and then report the delta when polled.

Signed-off-by: Brad Jorsch <anomie@users.sourceforge.net>
---
 hw/usb-hid.c |   44 ++++++++++++++++++++++++++++++++++++--------
 1 files changed, 36 insertions(+), 8 deletions(-)

diff --git a/hw/usb-hid.c b/hw/usb-hid.c
index deb4731..15cc2a1 100644
--- a/hw/usb-hid.c
+++ b/hw/usb-hid.c
@@ -44,7 +44,7 @@
 #define USB_KEYBOARD  3
 
 typedef struct USBMouseState {
-    int dx, dy, dz, buttons_state;
+    int dx, dy, dz, dw, buttons_state;
     int x, y;
     int mouse_grabbed;
     QEMUPutMouseEntry *eh_entry;
@@ -137,14 +137,14 @@ static const uint8_t qemu_mouse_config_descriptor[] = {
         0x00,        /*  u8 country_code */
         0x01,        /*  u8 num_descriptors */
         0x22,        /*  u8 type; Report */
-        52, 0,       /*  u16 len */
+        67, 0,       /*  u16 len */
 
 	/* one endpoint (status change endpoint) */
 	0x07,       /*  u8  ep_bLength; */
 	0x05,       /*  u8  ep_bDescriptorType; Endpoint */
 	0x81,       /*  u8  ep_bEndpointAddress; IN Endpoint 1 */
  	0x03,       /*  u8  ep_bmAttributes; Interrupt */
- 	0x04, 0x00, /*  u16 ep_wMaxPacketSize; */
+ 	0x05, 0x00, /*  u16 ep_wMaxPacketSize; */
 	0x0a,       /*  u8  ep_bInterval; (255ms -- usb 2.0 spec) */
 };
 
@@ -192,14 +192,14 @@ static const uint8_t qemu_tablet_config_descriptor[] = {
         0x00,        /*  u8 country_code */
         0x01,        /*  u8 num_descriptors */
         0x22,        /*  u8 type; Report */
-        74, 0,       /*  u16 len */
+        93, 0,       /*  u16 len */
 
 	/* one endpoint (status change endpoint) */
 	0x07,       /*  u8  ep_bLength; */
 	0x05,       /*  u8  ep_bDescriptorType; Endpoint */
 	0x81,       /*  u8  ep_bEndpointAddress; IN Endpoint 1 */
  	0x03,       /*  u8  ep_bmAttributes; Interrupt */
- 	0x08, 0x00, /*  u16 ep_wMaxPacketSize; */
+ 	0x09, 0x00, /*  u16 ep_wMaxPacketSize; */
 	0x0a,       /*  u8  ep_bInterval; (255ms -- usb 2.0 spec) */
 };
 
@@ -284,6 +284,13 @@ static const uint8_t qemu_mouse_hid_report_descriptor[] = {
     0x75, 0x08,		/*     Report Size (8) */
     0x95, 0x03,		/*     Report Count (3) */
     0x81, 0x06,		/*     Input (Data, Variable, Relative) */
+    0x05, 0x0c,		/*     Usage Page (Consumer Devices) */
+    0x0a, 0x38, 0x02,	/*     Usage (AC Pan) */
+    0x15, 0x81,		/*     Logical Minimum (-0x7f) */
+    0x25, 0x7f,		/*     Logical Maximum (0x7f) */
+    0x75, 0x08,		/*     Report Size (8) */
+    0x95, 0x01,		/*     Report Count (1) */
+    0x81, 0x06,		/*     Input (Data, Variable, Relative) */
     0xc0,		/*   End Collection */
     0xc0,		/* End Collection */
 };
@@ -324,6 +331,15 @@ static const uint8_t qemu_tablet_hid_report_descriptor[] = {
     0x75, 0x08,		/*     Report Size (8) */
     0x95, 0x01,		/*     Report Count (1) */
     0x81, 0x06,		/*     Input (Data, Variable, Relative) */
+    0x05, 0x0c,		/*     Usage Page (Consumer Devices) */
+    0x0a, 0x38, 0x02,	/*     Usage (AC Pan) */
+    0x15, 0x81,		/*     Logical Minimum (-0x7f) */
+    0x25, 0x7f,		/*     Logical Maximum (0x7f) */
+    0x35, 0x00,		/*     Physical Minimum (same as logical) */
+    0x45, 0x00,		/*     Physical Maximum (same as logical) */
+    0x75, 0x08,		/*     Report Size (8) */
+    0x95, 0x01,		/*     Report Count (1) */
+    0x81, 0x06,		/*     Input (Data, Variable, Relative) */
     0xc0,		/*   End Collection */
     0xc0,		/* End Collection */
 };
@@ -423,6 +439,7 @@ static void usb_mouse_event(void *opaque,
     s->dx += dx1;
     s->dy += dy1;
     s->dz += dz1;
+    s->dw += dw1;
     s->buttons_state = buttons_state;
 
     usb_hid_changed(hs);
@@ -437,6 +454,7 @@ static void usb_tablet_event(void *opaque,
     s->x = x;
     s->y = y;
     s->dz += dz;
+    s->dw += dw;
     s->buttons_state = buttons_state;
 
     usb_hid_changed(hs);
@@ -508,7 +526,7 @@ static inline int int_clamp(int val, int vmin, int vmax)
 
 static int usb_mouse_poll(USBHIDState *hs, uint8_t *buf, int len)
 {
-    int dx, dy, dz, b, l;
+    int dx, dy, dz, dw, b, l;
     USBMouseState *s = &hs->ptr;
 
     if (!s->mouse_grabbed) {
@@ -519,10 +537,12 @@ static int usb_mouse_poll(USBHIDState *hs, uint8_t *buf, int len)
     dx = int_clamp(s->dx, -127, 127);
     dy = int_clamp(s->dy, -127, 127);
     dz = int_clamp(s->dz, -127, 127);
+    dw = int_clamp(s->dw, -127, 127);
 
     s->dx -= dx;
     s->dy -= dy;
     s->dz -= dz;
+    s->dw -= dw;
 
     /* Appears we have to invert the wheel direction */
     dz = 0 - dz;
@@ -544,12 +564,15 @@ static int usb_mouse_poll(USBHIDState *hs, uint8_t *buf, int len)
         buf[l ++] = dy;
     if (len > l)
         buf[l ++] = dz;
+    if (len > l)
+        buf[l ++] = dw;
+
     return l;
 }
 
 static int usb_tablet_poll(USBHIDState *hs, uint8_t *buf, int len)
 {
-    int dz, b, l;
+    int dz, dw, b, l;
     USBMouseState *s = &hs->ptr;
 
     if (!s->mouse_grabbed) {
@@ -560,6 +583,9 @@ static int usb_tablet_poll(USBHIDState *hs, uint8_t *buf, int len)
     dz = int_clamp(s->dz, -127, 127);
     s->dz -= dz;
 
+    dw = int_clamp(s->dw, -127, 127);
+    s->dw -= dw;
+
     /* Appears we have to invert the wheel direction */
     dz = 0 - dz;
     b = 0;
@@ -576,7 +602,8 @@ static int usb_tablet_poll(USBHIDState *hs, uint8_t *buf, int len)
     buf[3] = s->y & 0xff;
     buf[4] = s->y >> 8;
     buf[5] = dz;
-    l = 6;
+    buf[6] = dw;
+    l = 7;
 
     return l;
 }
@@ -624,6 +651,7 @@ static void usb_mouse_handle_reset(USBDevice *dev)
     s->ptr.dx = 0;
     s->ptr.dy = 0;
     s->ptr.dz = 0;
+    s->ptr.dw = 0;
     s->ptr.x = 0;
     s->ptr.y = 0;
     s->ptr.buttons_state = 0;
-- 
1.7.1

  parent reply	other threads:[~2010-05-04 16:57 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-04 16:56 [Qemu-devel] [RFC] [PATCH 0/5] Add horizontal wheel support to mice, where possible Brad Jorsch
2010-05-04 16:56 ` [Qemu-devel] [PATCH 1/5] Add function parameters for hwheel Brad Jorsch
2010-05-04 16:56 ` [Qemu-devel] [PATCH 2/5] Add hwheel to monitor mouse_move Brad Jorsch
2010-05-04 16:56 ` [Qemu-devel] [PATCH 3/5] Pass hwheel events from the front-ends Brad Jorsch
2010-05-04 16:56 ` Brad Jorsch [this message]
2010-05-04 16:56 ` [Qemu-devel] [PATCH 5/5] Add a horizontal wheel to the exps/2 mouse Brad Jorsch
2010-06-02 13:30 ` [Qemu-devel] [RFC] [PATCH 0/5] Add horizontal wheel support to mice, where possible Anthony Liguori
2010-06-02 16:14   ` Brad Jorsch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1272992201-26911-5-git-send-email-anomie@users.sourceforge.net \
    --to=anomie@users.sourceforge.net \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).