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
30 #include "qmp-commands.h"
31 #include "tizen/src/debug_ch.h"
33 MULTI_DEBUG_CHANNEL(tizen, input);
35 static QEMUPutKBDEvent *qemu_put_kbd_event;
36 static void *qemu_put_kbd_event_opaque;
38 static QEMUPutKBDEvent *qemu_put_ps2kbd_event;
39 static void *qemu_put_ps2kbd_event_opaque;
41 static QTAILQ_HEAD(, QEMUPutLEDEntry) led_handlers = QTAILQ_HEAD_INITIALIZER(led_handlers);
42 static QTAILQ_HEAD(, QEMUPutMouseEntry) mouse_handlers =
43 QTAILQ_HEAD_INITIALIZER(mouse_handlers);
44 static NotifierList mouse_mode_notifiers =
45 NOTIFIER_LIST_INITIALIZER(mouse_mode_notifiers);
47 void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque)
49 qemu_put_kbd_event_opaque = opaque;
50 qemu_put_kbd_event = func;
53 void qemu_remove_kbd_event_handler(void)
55 qemu_put_kbd_event_opaque = NULL;
56 qemu_put_kbd_event = NULL;
60 /* use ps2kbd device as a hardkey device. */
61 void qemu_add_ps2kbd_event_handler(QEMUPutKBDEvent *func, void *opaque)
63 qemu_put_ps2kbd_event_opaque = opaque;
64 qemu_put_ps2kbd_event = func;
67 void qemu_remove_ps2kbd_event_handler(void)
69 qemu_put_ps2kbd_event_opaque = NULL;
70 qemu_put_ps2kbd_event = NULL;
73 void ps2kbd_put_keycode(int keycode)
75 if (qemu_put_ps2kbd_event) {
76 qemu_put_ps2kbd_event(qemu_put_ps2kbd_event_opaque, keycode);
81 static void check_mode_change(void)
83 static int current_is_absolute, current_has_absolute;
87 is_absolute = kbd_mouse_is_absolute();
88 has_absolute = kbd_mouse_has_absolute();
90 if (is_absolute != current_is_absolute ||
91 has_absolute != current_has_absolute) {
92 notifier_list_notify(&mouse_mode_notifiers, NULL);
95 current_is_absolute = is_absolute;
96 current_has_absolute = has_absolute;
99 QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
100 void *opaque, int absolute,
103 QEMUPutMouseEntry *s;
104 static int mouse_index = 0;
106 s = g_malloc0(sizeof(QEMUPutMouseEntry));
108 s->qemu_put_mouse_event = func;
109 s->qemu_put_mouse_event_opaque = opaque;
110 s->qemu_put_mouse_event_absolute = absolute;
111 s->qemu_put_mouse_event_name = g_strdup(name);
112 s->index = mouse_index++;
114 QTAILQ_INSERT_TAIL(&mouse_handlers, s, node);
121 void qemu_activate_mouse_event_handler(QEMUPutMouseEntry *entry)
123 QTAILQ_REMOVE(&mouse_handlers, entry, node);
124 QTAILQ_INSERT_HEAD(&mouse_handlers, entry, node);
129 void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry)
131 QTAILQ_REMOVE(&mouse_handlers, entry, node);
133 g_free(entry->qemu_put_mouse_event_name);
139 QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func,
144 s = g_malloc0(sizeof(QEMUPutLEDEntry));
148 QTAILQ_INSERT_TAIL(&led_handlers, s, next);
152 void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry)
156 QTAILQ_REMOVE(&led_handlers, entry, next);
160 void kbd_put_keycode(int keycode)
162 if (!runstate_is_running() && !runstate_check(RUN_STATE_SUSPENDED)) {
165 if (qemu_put_kbd_event) {
166 qemu_put_kbd_event(qemu_put_kbd_event_opaque, keycode);
170 void kbd_put_ledstate(int ledstate)
172 QEMUPutLEDEntry *cursor;
174 QTAILQ_FOREACH(cursor, &led_handlers, next) {
175 cursor->put_led(cursor->opaque, ledstate);
179 void kbd_mouse_event(int dx, int dy, int dz, int buttons_state)
181 QEMUPutMouseEntry *entry;
182 QEMUPutMouseEvent *mouse_event;
183 void *mouse_event_opaque;
186 if (!runstate_is_running() && !runstate_check(RUN_STATE_SUSPENDED)) {
189 if (QTAILQ_EMPTY(&mouse_handlers)) {
192 #if defined (CONFIG_MARU)
193 QTAILQ_FOREACH(entry, &mouse_handlers, node) {
194 /* if mouse event is wheelup ,wheeldown or move
195 then go to ps2 mouse event(index == 0) */
196 if((buttons_state > 3 && entry->index == 0)) {
197 //INFO("input device: %s, event: %d\n", entry->qemu_put_mouse_event_name, buttons_state);
199 mouse_event = entry->qemu_put_mouse_event;
200 mouse_event_opaque = entry->qemu_put_mouse_event_opaque;
204 /* other events(mouse up, down and drag), go to touch screen */
206 entry = QTAILQ_FIRST(&mouse_handlers);
207 mouse_event = entry->qemu_put_mouse_event;
208 mouse_event_opaque = entry->qemu_put_mouse_event_opaque;
209 //INFO("input device: %s, event: %d\n", entry->qemu_put_mouse_event_name, buttons_state);
212 entry = QTAILQ_FIRST(&mouse_handlers);
214 mouse_event = entry->qemu_put_mouse_event;
215 mouse_event_opaque = entry->qemu_put_mouse_event_opaque;
218 if (entry->qemu_put_mouse_event_absolute) {
222 width = graphic_width - 1;
223 height = graphic_height - 1;
226 switch (graphic_rotate) {
228 mouse_event(mouse_event_opaque,
229 dx, dy, dz, buttons_state);
232 mouse_event(mouse_event_opaque,
233 width - dy, dx, dz, buttons_state);
236 mouse_event(mouse_event_opaque,
237 width - dx, height - dy, dz, buttons_state);
240 mouse_event(mouse_event_opaque,
241 dy, height - dx, dz, buttons_state);
247 int kbd_mouse_is_absolute(void)
249 if (QTAILQ_EMPTY(&mouse_handlers)) {
253 return QTAILQ_FIRST(&mouse_handlers)->qemu_put_mouse_event_absolute;
256 int kbd_mouse_has_absolute(void)
258 QEMUPutMouseEntry *entry;
260 QTAILQ_FOREACH(entry, &mouse_handlers, node) {
261 if (entry->qemu_put_mouse_event_absolute) {
269 MouseInfoList *qmp_query_mice(Error **errp)
271 MouseInfoList *mice_list = NULL;
272 QEMUPutMouseEntry *cursor;
275 QTAILQ_FOREACH(cursor, &mouse_handlers, node) {
276 MouseInfoList *info = g_malloc0(sizeof(*info));
277 info->value = g_malloc0(sizeof(*info->value));
278 info->value->name = g_strdup(cursor->qemu_put_mouse_event_name);
279 info->value->index = cursor->index;
280 info->value->absolute = !!cursor->qemu_put_mouse_event_absolute;
281 info->value->current = current;
285 info->next = mice_list;
292 void do_mouse_set(Monitor *mon, const QDict *qdict)
294 QEMUPutMouseEntry *cursor;
295 int index = qdict_get_int(qdict, "index");
298 if (QTAILQ_EMPTY(&mouse_handlers)) {
299 monitor_printf(mon, "No mouse devices connected\n");
303 QTAILQ_FOREACH(cursor, &mouse_handlers, node) {
304 if (cursor->index == index) {
306 qemu_activate_mouse_event_handler(cursor);
312 monitor_printf(mon, "Mouse at given index not found\n");
318 void qemu_add_mouse_mode_change_notifier(Notifier *notify)
320 notifier_list_add(&mouse_mode_notifiers, notify);
323 void qemu_remove_mouse_mode_change_notifier(Notifier *notify)
325 notifier_remove(notify);