2010-01-13 16:05:34 +03:00
|
|
|
/*
|
|
|
|
* QEMU System Emulator
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003-2008 Fabrice Bellard
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2012-12-17 21:20:04 +04:00
|
|
|
#include "sysemu/sysemu.h"
|
2012-12-17 21:19:49 +04:00
|
|
|
#include "monitor/monitor.h"
|
2012-11-28 15:06:30 +04:00
|
|
|
#include "ui/console.h"
|
2012-12-17 21:19:43 +04:00
|
|
|
#include "qapi/error.h"
|
2011-09-21 22:29:55 +04:00
|
|
|
#include "qmp-commands.h"
|
2012-08-31 06:56:26 +04:00
|
|
|
#include "qapi-types.h"
|
2013-05-16 09:19:47 +04:00
|
|
|
#include "ui/keymaps.h"
|
2010-01-13 16:05:34 +03:00
|
|
|
|
2013-04-24 14:08:37 +04:00
|
|
|
struct QEMUPutMouseEntry {
|
|
|
|
QEMUPutMouseEvent *qemu_put_mouse_event;
|
|
|
|
void *qemu_put_mouse_event_opaque;
|
|
|
|
int qemu_put_mouse_event_absolute;
|
|
|
|
char *qemu_put_mouse_event_name;
|
|
|
|
|
|
|
|
int index;
|
|
|
|
|
|
|
|
/* used internally by qemu for handling mice */
|
|
|
|
QTAILQ_ENTRY(QEMUPutMouseEntry) node;
|
|
|
|
};
|
|
|
|
|
2013-04-24 14:08:38 +04:00
|
|
|
struct QEMUPutKbdEntry {
|
|
|
|
QEMUPutKBDEvent *put_kbd;
|
|
|
|
void *opaque;
|
|
|
|
QTAILQ_ENTRY(QEMUPutKbdEntry) next;
|
|
|
|
};
|
|
|
|
|
2013-04-24 14:08:37 +04:00
|
|
|
struct QEMUPutLEDEntry {
|
|
|
|
QEMUPutLEDEvent *put_led;
|
|
|
|
void *opaque;
|
|
|
|
QTAILQ_ENTRY(QEMUPutLEDEntry) next;
|
|
|
|
};
|
|
|
|
|
2013-04-24 14:08:38 +04:00
|
|
|
static QTAILQ_HEAD(, QEMUPutLEDEntry) led_handlers =
|
|
|
|
QTAILQ_HEAD_INITIALIZER(led_handlers);
|
|
|
|
static QTAILQ_HEAD(, QEMUPutKbdEntry) kbd_handlers =
|
|
|
|
QTAILQ_HEAD_INITIALIZER(kbd_handlers);
|
2010-03-10 05:52:22 +03:00
|
|
|
static QTAILQ_HEAD(, QEMUPutMouseEntry) mouse_handlers =
|
|
|
|
QTAILQ_HEAD_INITIALIZER(mouse_handlers);
|
2013-04-24 14:08:38 +04:00
|
|
|
static NotifierList mouse_mode_notifiers =
|
2010-03-09 22:25:00 +03:00
|
|
|
NOTIFIER_LIST_INITIALIZER(mouse_mode_notifiers);
|
2010-01-13 16:05:34 +03:00
|
|
|
|
2012-08-31 06:56:26 +04:00
|
|
|
static const int key_defs[] = {
|
2012-08-31 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|
|
|
|
#endif
|
|
|
|
[Q_KEY_CODE_MAX] = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
int index_from_key(const char *key)
|
|
|
|
{
|
2012-09-20 21:47:02 +04:00
|
|
|
int i;
|
2012-08-31 06:56:25 +04:00
|
|
|
|
|
|
|
for (i = 0; QKeyCode_lookup[i] != NULL; i++) {
|
|
|
|
if (!strcmp(key, QKeyCode_lookup[i])) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return Q_KEY_CODE_MAX if the key is invalid */
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
int index_from_keycode(int code)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < Q_KEY_CODE_MAX; i++) {
|
|
|
|
if (key_defs[i] == code) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return Q_KEY_CODE_MAX if the code is invalid */
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2012-09-20 20:44:28 +04:00
|
|
|
static int *keycodes;
|
|
|
|
static int keycodes_size;
|
2012-08-31 06:56:26 +04:00
|
|
|
static QEMUTimer *key_timer;
|
|
|
|
|
2012-09-20 21:19:47 +04:00
|
|
|
static int keycode_from_keyvalue(const KeyValue *value)
|
|
|
|
{
|
|
|
|
if (value->kind == KEY_VALUE_KIND_QCODE) {
|
|
|
|
return key_defs[value->qcode];
|
|
|
|
} else {
|
|
|
|
assert(value->kind == KEY_VALUE_KIND_NUMBER);
|
|
|
|
return value->number;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_keycodes(void)
|
|
|
|
{
|
|
|
|
g_free(keycodes);
|
|
|
|
keycodes = NULL;
|
|
|
|
keycodes_size = 0;
|
|
|
|
}
|
|
|
|
|
2012-08-31 06:56:26 +04:00
|
|
|
static void release_keys(void *opaque)
|
|
|
|
{
|
2013-04-16 09:47:32 +04:00
|
|
|
while (keycodes_size > 0) {
|
2013-05-16 09:19:47 +04:00
|
|
|
if (keycodes[--keycodes_size] & SCANCODE_GREY) {
|
|
|
|
kbd_put_keycode(SCANCODE_EMUL0);
|
2012-08-31 06:56:26 +04:00
|
|
|
}
|
2013-05-16 09:19:47 +04:00
|
|
|
kbd_put_keycode(keycodes[keycodes_size] | SCANCODE_UP);
|
2012-08-31 06:56:26 +04:00
|
|
|
}
|
2012-09-20 20:44:28 +04:00
|
|
|
|
2012-09-20 21:19:47 +04:00
|
|
|
free_keycodes();
|
2012-08-31 06:56:26 +04:00
|
|
|
}
|
|
|
|
|
2012-09-20 21:19:47 +04:00
|
|
|
void qmp_send_key(KeyValueList *keys, bool has_hold_time, int64_t hold_time,
|
2012-08-31 06:56:26 +04:00
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
int keycode;
|
2012-09-20 21:19:47 +04:00
|
|
|
KeyValueList *p;
|
2012-08-31 06:56:26 +04:00
|
|
|
|
|
|
|
if (!key_timer) {
|
|
|
|
key_timer = qemu_new_timer_ns(vm_clock, release_keys, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (keycodes != NULL) {
|
|
|
|
qemu_del_timer(key_timer);
|
|
|
|
release_keys(NULL);
|
|
|
|
}
|
2012-09-20 20:44:28 +04:00
|
|
|
|
2012-08-31 06:56:26 +04:00
|
|
|
if (!has_hold_time) {
|
|
|
|
hold_time = 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (p = keys; p != NULL; p = p->next) {
|
|
|
|
/* key down events */
|
2012-09-20 21:19:47 +04:00
|
|
|
keycode = keycode_from_keyvalue(p->value);
|
|
|
|
if (keycode < 0x01 || keycode > 0xff) {
|
error: Strip trailing '\n' from error string arguments (again)
Commit 6daf194d and be62a2eb got rid of a bunch, but they keep coming
back. Tracked down with this Coccinelle semantic patch:
@r@
expression err, eno, cls, fmt;
position p;
@@
(
error_report(fmt, ...)@p
|
error_set(err, cls, fmt, ...)@p
|
error_set_errno(err, eno, cls, fmt, ...)@p
|
error_setg(err, fmt, ...)@p
|
error_setg_errno(err, eno, fmt, ...)@p
)
@script:python@
fmt << r.fmt;
p << r.p;
@@
if "\\n" in str(fmt):
print "%s:%s:%s:%s" % (p[0].file, p[0].line, p[0].column, fmt)
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-id: 1360354939-10994-4-git-send-email-armbru@redhat.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2013-02-09 00:22:16 +04:00
|
|
|
error_setg(errp, "invalid hex keycode 0x%x", keycode);
|
2012-09-20 21:19:47 +04:00
|
|
|
free_keycodes();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-16 09:19:47 +04:00
|
|
|
if (keycode & SCANCODE_GREY) {
|
|
|
|
kbd_put_keycode(SCANCODE_EMUL0);
|
2012-08-31 06:56:26 +04:00
|
|
|
}
|
2013-05-16 09:19:47 +04:00
|
|
|
kbd_put_keycode(keycode & SCANCODE_KEYCODEMASK);
|
2012-09-20 20:44:28 +04:00
|
|
|
|
|
|
|
keycodes = g_realloc(keycodes, sizeof(int) * (keycodes_size + 1));
|
|
|
|
keycodes[keycodes_size++] = keycode;
|
2012-08-31 06:56:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* delayed key up events */
|
|
|
|
qemu_mod_timer(key_timer, qemu_get_clock_ns(vm_clock) +
|
|
|
|
muldiv64(get_ticks_per_sec(), hold_time, 1000));
|
|
|
|
}
|
|
|
|
|
2013-04-24 14:08:38 +04:00
|
|
|
QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque)
|
2010-01-13 16:05:34 +03:00
|
|
|
{
|
2013-04-24 14:08:38 +04:00
|
|
|
QEMUPutKbdEntry *entry;
|
|
|
|
|
|
|
|
entry = g_malloc0(sizeof(QEMUPutKbdEntry));
|
|
|
|
entry->put_kbd = func;
|
|
|
|
entry->opaque = opaque;
|
|
|
|
QTAILQ_INSERT_HEAD(&kbd_handlers, entry, next);
|
|
|
|
return entry;
|
2010-01-13 16:05:34 +03:00
|
|
|
}
|
|
|
|
|
2013-04-24 14:08:38 +04:00
|
|
|
void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry)
|
2010-06-08 17:12:18 +04:00
|
|
|
{
|
2013-04-24 14:08:38 +04:00
|
|
|
QTAILQ_REMOVE(&kbd_handlers, entry, next);
|
2010-06-08 17:12:18 +04:00
|
|
|
}
|
|
|
|
|
2010-03-09 22:25:00 +03:00
|
|
|
static void check_mode_change(void)
|
|
|
|
{
|
|
|
|
static int current_is_absolute, current_has_absolute;
|
|
|
|
int is_absolute;
|
|
|
|
int has_absolute;
|
|
|
|
|
|
|
|
is_absolute = kbd_mouse_is_absolute();
|
|
|
|
has_absolute = kbd_mouse_has_absolute();
|
|
|
|
|
|
|
|
if (is_absolute != current_is_absolute ||
|
|
|
|
has_absolute != current_has_absolute) {
|
2011-06-20 16:06:26 +04:00
|
|
|
notifier_list_notify(&mouse_mode_notifiers, NULL);
|
2010-03-09 22:25:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
current_is_absolute = is_absolute;
|
|
|
|
current_has_absolute = has_absolute;
|
|
|
|
}
|
|
|
|
|
2010-01-13 16:05:34 +03:00
|
|
|
QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
|
|
|
|
void *opaque, int absolute,
|
|
|
|
const char *name)
|
|
|
|
{
|
2010-03-10 05:52:22 +03:00
|
|
|
QEMUPutMouseEntry *s;
|
|
|
|
static int mouse_index = 0;
|
2010-01-13 16:05:34 +03:00
|
|
|
|
2011-08-21 07:09:37 +04:00
|
|
|
s = g_malloc0(sizeof(QEMUPutMouseEntry));
|
2010-01-13 16:05:34 +03:00
|
|
|
|
|
|
|
s->qemu_put_mouse_event = func;
|
|
|
|
s->qemu_put_mouse_event_opaque = opaque;
|
|
|
|
s->qemu_put_mouse_event_absolute = absolute;
|
2011-08-21 07:09:37 +04:00
|
|
|
s->qemu_put_mouse_event_name = g_strdup(name);
|
2010-03-10 05:52:22 +03:00
|
|
|
s->index = mouse_index++;
|
2010-01-13 16:05:34 +03:00
|
|
|
|
2010-03-10 05:52:22 +03:00
|
|
|
QTAILQ_INSERT_TAIL(&mouse_handlers, s, node);
|
2010-01-13 16:05:34 +03:00
|
|
|
|
2010-03-09 22:25:00 +03:00
|
|
|
check_mode_change();
|
|
|
|
|
2010-01-13 16:05:34 +03:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2010-03-10 05:52:22 +03:00
|
|
|
void qemu_activate_mouse_event_handler(QEMUPutMouseEntry *entry)
|
2010-01-13 16:05:34 +03:00
|
|
|
{
|
2010-03-10 05:52:22 +03:00
|
|
|
QTAILQ_REMOVE(&mouse_handlers, entry, node);
|
|
|
|
QTAILQ_INSERT_HEAD(&mouse_handlers, entry, node);
|
2010-01-13 16:05:34 +03:00
|
|
|
|
2010-03-10 05:52:22 +03:00
|
|
|
check_mode_change();
|
|
|
|
}
|
2010-01-13 16:05:34 +03:00
|
|
|
|
2010-03-10 05:52:22 +03:00
|
|
|
void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry)
|
|
|
|
{
|
|
|
|
QTAILQ_REMOVE(&mouse_handlers, entry, node);
|
2010-01-13 16:05:34 +03:00
|
|
|
|
2011-08-21 07:09:37 +04:00
|
|
|
g_free(entry->qemu_put_mouse_event_name);
|
|
|
|
g_free(entry);
|
2010-03-09 22:25:00 +03:00
|
|
|
|
|
|
|
check_mode_change();
|
2010-01-13 16:05:34 +03:00
|
|
|
}
|
|
|
|
|
2010-02-26 19:17:36 +03:00
|
|
|
QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
QEMUPutLEDEntry *s;
|
|
|
|
|
2011-08-21 07:09:37 +04:00
|
|
|
s = g_malloc0(sizeof(QEMUPutLEDEntry));
|
2010-02-26 19:17:36 +03:00
|
|
|
|
|
|
|
s->put_led = func;
|
|
|
|
s->opaque = opaque;
|
|
|
|
QTAILQ_INSERT_TAIL(&led_handlers, s, next);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry)
|
|
|
|
{
|
|
|
|
if (entry == NULL)
|
|
|
|
return;
|
|
|
|
QTAILQ_REMOVE(&led_handlers, entry, next);
|
2011-08-21 07:09:37 +04:00
|
|
|
g_free(entry);
|
2010-02-26 19:17:36 +03:00
|
|
|
}
|
|
|
|
|
2010-01-13 16:05:34 +03:00
|
|
|
void kbd_put_keycode(int keycode)
|
|
|
|
{
|
2013-04-24 14:08:38 +04:00
|
|
|
QEMUPutKbdEntry *entry = QTAILQ_FIRST(&kbd_handlers);
|
|
|
|
|
2012-04-27 20:33:36 +04:00
|
|
|
if (!runstate_is_running() && !runstate_check(RUN_STATE_SUSPENDED)) {
|
2012-02-15 12:15:37 +04:00
|
|
|
return;
|
|
|
|
}
|
2013-04-24 14:08:38 +04:00
|
|
|
if (entry) {
|
|
|
|
entry->put_kbd(entry->opaque, keycode);
|
2010-01-13 16:05:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-26 19:17:36 +03:00
|
|
|
void kbd_put_ledstate(int ledstate)
|
|
|
|
{
|
|
|
|
QEMUPutLEDEntry *cursor;
|
|
|
|
|
|
|
|
QTAILQ_FOREACH(cursor, &led_handlers, next) {
|
|
|
|
cursor->put_led(cursor->opaque, ledstate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-13 16:05:34 +03:00
|
|
|
void kbd_mouse_event(int dx, int dy, int dz, int buttons_state)
|
|
|
|
{
|
2010-03-10 05:52:22 +03:00
|
|
|
QEMUPutMouseEntry *entry;
|
2010-01-13 16:05:34 +03:00
|
|
|
QEMUPutMouseEvent *mouse_event;
|
|
|
|
void *mouse_event_opaque;
|
2011-06-17 14:04:36 +04:00
|
|
|
int width, height;
|
2010-01-13 16:05:34 +03:00
|
|
|
|
2012-04-27 20:33:36 +04:00
|
|
|
if (!runstate_is_running() && !runstate_check(RUN_STATE_SUSPENDED)) {
|
2012-02-15 12:15:37 +04:00
|
|
|
return;
|
|
|
|
}
|
2010-03-10 05:52:22 +03:00
|
|
|
if (QTAILQ_EMPTY(&mouse_handlers)) {
|
2010-01-13 16:05:34 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-03-10 05:52:22 +03:00
|
|
|
entry = QTAILQ_FIRST(&mouse_handlers);
|
|
|
|
|
|
|
|
mouse_event = entry->qemu_put_mouse_event;
|
|
|
|
mouse_event_opaque = entry->qemu_put_mouse_event_opaque;
|
2010-01-13 16:05:34 +03:00
|
|
|
|
|
|
|
if (mouse_event) {
|
2011-06-17 14:04:36 +04:00
|
|
|
if (entry->qemu_put_mouse_event_absolute) {
|
|
|
|
width = 0x7fff;
|
|
|
|
height = 0x7fff;
|
2011-04-09 06:11:36 +04:00
|
|
|
} else {
|
2011-06-17 14:04:36 +04:00
|
|
|
width = graphic_width - 1;
|
|
|
|
height = graphic_height - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (graphic_rotate) {
|
|
|
|
case 0:
|
|
|
|
mouse_event(mouse_event_opaque,
|
|
|
|
dx, dy, dz, buttons_state);
|
|
|
|
break;
|
|
|
|
case 90:
|
|
|
|
mouse_event(mouse_event_opaque,
|
|
|
|
width - dy, dx, dz, buttons_state);
|
|
|
|
break;
|
|
|
|
case 180:
|
|
|
|
mouse_event(mouse_event_opaque,
|
|
|
|
width - dx, height - dy, dz, buttons_state);
|
|
|
|
break;
|
|
|
|
case 270:
|
|
|
|
mouse_event(mouse_event_opaque,
|
|
|
|
dy, height - dx, dz, buttons_state);
|
|
|
|
break;
|
2011-04-09 06:11:36 +04:00
|
|
|
}
|
2010-01-13 16:05:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int kbd_mouse_is_absolute(void)
|
|
|
|
{
|
2010-03-10 05:52:22 +03:00
|
|
|
if (QTAILQ_EMPTY(&mouse_handlers)) {
|
2010-01-13 16:05:34 +03:00
|
|
|
return 0;
|
2010-03-10 05:52:22 +03:00
|
|
|
}
|
2010-01-13 16:05:34 +03:00
|
|
|
|
2010-03-10 05:52:22 +03:00
|
|
|
return QTAILQ_FIRST(&mouse_handlers)->qemu_put_mouse_event_absolute;
|
2010-01-13 16:05:34 +03:00
|
|
|
}
|
|
|
|
|
2010-03-09 23:26:40 +03:00
|
|
|
int kbd_mouse_has_absolute(void)
|
|
|
|
{
|
|
|
|
QEMUPutMouseEntry *entry;
|
|
|
|
|
|
|
|
QTAILQ_FOREACH(entry, &mouse_handlers, node) {
|
|
|
|
if (entry->qemu_put_mouse_event_absolute) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-09-21 22:29:55 +04:00
|
|
|
MouseInfoList *qmp_query_mice(Error **errp)
|
2010-01-13 16:05:34 +03:00
|
|
|
{
|
2011-09-21 22:29:55 +04:00
|
|
|
MouseInfoList *mice_list = NULL;
|
2010-01-13 16:05:34 +03:00
|
|
|
QEMUPutMouseEntry *cursor;
|
2011-09-21 22:29:55 +04:00
|
|
|
bool current = true;
|
2010-01-13 16:05:34 +03:00
|
|
|
|
2011-09-21 22:29:55 +04:00
|
|
|
QTAILQ_FOREACH(cursor, &mouse_handlers, node) {
|
|
|
|
MouseInfoList *info = g_malloc0(sizeof(*info));
|
|
|
|
info->value = g_malloc0(sizeof(*info->value));
|
|
|
|
info->value->name = g_strdup(cursor->qemu_put_mouse_event_name);
|
|
|
|
info->value->index = cursor->index;
|
|
|
|
info->value->absolute = !!cursor->qemu_put_mouse_event_absolute;
|
|
|
|
info->value->current = current;
|
2010-01-13 16:05:34 +03:00
|
|
|
|
2011-09-21 22:29:55 +04:00
|
|
|
current = false;
|
2010-03-10 05:52:22 +03:00
|
|
|
|
2011-09-21 22:29:55 +04:00
|
|
|
info->next = mice_list;
|
|
|
|
mice_list = info;
|
2010-01-13 16:05:34 +03:00
|
|
|
}
|
|
|
|
|
2011-09-21 22:29:55 +04:00
|
|
|
return mice_list;
|
2010-01-13 16:05:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void do_mouse_set(Monitor *mon, const QDict *qdict)
|
|
|
|
{
|
|
|
|
QEMUPutMouseEntry *cursor;
|
|
|
|
int index = qdict_get_int(qdict, "index");
|
2010-03-10 05:52:22 +03:00
|
|
|
int found = 0;
|
2010-01-13 16:05:34 +03:00
|
|
|
|
2010-03-10 05:52:22 +03:00
|
|
|
if (QTAILQ_EMPTY(&mouse_handlers)) {
|
2010-01-13 16:05:34 +03:00
|
|
|
monitor_printf(mon, "No mouse devices connected\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-03-10 05:52:22 +03:00
|
|
|
QTAILQ_FOREACH(cursor, &mouse_handlers, node) {
|
|
|
|
if (cursor->index == index) {
|
|
|
|
found = 1;
|
|
|
|
qemu_activate_mouse_event_handler(cursor);
|
|
|
|
break;
|
|
|
|
}
|
2010-01-13 16:05:34 +03:00
|
|
|
}
|
|
|
|
|
2010-03-10 05:52:22 +03:00
|
|
|
if (!found) {
|
2010-01-13 16:05:34 +03:00
|
|
|
monitor_printf(mon, "Mouse at given index not found\n");
|
2010-03-10 05:52:22 +03:00
|
|
|
}
|
2010-03-09 22:25:00 +03:00
|
|
|
|
|
|
|
check_mode_change();
|
|
|
|
}
|
|
|
|
|
|
|
|
void qemu_add_mouse_mode_change_notifier(Notifier *notify)
|
|
|
|
{
|
|
|
|
notifier_list_add(&mouse_mode_notifiers, notify);
|
|
|
|
}
|
|
|
|
|
|
|
|
void qemu_remove_mouse_mode_change_notifier(Notifier *notify)
|
|
|
|
{
|
2012-01-13 20:34:01 +04:00
|
|
|
notifier_remove(notify);
|
2010-01-13 16:05:34 +03:00
|
|
|
}
|