static int usb_mouse_poll(USBMouseState *s, uint8_t *buf, int len) { int dx, dy, dz, b, l; if (!s->mouse_grabbed) { qemu_add_mouse_event_handler(usb_mouse_event, s, 0); s->mouse_grabbed = 1; } 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] = dx; buf[2] = dy; l = 3; if (len >= 4) { buf[3] = dz; l = 4; } return l; }
static int usb_tablet_poll(USBHIDState *hs, uint8_t *buf, int len) { int dz, b, l; USBMouseState *s = &hs->ptr; if (!s->mouse_grabbed) { s->eh_entry = qemu_add_mouse_event_handler(usb_tablet_event, hs, 1, "QEMU USB Tablet"); s->mouse_grabbed = 1; } dz = int_clamp(s->dz, -128, 127); s->dz -= dz; /* Appears we have to invert the wheel direction */ dz = 0 - 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; buf[5] = dz; l = 6; return l; }
int hid_pointer_poll(HIDState *hs, uint8_t *buf, int len) { int dx, dy, dz, b, l; int index; HIDPointerEvent *e; hs->idle_pending = false; hid_pointer_activate(hs); /* When the buffer is empty, return the last event. Relative movements will all be zero. */ index = (hs->n ? hs->head : hs->head - 1); e = &hs->ptr.queue[index & QUEUE_MASK]; if (hs->kind == HID_MOUSE) { dx = int_clamp(e->xdx, -127, 127); dy = int_clamp(e->ydy, -127, 127); e->xdx -= dx; e->ydy -= dy; } else { dx = e->xdx; dy = e->ydy; } dz = int_clamp(e->dz, -127, 127); e->dz -= dz; b = 0; if (e->buttons_state & MOUSE_EVENT_LBUTTON) { b |= 0x01; } if (e->buttons_state & MOUSE_EVENT_RBUTTON) { b |= 0x02; } if (e->buttons_state & MOUSE_EVENT_MBUTTON) { b |= 0x04; } if (hs->n && !e->dz && (hs->kind == HID_TABLET || (!e->xdx && !e->ydy))) { /* that deals with this event */ QUEUE_INCR(hs->head); hs->n--; } /* Appears we have to invert the wheel direction */ dz = 0 - dz; l = 0; switch (hs->kind) { case HID_MOUSE: if (len > l) { buf[l++] = b; } if (len > l) { buf[l++] = dx; } if (len > l) { buf[l++] = dy; } if (len > l) { buf[l++] = dz; } break; case HID_TABLET: if (len > l) { buf[l++] = b; } if (len > l) { buf[l++] = dx & 0xff; } if (len > l) { buf[l++] = dx >> 8; } if (len > l) { buf[l++] = dy & 0xff; } if (len > l) { buf[l++] = dy >> 8; }
static int usb_pointer_poll(USBHIDState *hs, uint8_t *buf, int len) { int dx, dy, dz, b, l; USBPointerState *s = &hs->ptr; USBPointerEvent *e; if (usb_suppress_report(hs, s->head == s->tail)) return USB_RET_NAK; if (!s->mouse_grabbed) { s->eh_entry = qemu_add_mouse_event_handler(usb_pointer_event, hs, !s->xyrel, "QEMU USB Pointer"); s->mouse_grabbed = 1; } if (s->head == s->tail) /* use the last report */ s->head = (s->head - 1) & QUEUEINDEXMASK; e = &s->queue[s->head]; dz = int_clamp(e->dz, -127, 127); if (s->xyrel) { dx = int_clamp(e->xdx, -127, 127); dy = int_clamp(e->ydy, -127, 127); e->xdx -= dx; e->ydy -= dy; } else { dx = e->xdx; dy = e->ydy; } /* Appears we have to invert the wheel direction */ dz = 0 - dz; if (!(e->dz || (s->xyrel && (e->xdx || e->ydy)))) { /* that deals with this event */ QUEUE_INCR(s->head); } b = 0; if (e->buttons_state & MOUSE_EVENT_LBUTTON) b |= 0x01; if (e->buttons_state & MOUSE_EVENT_RBUTTON) b |= 0x02; if (e->buttons_state & MOUSE_EVENT_MBUTTON) b |= 0x04; switch (hs->kind) { case USB_MOUSE: l = 0; if (len > l) buf[l ++] = b; if (len > l) buf[l ++] = dx; if (len > l) buf[l ++] = dy; if (len > l) buf[l ++] = dz; break; case USB_TABLET: /* Appears we have to invert the wheel direction */ dz = 0 - dz; buf[0] = b; buf[1] = dx & 0xff; buf[2] = dx >> 8; buf[3] = dy & 0xff; buf[4] = dy >> 8; buf[5] = dz; l = 6; break; default: abort(); } return l; }