]> Git Repo - qemu.git/blob - input.c
Allocate memory below 4GB as one chunk
[qemu.git] / input.c
1 /*
2  * QEMU System Emulator
3  *
4  * Copyright (c) 2003-2008 Fabrice Bellard
5  *
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:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
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
22  * THE SOFTWARE.
23  */
24
25 #include "sysemu.h"
26 #include "net.h"
27 #include "monitor.h"
28 #include "console.h"
29 #include "qjson.h"
30
31
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;
36
37 void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque)
38 {
39     qemu_put_kbd_event_opaque = opaque;
40     qemu_put_kbd_event = func;
41 }
42
43 QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
44                                                 void *opaque, int absolute,
45                                                 const char *name)
46 {
47     QEMUPutMouseEntry *s, *cursor;
48
49     s = qemu_mallocz(sizeof(QEMUPutMouseEntry));
50
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);
55     s->next = NULL;
56
57     if (!qemu_put_mouse_event_head) {
58         qemu_put_mouse_event_head = qemu_put_mouse_event_current = s;
59         return s;
60     }
61
62     cursor = qemu_put_mouse_event_head;
63     while (cursor->next != NULL)
64         cursor = cursor->next;
65
66     cursor->next = s;
67     qemu_put_mouse_event_current = s;
68
69     return s;
70 }
71
72 void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry)
73 {
74     QEMUPutMouseEntry *prev = NULL, *cursor;
75
76     if (!qemu_put_mouse_event_head || entry == NULL)
77         return;
78
79     cursor = qemu_put_mouse_event_head;
80     while (cursor != NULL && cursor != entry) {
81         prev = cursor;
82         cursor = cursor->next;
83     }
84
85     if (cursor == NULL) // does not exist or list empty
86         return;
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);
92         qemu_free(entry);
93         return;
94     }
95
96     prev->next = entry->next;
97
98     if (qemu_put_mouse_event_current == entry)
99         qemu_put_mouse_event_current = prev;
100
101     qemu_free(entry->qemu_put_mouse_event_name);
102     qemu_free(entry);
103 }
104
105 void kbd_put_keycode(int keycode)
106 {
107     if (qemu_put_kbd_event) {
108         qemu_put_kbd_event(qemu_put_kbd_event_opaque, keycode);
109     }
110 }
111
112 void kbd_mouse_event(int dx, int dy, int dz, int buttons_state)
113 {
114     QEMUPutMouseEvent *mouse_event;
115     void *mouse_event_opaque;
116     int width;
117
118     if (!qemu_put_mouse_event_current) {
119         return;
120     }
121
122     mouse_event =
123         qemu_put_mouse_event_current->qemu_put_mouse_event;
124     mouse_event_opaque =
125         qemu_put_mouse_event_current->qemu_put_mouse_event_opaque;
126
127     if (mouse_event) {
128         if (graphic_rotate) {
129             if (qemu_put_mouse_event_current->qemu_put_mouse_event_absolute)
130                 width = 0x7fff;
131             else
132                 width = graphic_width - 1;
133             mouse_event(mouse_event_opaque,
134                                  width - dy, dx, dz, buttons_state);
135         } else
136             mouse_event(mouse_event_opaque,
137                                  dx, dy, dz, buttons_state);
138     }
139 }
140
141 int kbd_mouse_is_absolute(void)
142 {
143     if (!qemu_put_mouse_event_current)
144         return 0;
145
146     return qemu_put_mouse_event_current->qemu_put_mouse_event_absolute;
147 }
148
149 static void info_mice_iter(QObject *data, void *opaque)
150 {
151     QDict *mouse;
152     Monitor *mon = opaque;
153
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"));
158 }
159
160 void do_info_mice_print(Monitor *mon, const QObject *data)
161 {
162     QList *mice_list;
163
164     mice_list = qobject_to_qlist(data);
165     if (qlist_empty(mice_list)) {
166         monitor_printf(mon, "No mouse devices connected\n");
167         return;
168     }
169
170     qlist_iter(mice_list, info_mice_iter, mon);
171 }
172
173 /**
174  * do_info_mice(): Show VM mice information
175  *
176  * Each mouse is represented by a QDict, the returned QObject is a QList of
177  * all mice.
178  *
179  * The mouse QDict contains the following:
180  *
181  * - "name": mouse's name
182  * - "index": mouse's index
183  * - "current": true if this mouse is receiving events, false otherwise
184  *
185  * Example:
186  *
187  * [ { "name": "QEMU Microsoft Mouse", "index": 0, "current": false },
188  *   { "name": "QEMU PS/2 Mouse", "index": 1, "current": true } ]
189  */
190 void do_info_mice(Monitor *mon, QObject **ret_data)
191 {
192     QEMUPutMouseEntry *cursor;
193     QList *mice_list;
194     int index = 0;
195
196     mice_list = qlist_new();
197
198     if (!qemu_put_mouse_event_head) {
199         goto out;
200     }
201
202     cursor = qemu_put_mouse_event_head;
203     while (cursor != NULL) {
204         QObject *obj;
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);
209         index++;
210         cursor = cursor->next;
211     }
212
213 out:
214     *ret_data = QOBJECT(mice_list);
215 }
216
217 void do_mouse_set(Monitor *mon, const QDict *qdict)
218 {
219     QEMUPutMouseEntry *cursor;
220     int i = 0;
221     int index = qdict_get_int(qdict, "index");
222
223     if (!qemu_put_mouse_event_head) {
224         monitor_printf(mon, "No mouse devices connected\n");
225         return;
226     }
227
228     cursor = qemu_put_mouse_event_head;
229     while (cursor != NULL && index != i) {
230         i++;
231         cursor = cursor->next;
232     }
233
234     if (cursor != NULL)
235         qemu_put_mouse_event_current = cursor;
236     else
237         monitor_printf(mon, "Mouse at given index not found\n");
238 }
This page took 0.071977 seconds and 4 git commands to generate.