hid.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #ifndef QEMU_HID_H
  2. #define QEMU_HID_H
  3. #include "migration/vmstate.h"
  4. #define HID_MOUSE 1
  5. #define HID_TABLET 2
  6. #define HID_KEYBOARD 3
  7. typedef struct HIDPointerEvent {
  8. int32_t xdx, ydy; /* relative iff it's a mouse, otherwise absolute */
  9. int32_t dz, buttons_state;
  10. } HIDPointerEvent;
  11. #define QUEUE_LENGTH 16 /* should be enough for a triple-click */
  12. #define QUEUE_MASK (QUEUE_LENGTH-1u)
  13. #define QUEUE_INCR(v) ((v)++, (v) &= QUEUE_MASK)
  14. typedef struct HIDState HIDState;
  15. typedef void (*HIDEventFunc)(HIDState *s);
  16. typedef struct HIDMouseState {
  17. HIDPointerEvent queue[QUEUE_LENGTH];
  18. int mouse_grabbed;
  19. QEMUPutMouseEntry *eh_entry;
  20. } HIDMouseState;
  21. typedef struct HIDKeyboardState {
  22. uint32_t keycodes[QUEUE_LENGTH];
  23. uint16_t modifiers;
  24. uint8_t leds;
  25. uint8_t key[16];
  26. int32_t keys;
  27. } HIDKeyboardState;
  28. struct HIDState {
  29. union {
  30. HIDMouseState ptr;
  31. HIDKeyboardState kbd;
  32. };
  33. uint32_t head; /* index into circular queue */
  34. uint32_t n;
  35. int kind;
  36. int32_t protocol;
  37. uint8_t idle;
  38. bool idle_pending;
  39. QEMUTimer *idle_timer;
  40. HIDEventFunc event;
  41. };
  42. void hid_init(HIDState *hs, int kind, HIDEventFunc event);
  43. void hid_reset(HIDState *hs);
  44. void hid_free(HIDState *hs);
  45. bool hid_has_events(HIDState *hs);
  46. void hid_set_next_idle(HIDState *hs);
  47. void hid_pointer_activate(HIDState *hs);
  48. int hid_pointer_poll(HIDState *hs, uint8_t *buf, int len);
  49. int hid_keyboard_poll(HIDState *hs, uint8_t *buf, int len);
  50. int hid_keyboard_write(HIDState *hs, uint8_t *buf, int len);
  51. extern const VMStateDescription vmstate_hid_keyboard_device;
  52. #define VMSTATE_HID_KEYBOARD_DEVICE(_field, _state) { \
  53. .name = (stringify(_field)), \
  54. .size = sizeof(HIDState), \
  55. .vmsd = &vmstate_hid_keyboard_device, \
  56. .flags = VMS_STRUCT, \
  57. .offset = vmstate_offset_value(_state, _field, HIDState), \
  58. }
  59. extern const VMStateDescription vmstate_hid_ptr_device;
  60. #define VMSTATE_HID_POINTER_DEVICE(_field, _state) { \
  61. .name = (stringify(_field)), \
  62. .size = sizeof(HIDState), \
  63. .vmsd = &vmstate_hid_ptr_device, \
  64. .flags = VMS_STRUCT, \
  65. .offset = vmstate_offset_value(_state, _field, HIDState), \
  66. }
  67. #endif /* QEMU_HID_H */