Revision 6fef28ee input.c
b/input.c | ||
---|---|---|
31 | 31 |
|
32 | 32 |
static QEMUPutKBDEvent *qemu_put_kbd_event; |
33 | 33 |
static void *qemu_put_kbd_event_opaque; |
34 |
static QEMUPutMouseEntry *qemu_put_mouse_event_head; |
|
35 |
static QEMUPutMouseEntry *qemu_put_mouse_event_current; |
|
36 | 34 |
static QTAILQ_HEAD(, QEMUPutLEDEntry) led_handlers = QTAILQ_HEAD_INITIALIZER(led_handlers); |
35 |
static QTAILQ_HEAD(, QEMUPutMouseEntry) mouse_handlers = |
|
36 |
QTAILQ_HEAD_INITIALIZER(mouse_handlers); |
|
37 | 37 |
|
38 | 38 |
void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque) |
39 | 39 |
{ |
... | ... | |
45 | 45 |
void *opaque, int absolute, |
46 | 46 |
const char *name) |
47 | 47 |
{ |
48 |
QEMUPutMouseEntry *s, *cursor; |
|
48 |
QEMUPutMouseEntry *s; |
|
49 |
static int mouse_index = 0; |
|
49 | 50 |
|
50 | 51 |
s = qemu_mallocz(sizeof(QEMUPutMouseEntry)); |
51 | 52 |
|
... | ... | |
53 | 54 |
s->qemu_put_mouse_event_opaque = opaque; |
54 | 55 |
s->qemu_put_mouse_event_absolute = absolute; |
55 | 56 |
s->qemu_put_mouse_event_name = qemu_strdup(name); |
56 |
s->next = NULL;
|
|
57 |
s->index = mouse_index++;
|
|
57 | 58 |
|
58 |
if (!qemu_put_mouse_event_head) { |
|
59 |
qemu_put_mouse_event_head = qemu_put_mouse_event_current = s; |
|
60 |
return s; |
|
61 |
} |
|
62 |
|
|
63 |
cursor = qemu_put_mouse_event_head; |
|
64 |
while (cursor->next != NULL) |
|
65 |
cursor = cursor->next; |
|
66 |
|
|
67 |
cursor->next = s; |
|
68 |
qemu_put_mouse_event_current = s; |
|
59 |
QTAILQ_INSERT_TAIL(&mouse_handlers, s, node); |
|
69 | 60 |
|
70 | 61 |
return s; |
71 | 62 |
} |
72 | 63 |
|
73 |
void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry)
|
|
64 |
void qemu_activate_mouse_event_handler(QEMUPutMouseEntry *entry)
|
|
74 | 65 |
{ |
75 |
QEMUPutMouseEntry *prev = NULL, *cursor; |
|
76 |
|
|
77 |
if (!qemu_put_mouse_event_head || entry == NULL) |
|
78 |
return; |
|
79 |
|
|
80 |
cursor = qemu_put_mouse_event_head; |
|
81 |
while (cursor != NULL && cursor != entry) { |
|
82 |
prev = cursor; |
|
83 |
cursor = cursor->next; |
|
84 |
} |
|
66 |
QTAILQ_REMOVE(&mouse_handlers, entry, node); |
|
67 |
QTAILQ_INSERT_HEAD(&mouse_handlers, entry, node); |
|
85 | 68 |
|
86 |
if (cursor == NULL) // does not exist or list empty |
|
87 |
return; |
|
88 |
else if (prev == NULL) { // entry is head |
|
89 |
qemu_put_mouse_event_head = cursor->next; |
|
90 |
if (qemu_put_mouse_event_current == entry) |
|
91 |
qemu_put_mouse_event_current = cursor->next; |
|
92 |
qemu_free(entry->qemu_put_mouse_event_name); |
|
93 |
qemu_free(entry); |
|
94 |
return; |
|
95 |
} |
|
96 |
|
|
97 |
prev->next = entry->next; |
|
69 |
check_mode_change(); |
|
70 |
} |
|
98 | 71 |
|
99 |
if (qemu_put_mouse_event_current == entry) |
|
100 |
qemu_put_mouse_event_current = prev; |
|
72 |
void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry) |
|
73 |
{ |
|
74 |
QTAILQ_REMOVE(&mouse_handlers, entry, node); |
|
101 | 75 |
|
102 | 76 |
qemu_free(entry->qemu_put_mouse_event_name); |
103 | 77 |
qemu_free(entry); |
... | ... | |
142 | 116 |
|
143 | 117 |
void kbd_mouse_event(int dx, int dy, int dz, int buttons_state) |
144 | 118 |
{ |
119 |
QEMUPutMouseEntry *entry; |
|
145 | 120 |
QEMUPutMouseEvent *mouse_event; |
146 | 121 |
void *mouse_event_opaque; |
147 | 122 |
int width; |
148 | 123 |
|
149 |
if (!qemu_put_mouse_event_current) {
|
|
124 |
if (QTAILQ_EMPTY(&mouse_handlers)) {
|
|
150 | 125 |
return; |
151 | 126 |
} |
152 | 127 |
|
153 |
mouse_event =
|
|
154 |
qemu_put_mouse_event_current->qemu_put_mouse_event; |
|
155 |
mouse_event_opaque =
|
|
156 |
qemu_put_mouse_event_current->qemu_put_mouse_event_opaque;
|
|
128 |
entry = QTAILQ_FIRST(&mouse_handlers);
|
|
129 |
|
|
130 |
mouse_event = entry->qemu_put_mouse_event;
|
|
131 |
mouse_event_opaque = entry->qemu_put_mouse_event_opaque;
|
|
157 | 132 |
|
158 | 133 |
if (mouse_event) { |
159 | 134 |
if (graphic_rotate) { |
160 |
if (qemu_put_mouse_event_current->qemu_put_mouse_event_absolute)
|
|
135 |
if (entry->qemu_put_mouse_event_absolute)
|
|
161 | 136 |
width = 0x7fff; |
162 | 137 |
else |
163 | 138 |
width = graphic_width - 1; |
164 | 139 |
mouse_event(mouse_event_opaque, |
165 |
width - dy, dx, dz, buttons_state);
|
|
140 |
width - dy, dx, dz, buttons_state); |
|
166 | 141 |
} else |
167 | 142 |
mouse_event(mouse_event_opaque, |
168 |
dx, dy, dz, buttons_state);
|
|
143 |
dx, dy, dz, buttons_state); |
|
169 | 144 |
} |
170 | 145 |
} |
171 | 146 |
|
172 | 147 |
int kbd_mouse_is_absolute(void) |
173 | 148 |
{ |
174 |
if (!qemu_put_mouse_event_current)
|
|
149 |
if (QTAILQ_EMPTY(&mouse_handlers)) {
|
|
175 | 150 |
return 0; |
151 |
} |
|
176 | 152 |
|
177 |
return qemu_put_mouse_event_current->qemu_put_mouse_event_absolute;
|
|
153 |
return QTAILQ_FIRST(&mouse_handlers)->qemu_put_mouse_event_absolute;
|
|
178 | 154 |
} |
179 | 155 |
|
180 | 156 |
static void info_mice_iter(QObject *data, void *opaque) |
... | ... | |
222 | 198 |
{ |
223 | 199 |
QEMUPutMouseEntry *cursor; |
224 | 200 |
QList *mice_list; |
225 |
int index = 0;
|
|
201 |
int current;
|
|
226 | 202 |
|
227 | 203 |
mice_list = qlist_new(); |
228 | 204 |
|
229 |
if (!qemu_put_mouse_event_head) {
|
|
205 |
if (QTAILQ_EMPTY(&mouse_handlers)) {
|
|
230 | 206 |
goto out; |
231 | 207 |
} |
232 | 208 |
|
233 |
cursor = qemu_put_mouse_event_head; |
|
234 |
while (cursor != NULL) { |
|
209 |
current = QTAILQ_FIRST(&mouse_handlers)->index; |
|
210 |
|
|
211 |
QTAILQ_FOREACH(cursor, &mouse_handlers, node) { |
|
235 | 212 |
QObject *obj; |
236 | 213 |
obj = qobject_from_jsonf("{ 'name': %s, 'index': %d, 'current': %i }", |
237 | 214 |
cursor->qemu_put_mouse_event_name, |
238 |
index, cursor == qemu_put_mouse_event_current); |
|
215 |
cursor->index, |
|
216 |
cursor->index == current); |
|
239 | 217 |
qlist_append_obj(mice_list, obj); |
240 |
index++; |
|
241 |
cursor = cursor->next; |
|
242 | 218 |
} |
243 | 219 |
|
244 | 220 |
out: |
... | ... | |
248 | 224 |
void do_mouse_set(Monitor *mon, const QDict *qdict) |
249 | 225 |
{ |
250 | 226 |
QEMUPutMouseEntry *cursor; |
251 |
int i = 0; |
|
252 | 227 |
int index = qdict_get_int(qdict, "index"); |
228 |
int found = 0; |
|
253 | 229 |
|
254 |
if (!qemu_put_mouse_event_head) {
|
|
230 |
if (QTAILQ_EMPTY(&mouse_handlers)) {
|
|
255 | 231 |
monitor_printf(mon, "No mouse devices connected\n"); |
256 | 232 |
return; |
257 | 233 |
} |
258 | 234 |
|
259 |
cursor = qemu_put_mouse_event_head; |
|
260 |
while (cursor != NULL && index != i) { |
|
261 |
i++; |
|
262 |
cursor = cursor->next; |
|
235 |
QTAILQ_FOREACH(cursor, &mouse_handlers, node) { |
|
236 |
if (cursor->index == index) { |
|
237 |
found = 1; |
|
238 |
qemu_activate_mouse_event_handler(cursor); |
|
239 |
break; |
|
240 |
} |
|
263 | 241 |
} |
264 | 242 |
|
265 |
if (cursor != NULL) |
|
266 |
qemu_put_mouse_event_current = cursor; |
|
267 |
else |
|
243 |
if (!found) { |
|
268 | 244 |
monitor_printf(mon, "Mouse at given index not found\n"); |
245 |
} |
|
269 | 246 |
} |
Also available in: Unified diff