diff -r 8937c657c23f hw/usb-hid.c --- a/hw/usb-hid.c Sun Mar 26 01:31:22 2006 +0000 +++ b/hw/usb-hid.c Sun Apr 9 15:57:13 2006 -0500 @@ -33,6 +33,7 @@ typedef struct USBMouseState { USBDevice dev; int dx, dy, dz, buttons_state; + int X, Y; } USBMouseState; /* mostly the same values as the Bochs USB Mouse device */ @@ -92,14 +93,6 @@ 0x01, /* u8 if_bInterfaceSubClass; */ 0x02, /* u8 if_bInterfaceProtocol; [usb1.1 or single tt] */ 0x05, /* u8 if_iInterface; */ - - /* 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 */ - 0x03, 0x00, /* u16 ep_wMaxPacketSize; */ - 0x0a, /* u8 ep_bInterval; (255ms -- usb 2.0 spec) */ /* HID descriptor */ 0x09, /* u8 bLength; */ @@ -109,8 +102,17 @@ 0x01, /* u8 num_descriptors */ 0x22, /* u8 type; Report */ 50, 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 */ + 0x03, 0x00, /* u16 ep_wMaxPacketSize; */ + 0x0a, /* u8 ep_bInterval; (255ms -- usb 2.0 spec) */ }; +#if 0 static const uint8_t qemu_mouse_hid_report_descriptor[] = { 0x05, 0x01, 0x09, 0x02, 0xA1, 0x01, 0x09, 0x01, 0xA1, 0x00, 0x05, 0x09, 0x19, 0x01, 0x29, 0x03, @@ -120,6 +122,41 @@ 0x25, 0x7F, 0x75, 0x08, 0x95, 0x02, 0x81, 0x06, 0xC0, 0xC0, }; +#else +static const uint8_t qemu_mouse_hid_report_descriptor[] = { + 0x05, 0x01, /* Usage Page Generic Desktop */ + 0x09, 0x01, /* Usage Mouse */ + 0xA1, 0x01, /* Collection Application */ + 0x09, 0x01, /* Usage Pointer */ + 0xA1, 0x00, /* Collection Physical */ + 0x05, 0x09, /* Usage Page Button */ + 0x19, 0x01, /* Usage Minimum Button 1 */ + 0x29, 0x03, /* Usage Maximum Button 3 */ + 0x15, 0x00, /* Logical Minimum 0 */ + 0x25, 0x01, /* Logical Maximum 1 */ + 0x95, 0x03, /* Report Count 3 */ + 0x75, 0x01, /* Report Size 1 */ + 0x81, 0x02, /* Input (Data, Var, Abs) */ + 0x95, 0x01, /* Report Count 1 */ + 0x75, 0x05, /* Report Size 5 */ + 0x81, 0x01, /* Input (Cnst, Var, Abs) */ + 0x05, 0x01, /* Usage Page Generic Desktop */ + 0x09, 0x30, /* Usage X */ + 0x09, 0x31, /* Usage Y */ + 0x15, 0x00, /* Logical Minimum 0 */ + 0x27, 0xFF, 0xFF, 0x00, 0x00, /* Logical Maximum 0xffff */ + 0x75, 0x10, /* Report Size 32 */ + 0x95, 0x02, /* Report Count 2 */ + 0x81, 0x02, /* Input (Data, Var, Abs) */ +// 0x09, 0x32, /* Usage Z */ +// 0x15, 0x81, /* Logical Minimum -127 */ +// 0x25, 0x7F, /* Logical Maximum 127 */ +// 0x75, 0x08, /* Report Size 8 */ +// 0x95, 0x01, /* Report Count 1 */ + 0xC0, /* End Collection */ + 0xC0, /* End Collection */ +}; +#endif static void usb_mouse_event(void *opaque, int dx1, int dy1, int dz1, int buttons_state) @@ -129,6 +166,8 @@ s->dx += dx1; s->dy += dy1; s->dz += dz1; + s->X = dx1; + s->Y = dy1; s->buttons_state = buttons_state; } @@ -142,6 +181,7 @@ return val; } +#if 0 static int usb_mouse_poll(USBMouseState *s, uint8_t *buf, int len) { int dx, dy, dz, b, l; @@ -172,6 +212,37 @@ } return l; } +#else + +static int usb_mouse_poll(USBMouseState *s, uint8_t *buf, int len) +{ + int dx, dy, dz, b, l; + + dx = int_clamp(s->dx, -128, 127); + dy = int_clamp(s->dy, -128, 127); + dz = int_clamp(s->dz, -128, 127); + + s->dx -= dx; + s->dy -= dy; + s->dz -= dz; + b = 0; + if (s->buttons_state & MOUSE_EVENT_LBUTTON) + b |= 0x01; + if (s->buttons_state & MOUSE_EVENT_RBUTTON) + b |= 0x02; + if (s->buttons_state & MOUSE_EVENT_MBUTTON) + b |= 0x04; + + buf[0] = b; + buf[1] = s->X & 0xff; + buf[2] = s->X >> 8; + buf[3] = s->Y & 0xff; + buf[4] = s->Y >> 8; + l = 5; + + return l; +} +#endif static void usb_mouse_handle_reset(USBDevice *dev) { @@ -180,6 +251,8 @@ s->dx = 0; s->dy = 0; s->dz = 0; + s->X = 0; + s->Y = 0; s->buttons_state = 0; } @@ -341,7 +414,8 @@ s->dev.handle_control = usb_mouse_handle_control; s->dev.handle_data = usb_mouse_handle_data; - qemu_add_mouse_event_handler(usb_mouse_event, s); + qemu_add_mouse_event_handler(NULL, NULL); + qemu_add_mouse_abs_event_handler(usb_mouse_event, s); return (USBDevice *)s; } diff -r 8937c657c23f sdl.c --- a/sdl.c Sun Mar 26 01:31:22 2006 +0000 +++ b/sdl.c Sun Apr 9 15:57:13 2006 -0500 @@ -301,6 +301,9 @@ if (state & SDL_BUTTON(SDL_BUTTON_MIDDLE)) buttons |= MOUSE_EVENT_MBUTTON; kbd_mouse_event(dx, dy, dz, buttons); + + SDL_GetMouseState(&dx, &dy); + kbd_mouse_abs_event(dx, dy, dz, buttons); } static void toggle_full_screen(DisplayState *ds) diff -r 8937c657c23f vl.c --- a/vl.c Sun Mar 26 01:31:22 2006 +0000 +++ b/vl.c Sun Apr 9 15:57:13 2006 -0500 @@ -475,6 +475,8 @@ static void *qemu_put_kbd_event_opaque; static QEMUPutMouseEvent *qemu_put_mouse_event; static void *qemu_put_mouse_event_opaque; +static QEMUPutMouseAbsEvent *qemu_put_mouse_abs_event; +static void *qemu_put_mouse_abs_event_opaque; void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque) { @@ -486,6 +488,12 @@ { qemu_put_mouse_event_opaque = opaque; qemu_put_mouse_event = func; +} + +void qemu_add_mouse_abs_event_handler(QEMUPutMouseAbsEvent *func, void *opaque) +{ + qemu_put_mouse_abs_event_opaque = opaque; + qemu_put_mouse_abs_event = func; } void kbd_put_keycode(int keycode) @@ -500,6 +508,14 @@ if (qemu_put_mouse_event) { qemu_put_mouse_event(qemu_put_mouse_event_opaque, dx, dy, dz, buttons_state); + } +} + +void kbd_mouse_abs_event(int x, int y, int dz, int buttons_state) +{ + if (qemu_put_mouse_abs_event) { + qemu_put_mouse_abs_event(qemu_put_mouse_abs_event_opaque, + x, y, dz, buttons_state); } } @@ -1308,7 +1324,7 @@ /* for STDIO, we handle the case where several clients use it (nographic mode) */ -#define TERM_ESCAPE 0x01 /* ctrl-a is used for escape */ +#define TERM_ESCAPE 0x1d /* ctrl-a is used for escape */ #define TERM_FIFO_MAX_SIZE 1 diff -r 8937c657c23f vl.h --- a/vl.h Sun Mar 26 01:31:22 2006 +0000 +++ b/vl.h Sun Apr 9 15:57:13 2006 -0500 @@ -156,12 +156,15 @@ typedef void QEMUPutKBDEvent(void *opaque, int keycode); typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz, int buttons_state); +typedef void QEMUPutMouseAbsEvent(void *opaque, int x, int y, int dz, int buttons_state); void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque); void qemu_add_mouse_event_handler(QEMUPutMouseEvent *func, void *opaque); +void qemu_add_mouse_abs_event_handler(QEMUPutMouseAbsEvent *func, void *opaque); void kbd_put_keycode(int keycode); void kbd_mouse_event(int dx, int dy, int dz, int buttons_state); +void kbd_mouse_abs_event(int x, int y, int dz, int buttons_state); /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx constants) */