4 * Copyright (c) 2003-2008 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
32 static QEMUPutKBDEvent
*qemu_put_kbd_event
;
33 static void *qemu_put_kbd_event_opaque
;
34 static QEMUPutMouseEntry
*qemu_put_mouse_event_head
;
35 static QEMUPutMouseEntry
*qemu_put_mouse_event_current
;
37 void qemu_add_kbd_event_handler(QEMUPutKBDEvent
*func
, void *opaque
)
39 qemu_put_kbd_event_opaque
= opaque
;
40 qemu_put_kbd_event
= func
;
43 QEMUPutMouseEntry
*qemu_add_mouse_event_handler(QEMUPutMouseEvent
*func
,
44 void *opaque
, int absolute
,
47 QEMUPutMouseEntry
*s
, *cursor
;
49 s
= qemu_mallocz(sizeof(QEMUPutMouseEntry
));
51 s
->qemu_put_mouse_event
= func
;
52 s
->qemu_put_mouse_event_opaque
= opaque
;
53 s
->qemu_put_mouse_event_absolute
= absolute
;
54 s
->qemu_put_mouse_event_name
= qemu_strdup(name
);
57 if (!qemu_put_mouse_event_head
) {
58 qemu_put_mouse_event_head
= qemu_put_mouse_event_current
= s
;
62 cursor
= qemu_put_mouse_event_head
;
63 while (cursor
->next
!= NULL
)
64 cursor
= cursor
->next
;
67 qemu_put_mouse_event_current
= s
;
72 void qemu_remove_mouse_event_handler(QEMUPutMouseEntry
*entry
)
74 QEMUPutMouseEntry
*prev
= NULL
, *cursor
;
76 if (!qemu_put_mouse_event_head
|| entry
== NULL
)
79 cursor
= qemu_put_mouse_event_head
;
80 while (cursor
!= NULL
&& cursor
!= entry
) {
82 cursor
= cursor
->next
;
85 if (cursor
== NULL
) // does not exist or list empty
87 else if (prev
== NULL
) { // entry is head
88 qemu_put_mouse_event_head
= cursor
->next
;
89 if (qemu_put_mouse_event_current
== entry
)
90 qemu_put_mouse_event_current
= cursor
->next
;
91 qemu_free(entry
->qemu_put_mouse_event_name
);
96 prev
->next
= entry
->next
;
98 if (qemu_put_mouse_event_current
== entry
)
99 qemu_put_mouse_event_current
= prev
;
101 qemu_free(entry
->qemu_put_mouse_event_name
);
105 void kbd_put_keycode(int keycode
)
107 if (qemu_put_kbd_event
) {
108 qemu_put_kbd_event(qemu_put_kbd_event_opaque
, keycode
);
112 void kbd_mouse_event(int dx
, int dy
, int dz
, int buttons_state
)
114 QEMUPutMouseEvent
*mouse_event
;
115 void *mouse_event_opaque
;
118 if (!qemu_put_mouse_event_current
) {
123 qemu_put_mouse_event_current
->qemu_put_mouse_event
;
125 qemu_put_mouse_event_current
->qemu_put_mouse_event_opaque
;
128 if (graphic_rotate
) {
129 if (qemu_put_mouse_event_current
->qemu_put_mouse_event_absolute
)
132 width
= graphic_width
- 1;
133 mouse_event(mouse_event_opaque
,
134 width
- dy
, dx
, dz
, buttons_state
);
136 mouse_event(mouse_event_opaque
,
137 dx
, dy
, dz
, buttons_state
);
141 int kbd_mouse_is_absolute(void)
143 if (!qemu_put_mouse_event_current
)
146 return qemu_put_mouse_event_current
->qemu_put_mouse_event_absolute
;
149 static void info_mice_iter(QObject
*data
, void *opaque
)
152 Monitor
*mon
= opaque
;
154 mouse
= qobject_to_qdict(data
);
155 monitor_printf(mon
, "%c Mouse #%" PRId64
": %s\n",
156 (qdict_get_bool(mouse
, "current") ? '*' : ' '),
157 qdict_get_int(mouse
, "index"), qdict_get_str(mouse
, "name"));
160 void do_info_mice_print(Monitor
*mon
, const QObject
*data
)
164 mice_list
= qobject_to_qlist(data
);
165 if (qlist_empty(mice_list
)) {
166 monitor_printf(mon
, "No mouse devices connected\n");
170 qlist_iter(mice_list
, info_mice_iter
, mon
);
174 * do_info_mice(): Show VM mice information
176 * Each mouse is represented by a QDict, the returned QObject is a QList of
179 * The mouse QDict contains the following:
181 * - "name": mouse's name
182 * - "index": mouse's index
183 * - "current": true if this mouse is receiving events, false otherwise
187 * [ { "name": "QEMU Microsoft Mouse", "index": 0, "current": false },
188 * { "name": "QEMU PS/2 Mouse", "index": 1, "current": true } ]
190 void do_info_mice(Monitor
*mon
, QObject
**ret_data
)
192 QEMUPutMouseEntry
*cursor
;
196 mice_list
= qlist_new();
198 if (!qemu_put_mouse_event_head
) {
202 cursor
= qemu_put_mouse_event_head
;
203 while (cursor
!= NULL
) {
205 obj
= qobject_from_jsonf("{ 'name': %s, 'index': %d, 'current': %i }",
206 cursor
->qemu_put_mouse_event_name
,
207 index
, cursor
== qemu_put_mouse_event_current
);
208 qlist_append_obj(mice_list
, obj
);
210 cursor
= cursor
->next
;
214 *ret_data
= QOBJECT(mice_list
);
217 void do_mouse_set(Monitor
*mon
, const QDict
*qdict
)
219 QEMUPutMouseEntry
*cursor
;
221 int index
= qdict_get_int(qdict
, "index");
223 if (!qemu_put_mouse_event_head
) {
224 monitor_printf(mon
, "No mouse devices connected\n");
228 cursor
= qemu_put_mouse_event_head
;
229 while (cursor
!= NULL
&& index
!= i
) {
231 cursor
= cursor
->next
;
235 qemu_put_mouse_event_current
= cursor
;
237 monitor_printf(mon
, "Mouse at given index not found\n");