From patchwork Tue Sep 21 16:51:38 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 65341 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 3248EB70CC for ; Wed, 22 Sep 2010 02:55:54 +1000 (EST) Received: from localhost ([127.0.0.1]:47050 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Oy68F-00050e-Bz for incoming@patchwork.ozlabs.org; Tue, 21 Sep 2010 12:55:51 -0400 Received: from [140.186.70.92] (port=32824 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Oy64T-0002qx-LG for qemu-devel@nongnu.org; Tue, 21 Sep 2010 12:51:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Oy64S-0000rS-Al for qemu-devel@nongnu.org; Tue, 21 Sep 2010 12:51:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37324) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Oy64S-0000rD-1t for qemu-devel@nongnu.org; Tue, 21 Sep 2010 12:51:56 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o8LGptLS007202 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 21 Sep 2010 12:51:55 -0400 Received: from rincewind.home.kraxel.org (vpn1-4-82.ams2.redhat.com [10.36.4.82]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o8LGpnxm020789; Tue, 21 Sep 2010 12:51:50 -0400 Received: by rincewind.home.kraxel.org (Postfix, from userid 500) id C259E4522C; Tue, 21 Sep 2010 18:51:42 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Tue, 21 Sep 2010 18:51:38 +0200 Message-Id: <1285087901-10232-8-git-send-email-kraxel@redhat.com> In-Reply-To: <1285087901-10232-1-git-send-email-kraxel@redhat.com> References: <1285087901-10232-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH v6 07/10] spice: add keyboard 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 Open keyboard channel. Now you can type into the spice client and the keyboard events are sent to your guest. You'll need some other display like vnc to actually see the guest responding to them though. Signed-off-by: Gerd Hoffmann --- Makefile.objs | 2 +- ui/qemu-spice.h | 1 + ui/spice-core.c | 2 + ui/spice-input.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+), 1 deletions(-) create mode 100644 ui/spice-input.c diff --git a/Makefile.objs b/Makefile.objs index 2b58109..a95106f 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -88,7 +88,7 @@ common-obj-y += pflib.o common-obj-$(CONFIG_BRLAPI) += baum.o common-obj-$(CONFIG_POSIX) += migration-exec.o migration-unix.o migration-fd.o -common-obj-$(CONFIG_SPICE) += ui/spice-core.o +common-obj-$(CONFIG_SPICE) += ui/spice-core.o ui/spice-input.o audio-obj-y = audio.o noaudio.o wavaudio.o mixeng.o audio-obj-$(CONFIG_SDL) += sdlaudio.o diff --git a/ui/qemu-spice.h b/ui/qemu-spice.h index 50faefb..175c961 100644 --- a/ui/qemu-spice.h +++ b/ui/qemu-spice.h @@ -28,6 +28,7 @@ extern int using_spice; void qemu_spice_init(void); +void qemu_spice_input_init(void); int qemu_spice_add_interface(SpiceBaseInstance *sin); #else /* CONFIG_SPICE */ diff --git a/ui/spice-core.c b/ui/spice-core.c index 006604b..8b5e4a8 100644 --- a/ui/spice-core.c +++ b/ui/spice-core.c @@ -167,6 +167,8 @@ void qemu_spice_init(void) spice_server_init(spice_server, &core_interface); using_spice = 1; + + qemu_spice_input_init(); } int qemu_spice_add_interface(SpiceBaseInstance *sin) diff --git a/ui/spice-input.c b/ui/spice-input.c new file mode 100644 index 0000000..5538a79 --- /dev/null +++ b/ui/spice-input.c @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2010 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 or + * (at your option) version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include + +#include +#include + +#include "qemu-common.h" +#include "qemu-spice.h" +#include "console.h" + +/* keyboard bits */ + +typedef struct QemuSpiceKbd { + SpiceKbdInstance sin; + int ledstate; +} QemuSpiceKbd; + +static void kbd_push_key(SpiceKbdInstance *sin, uint8_t frag); +static uint8_t kbd_get_leds(SpiceKbdInstance *sin); +static void kbd_leds(void *opaque, int l); + +static const SpiceKbdInterface kbd_interface = { + .base.type = SPICE_INTERFACE_KEYBOARD, + .base.description = "qemu keyboard", + .base.major_version = SPICE_INTERFACE_KEYBOARD_MAJOR, + .base.minor_version = SPICE_INTERFACE_KEYBOARD_MINOR, + .push_scan_freg = kbd_push_key, + .get_leds = kbd_get_leds, +}; + +static void kbd_push_key(SpiceKbdInstance *sin, uint8_t frag) +{ + kbd_put_keycode(frag); +} + +static uint8_t kbd_get_leds(SpiceKbdInstance *sin) +{ + QemuSpiceKbd *kbd = container_of(sin, QemuSpiceKbd, sin); + return kbd->ledstate; +} + +static void kbd_leds(void *opaque, int ledstate) +{ + QemuSpiceKbd *kbd = opaque; + + kbd->ledstate = 0; + if (ledstate & QEMU_SCROLL_LOCK_LED) { + kbd->ledstate |= SPICE_KEYBOARD_MODIFIER_FLAGS_SCROLL_LOCK; + } + if (ledstate & QEMU_NUM_LOCK_LED) { + kbd->ledstate |= SPICE_KEYBOARD_MODIFIER_FLAGS_NUM_LOCK; + } + if (ledstate & QEMU_CAPS_LOCK_LED) { + kbd->ledstate |= SPICE_KEYBOARD_MODIFIER_FLAGS_CAPS_LOCK; + } + spice_server_kbd_leds(&kbd->sin, ledstate); +} + +void qemu_spice_input_init(void) +{ + QemuSpiceKbd *kbd; + + kbd = qemu_mallocz(sizeof(*kbd)); + kbd->sin.base.sif = &kbd_interface.base; + qemu_spice_add_interface(&kbd->sin.base); + qemu_add_led_event_handler(kbd_leds, kbd); +}