2
0

hid.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #ifndef QEMU_HID_H
  2. #define QEMU_HID_H
  3. #define HID_MOUSE 1
  4. #define HID_TABLET 2
  5. #define HID_KEYBOARD 3
  6. typedef struct HIDPointerEvent {
  7. int32_t xdx, ydy; /* relative iff it's a mouse, otherwise absolute */
  8. int32_t dz, buttons_state;
  9. } HIDPointerEvent;
  10. #define QUEUE_LENGTH 16 /* should be enough for a triple-click */
  11. #define QUEUE_MASK (QUEUE_LENGTH-1u)
  12. #define QUEUE_INCR(v) ((v)++, (v) &= QUEUE_MASK)
  13. typedef struct HIDState HIDState;
  14. typedef void (*HIDEventFunc)(HIDState *s);
  15. typedef struct HIDMouseState {
  16. HIDPointerEvent queue[QUEUE_LENGTH];
  17. int mouse_grabbed;
  18. QEMUPutMouseEntry *eh_entry;
  19. } HIDMouseState;
  20. typedef struct HIDKeyboardState {
  21. uint32_t keycodes[QUEUE_LENGTH];
  22. uint16_t modifiers;
  23. uint8_t leds;
  24. uint8_t key[16];
  25. int32_t keys;
  26. } HIDKeyboardState;
  27. struct HIDState {
  28. union {
  29. HIDMouseState ptr;
  30. HIDKeyboardState kbd;
  31. };
  32. uint32_t head; /* index into circular queue */
  33. uint32_t n;
  34. int kind;
  35. int32_t protocol;
  36. uint8_t idle;
  37. int64_t next_idle_clock;
  38. HIDEventFunc event;
  39. };
  40. void hid_init(HIDState *hs, int kind, HIDEventFunc event);
  41. void hid_reset(HIDState *hs);
  42. void hid_free(HIDState *hs);
  43. bool hid_has_events(HIDState *hs);
  44. void hid_set_next_idle(HIDState *hs, int64_t curtime);
  45. void hid_pointer_activate(HIDState *hs);
  46. int hid_pointer_poll(HIDState *hs, uint8_t *buf, int len);
  47. int hid_keyboard_poll(HIDState *hs, uint8_t *buf, int len);
  48. int hid_keyboard_write(HIDState *hs, uint8_t *buf, int len);
  49. #endif /* QEMU_HID_H */