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