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