From patchwork Wed Aug 25 14:19:30 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 62688 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 5070DB70CD for ; Thu, 26 Aug 2010 00:36:23 +1000 (EST) Received: from localhost ([127.0.0.1]:45084 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OoH0y-0004Wu-Tb for incoming@patchwork.ozlabs.org; Wed, 25 Aug 2010 10:31:45 -0400 Received: from [140.186.70.92] (port=37832 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OoGpN-0005t1-Ao for qemu-devel@nongnu.org; Wed, 25 Aug 2010 10:19:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OoGpL-0008IT-2x for qemu-devel@nongnu.org; Wed, 25 Aug 2010 10:19:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:11757) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OoGpK-0008Ex-Su for qemu-devel@nongnu.org; Wed, 25 Aug 2010 10:19:43 -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 o7PEJgoq003925 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 25 Aug 2010 10:19:42 -0400 Received: from rincewind.home.kraxel.org (vpn1-5-126.ams2.redhat.com [10.36.5.126]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o7PEJaP2021064; Wed, 25 Aug 2010 10:19:36 -0400 Received: by rincewind.home.kraxel.org (Postfix, from userid 500) id 0889340859; Wed, 25 Aug 2010 16:19:31 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Wed, 25 Aug 2010 16:19:30 +0200 Message-Id: <1282745970-11506-11-git-send-email-kraxel@redhat.com> In-Reply-To: <1282745970-11506-1-git-send-email-kraxel@redhat.com> References: <1282745970-11506-1-git-send-email-kraxel@redhat.com> 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: Gerd Hoffmann Subject: [Qemu-devel] [PATCH v3 10/10] spice: add tablet support 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 Add support for the spice tablet interface. The tablet interface will be registered (and then used by the spice client) as soon as a absolute pointing device is available and used by the guest, i.e. you'll have to configure your guest with '-usbdevice tablet'. Signed-off-by: Gerd Hoffmann --- ui/spice-display.c | 2 +- ui/spice-input.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 85 insertions(+), 8 deletions(-) diff --git a/ui/spice-display.c b/ui/spice-display.c index 7163714..6b17be7 100644 --- a/ui/spice-display.c +++ b/ui/spice-display.c @@ -166,7 +166,7 @@ void qemu_spice_create_host_primary(SimpleSpiceDisplay *ssd) surface.width = ds_get_width(ssd->ds); surface.height = ds_get_height(ssd->ds); surface.stride = -surface.width * 4; - surface.mouse_mode = 0; + surface.mouse_mode = true; surface.flags = 0; surface.type = 0; surface.mem = (intptr_t)ssd->buf; diff --git a/ui/spice-input.c b/ui/spice-input.c index 130760d..7cc5aa8 100644 --- a/ui/spice-input.c +++ b/ui/spice-input.c @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -73,9 +74,13 @@ static void kbd_leds(void *opaque, int ledstate) /* mouse bits */ -typedef struct QemuSpiceMouse { - SpiceMouseInstance sin; -} QemuSpiceMouse; +typedef struct QemuSpicePointer { + SpiceMouseInstance mouse; + SpiceTabletInstance tablet; + int width, height, x, y; + Notifier mouse_mode; + bool absolute; +} QemuSpicePointer; static int map_buttons(int spice_buttons) { @@ -110,17 +115,89 @@ static const SpiceMouseInterface mouse_interface = { .buttons = mouse_buttons, }; +static void tablet_set_logical_size(SpiceTabletInstance* sin, int width, int height) +{ + QemuSpicePointer *pointer = container_of(sin, QemuSpicePointer, tablet); + + if (height < 16) + height = 16; + if (width < 16) + width = 16; + pointer->width = width; + pointer->height = height; +} + +static void tablet_position(SpiceTabletInstance* sin, int x, int y, + uint32_t buttons_state) +{ + QemuSpicePointer *pointer = container_of(sin, QemuSpicePointer, tablet); + + pointer->x = x * 0x7FFF / (pointer->width - 1); + pointer->y = y * 0x7FFF / (pointer->height - 1); + kbd_mouse_event(pointer->x, pointer->y, 0, map_buttons(buttons_state)); +} + + +static void tablet_wheel(SpiceTabletInstance* sin, int wheel, + uint32_t buttons_state) +{ + QemuSpicePointer *pointer = container_of(sin, QemuSpicePointer, tablet); + + kbd_mouse_event(pointer->x, pointer->y, wheel, map_buttons(buttons_state)); +} + +static void tablet_buttons(SpiceTabletInstance *sin, + uint32_t buttons_state) +{ + QemuSpicePointer *pointer = container_of(sin, QemuSpicePointer, tablet); + + kbd_mouse_event(pointer->x, pointer->y, 0, map_buttons(buttons_state)); +} + +static const SpiceTabletInterface tablet_interface = { + .base.type = SPICE_INTERFACE_TABLET, + .base.description = "tablet", + .base.major_version = SPICE_INTERFACE_TABLET_MAJOR, + .base.minor_version = SPICE_INTERFACE_TABLET_MINOR, + .set_logical_size = tablet_set_logical_size, + .position = tablet_position, + .wheel = tablet_wheel, + .buttons = tablet_buttons, +}; + +static void mouse_mode_notifier(Notifier *notifier) +{ + QemuSpicePointer *pointer = container_of(notifier, QemuSpicePointer, mouse_mode); + bool is_absolute = kbd_mouse_is_absolute(); + + if (pointer->absolute == is_absolute) + return; + + if (is_absolute) { + spice_server_add_interface(spice_server, &pointer->tablet.base); + } else { + spice_server_remove_interface(&pointer->tablet.base); + } + pointer->absolute = is_absolute; +} + void qemu_spice_input_init(void) { QemuSpiceKbd *kbd; - QemuSpiceMouse *mouse; + QemuSpicePointer *pointer; kbd = qemu_mallocz(sizeof(*kbd)); kbd->sin.base.sif = &kbd_interface.base; spice_server_add_interface(spice_server, &kbd->sin.base); qemu_add_led_event_handler(kbd_leds, kbd); - mouse = qemu_mallocz(sizeof(*mouse)); - mouse->sin.base.sif = &mouse_interface.base; - spice_server_add_interface(spice_server, &mouse->sin.base); + pointer = qemu_mallocz(sizeof(*pointer)); + pointer->mouse.base.sif = &mouse_interface.base; + pointer->tablet.base.sif = &tablet_interface.base; + spice_server_add_interface(spice_server, &pointer->mouse.base); + + pointer->absolute = false; + pointer->mouse_mode.notify = mouse_mode_notifier; + qemu_add_mouse_mode_change_notifier(&pointer->mouse_mode); + mouse_mode_notifier(&pointer->mouse_mode); }