From patchwork Sat Mar 27 18:15:09 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shahar Havivi X-Patchwork-Id: 48750 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B9F1AB7CF8 for ; Sun, 28 Mar 2010 05:16:18 +1100 (EST) Received: from localhost ([127.0.0.1]:41061 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NvaYQ-0007CG-Qp for incoming@patchwork.ozlabs.org; Sat, 27 Mar 2010 14:16:14 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NvaXt-0007Bz-8m for qemu-devel@nongnu.org; Sat, 27 Mar 2010 14:15:41 -0400 Received: from [140.186.70.92] (port=50306 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NvaXr-0007Bq-UN for qemu-devel@nongnu.org; Sat, 27 Mar 2010 14:15:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NvaXp-0005eN-CB for qemu-devel@nongnu.org; Sat, 27 Mar 2010 14:15:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:1879) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NvaXp-0005eH-1V for qemu-devel@nongnu.org; Sat, 27 Mar 2010 14:15:37 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o2RIFZRP021902 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sat, 27 Mar 2010 14:15:36 -0400 Received: from localhost (dhcp-1-229.tlv.redhat.com [10.35.1.229]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o2RIFXQR029747; Sat, 27 Mar 2010 14:15:34 -0400 Date: Sat, 27 Mar 2010 21:15:09 +0300 From: Shahar Havivi To: Markus Armbruster Subject: Re: [Qemu-devel] [PATCH 2/2] Added monitor commands: 'keyboard_set' and 'info keybaord' Message-ID: <20100327181507.GA21454@redhat.com> References: <24a0619c9d6c07c5b10f5aff19478ff3040c4af8.1269373411.git.shaharh@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-08-17) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: qemu-devel@nongnu.org X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Fix to Markus comments. --- console.h | 6 +++ input.c | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++---- monitor.c | 8 ++++ qemu-monitor.hx | 17 ++++++++ 4 files changed, 141 insertions(+), 9 deletions(-) diff --git a/console.h b/console.h index 7d19407..c2af79c 100644 --- a/console.h +++ b/console.h @@ -45,6 +45,8 @@ typedef struct QEMUPutKbdEntry { char *qemu_put_kbd_name; QEMUPutKBDEvent *qemu_put_kbd_event; void *qemu_put_kbd_event_opaque; + int index; + QTAILQ_ENTRY(QEMUPutKbdEntry) entry; } QEMUPutKbdEntry; @@ -85,6 +87,10 @@ void do_info_mice_print(Monitor *mon, const QObject *data); void do_info_mice(Monitor *mon, QObject **ret_data); void do_mouse_set(Monitor *mon, const QDict *qdict); +void do_info_keyboard_print(Monitor *mon, const QObject *data); +void do_info_keyboard(Monitor *mon, QObject **ret_data); +int do_keyboard_set(Monitor *mon, const QDict *qdict, QObject **ret_data); + /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx constants) */ #define QEMU_KEY_ESC1(c) ((c) | 0xe100) diff --git a/input.c b/input.c index c27a600..2af6e9d 100644 --- a/input.c +++ b/input.c @@ -30,7 +30,6 @@ static QTAILQ_HEAD(, QEMUPutKbdEntry) kbd_handlers = QTAILQ_HEAD_INITIALIZER(kbd_handlers); -static QEMUPutKbdEntry *kbd_current; static QTAILQ_HEAD(, QEMUPutLEDEntry) led_handlers = QTAILQ_HEAD_INITIALIZER(led_handlers); static QTAILQ_HEAD(, QEMUPutMouseEntry) mouse_handlers = QTAILQ_HEAD_INITIALIZER(mouse_handlers); @@ -59,12 +58,12 @@ QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque, const char *name) { + static int mouse_index = 0; QEMUPutKbdEntry *s, *cursor; QTAILQ_FOREACH(cursor, &kbd_handlers, entry) { if (cursor->qemu_put_kbd_event == func && cursor->qemu_put_kbd_event_opaque == opaque) { - kbd_current = cursor; return cursor; } } @@ -74,9 +73,9 @@ QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, s->qemu_put_kbd_event_opaque = opaque; s->qemu_put_kbd_event = func; s->qemu_put_kbd_name = qemu_strdup(name); + s->index = mouse_index++; QTAILQ_INSERT_TAIL(&kbd_handlers, s, entry); - kbd_current = s; return s; } @@ -84,9 +83,6 @@ QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry) { QTAILQ_REMOVE(&kbd_handlers, entry, entry); - if (kbd_current == entry) { - kbd_current = QTAILQ_FIRST(&kbd_handlers); - } qemu_free(entry); } @@ -153,10 +149,14 @@ void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry) void kbd_put_keycode(int keycode) { - if (kbd_current) { - kbd_current->qemu_put_kbd_event( - kbd_current->qemu_put_kbd_event_opaque, keycode); + QEMUPutKbdEntry *entry; + + if (QTAILQ_EMPTY(&kbd_handlers)) { + return; } + + entry = QTAILQ_FIRST(&kbd_handlers); + entry->qemu_put_kbd_event(entry->qemu_put_kbd_event_opaque, keycode); } void kbd_put_ledstate(int ledstate) @@ -329,3 +329,104 @@ void qemu_remove_mouse_mode_change_notifier(Notifier *notify) { notifier_list_remove(&mouse_mode_notifiers, notify); } + +static void info_keyboard_iter(QObject *data, void *opaque) +{ + QDict *kbd; + Monitor *mon = opaque; + + kbd = qobject_to_qdict(data); + monitor_printf(mon, "%c Keyboard #%" PRId64 ": %s\n", + (qdict_get_bool(kbd, "current") ? '*' : ' '), + qdict_get_int(kbd, "index"), qdict_get_str(kbd, "name")); +} + +void do_info_keyboard_print(Monitor *mon, const QObject *data) +{ + QList *kbd_list; + + kbd_list = qobject_to_qlist(data); + if (qlist_empty(kbd_list)) { + monitor_printf(mon, "No keyboard devices connected\n"); + return; + } + + qlist_iter(kbd_list, info_keyboard_iter, mon); +} + +/* + * do_info_keyboard(): Show VM keyboard information + * + * Each keyboard is represented by a QDict, the returned QObject is + * a QList of all keyboards. + * + * The keyboard QDict contains the following: + * + * - "name": keyboard's name + * - "index": keyboard's index + * - "current": true if this keyboard is receiving events, false otherwise + * + * Example: + * + * [ { "name": "QEMU USB Keyboard", "index": 0, "current": false }, + * { "name": "QEMU PS/2 Keyboard", "index": 1, "current": true } ] + */ +void do_info_keyboard(Monitor *mon, QObject **ret_data) +{ + QEMUPutKbdEntry *cursor; + QList *kbd_list; + int current; + + kbd_list = qlist_new(); + + if (QTAILQ_EMPTY(&kbd_handlers)) { + goto out; + } + + current = QTAILQ_FIRST(&kbd_handlers)->index; + QTAILQ_FOREACH(cursor, &kbd_handlers, entry) { + QObject *obj; + obj = qobject_from_jsonf("{ 'name': %s," + " 'index': %d," + " 'current': %i }", + cursor->qemu_put_kbd_name, + cursor->index, + current == cursor->index); + qlist_append_obj(kbd_list, obj); + } +out: + *ret_data = QOBJECT(kbd_list); +} + +/* + * do_keyboard_set(): Set active keyboard + * + * Argument qdict contains + * - "index": the keyboard index to set + * + * Example: + * + * { "index": "0" } + */ +int do_keyboard_set(Monitor *mon, const QDict *qdict, QObject **ret_data) +{ + QEMUPutKbdEntry *cursor; + int index = qdict_get_int(qdict, "index"); + int found = 0; + + if (QTAILQ_EMPTY(&kbd_handlers)) { + qerror_report(QERR_DEVICE_NOT_FOUND, "keyboard"); + return -1; + } + + QTAILQ_FOREACH(cursor, &kbd_handlers, entry) { + if (cursor->index == index) { + QTAILQ_REMOVE(&kbd_handlers, cursor, entry); + QTAILQ_INSERT_HEAD(&kbd_handlers, cursor, entry); + found = 1; + break; + } + } + + return 0; +} diff --git a/monitor.c b/monitor.c index 0448a70..cc95b3d 100644 --- a/monitor.c +++ b/monitor.c @@ -2783,6 +2783,14 @@ static const mon_cmd_t info_cmds[] = { .mhandler.info_new = do_info_mice, }, { + .name = "keyboard", + .args_type = "", + .params = "", + .help = "show which guest keyboard is receiving events", + .user_print = do_info_keyboard_print, + .mhandler.info_new = do_info_keyboard, + }, + { .name = "vnc", .args_type = "", .params = "", diff --git a/qemu-monitor.hx b/qemu-monitor.hx index 5308f36..e9beb12 100644 --- a/qemu-monitor.hx +++ b/qemu-monitor.hx @@ -659,6 +659,23 @@ info mice @end example ETEXI + { + .name = "keyboard_set", + .args_type = "index:i", + .params = "index", + .help = "set which keyboard device receives events", + .mhandler.cmd_new = do_keyboard_set, + }, + +STEXI +@item keyboard_set @var{index} +@findex keyboard_set +Set which keyboard device receives events at given @var{index}, index +can be obtained with +@example +info keyboard +@end example +ETEXI #ifdef HAS_AUDIO { .name = "wavcapture",