From: Anthony Liguori <anthony@codemonkey.ws>
To: Gerd Hoffmann <kraxel@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 9/9] spice: add tablet support
Date: Thu, 19 Aug 2010 09:40:41 -0500 [thread overview]
Message-ID: <4C6D4269.4030807@codemonkey.ws> (raw)
In-Reply-To: <1282221625-29501-10-git-send-email-kraxel@redhat.com>
On 08/19/2010 07:40 AM, Gerd Hoffmann wrote:
> 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<kraxel@redhat.com>
> ---
> spice-display.c | 2 +-
> spice-input.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++----
> 2 files changed, 93 insertions(+), 8 deletions(-)
>
> diff --git a/spice-display.c b/spice-display.c
> index 1e6d939..fec2432 100644
> --- a/spice-display.c
> +++ b/spice-display.c
> @@ -143,7 +143,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/spice-input.c b/spice-input.c
> index 8f3deb4..5646ff9 100644
> --- a/spice-input.c
> +++ b/spice-input.c
> @@ -1,5 +1,6 @@
> #include<stdlib.h>
> #include<stdio.h>
> +#include<stdbool.h>
> #include<string.h>
>
> #include<spice.h>
> @@ -48,9 +49,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 void mouse_motion(SpiceMouseInstance *sin, int dx, int dy, int dz,
> uint32_t buttons_state)
> @@ -72,17 +77,97 @@ 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);
> +
> + fprintf(stderr, "%s: %dx%d\n", __FUNCTION__, width, height);
> + 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, 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, 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, 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();
> + bool has_absolute = kbd_mouse_has_absolute();
> +
> + fprintf(stderr, "%s: absolute pointer: %s%s\n", __FUNCTION__,
> + has_absolute ? "present" : "not available",
> + is_absolute ? "+active" : "");
> +
> + if (pointer->absolute == is_absolute)
> + return;
> +
> + if (is_absolute) {
> + fprintf(stderr, "%s: using absolute pointer (client mode)\n", __FUNCTION__);
> + spice_server_add_interface(spice_server,&pointer->tablet.base);
> + } else {
> + fprintf(stderr, "%s: using relative pointer (server mode)\n", __FUNCTION__);
> + spice_server_remove_interface(&pointer->tablet.base);
> + }
> + pointer->absolute = is_absolute;
> +}
> +
>
Minus the fprintf()s and the lack of conversion of button formats, this
all looks pretty reasonable.
Regards,
Anthony Liguori
> 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);
> }
>
prev parent reply other threads:[~2010-08-19 14:40 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-19 12:40 [Qemu-devel] [PATCH 0/9] initial spice support Gerd Hoffmann
2010-08-19 12:40 ` [Qemu-devel] [PATCH 1/9] add pflib: PixelFormat conversion library Gerd Hoffmann
2010-08-19 14:04 ` Anthony Liguori
2010-08-19 15:34 ` Gerd Hoffmann
2010-08-19 19:09 ` Anthony Liguori
2010-08-20 10:38 ` Gerd Hoffmann
2010-08-19 12:40 ` [Qemu-devel] [PATCH 2/9] configure: add logging Gerd Hoffmann
2010-08-19 14:05 ` Anthony Liguori
2010-08-19 15:44 ` Gerd Hoffmann
2010-08-19 12:40 ` [Qemu-devel] [PATCH 3/9] add spice into the configure file Gerd Hoffmann
2010-08-19 14:06 ` Anthony Liguori
2010-08-19 12:40 ` [Qemu-devel] [PATCH 4/9] configure: require spice 0.5.3 Gerd Hoffmann
2010-08-19 12:40 ` [Qemu-devel] [PATCH 5/9] spice: core bits Gerd Hoffmann
2010-08-19 14:19 ` Anthony Liguori
2010-08-20 11:54 ` Gerd Hoffmann
2010-08-25 12:37 ` Gerd Hoffmann
2010-08-19 12:40 ` [Qemu-devel] [PATCH 6/9] spice: add keyboard Gerd Hoffmann
2010-08-19 14:24 ` Anthony Liguori
2010-08-20 12:34 ` Gerd Hoffmann
2010-08-20 13:18 ` Anthony Liguori
2010-08-20 13:56 ` Gerd Hoffmann
2010-08-20 14:15 ` Daniel P. Berrange
2010-08-20 14:49 ` Gerd Hoffmann
2010-08-20 15:01 ` Daniel P. Berrange
2010-08-19 12:40 ` [Qemu-devel] [PATCH 7/9] spice: add mouse Gerd Hoffmann
2010-08-19 14:25 ` Anthony Liguori
2010-08-20 12:42 ` Gerd Hoffmann
2010-08-20 13:19 ` Anthony Liguori
2010-08-20 14:03 ` Gerd Hoffmann
2010-08-20 14:37 ` Anthony Liguori
2010-08-19 12:40 ` [Qemu-devel] [PATCH 8/9] spice: simple display Gerd Hoffmann
2010-08-19 14:39 ` Anthony Liguori
2010-08-19 15:23 ` malc
2010-08-19 15:34 ` Anthony Liguori
2010-08-19 15:36 ` malc
2010-08-19 19:03 ` Anthony Liguori
2010-08-19 19:10 ` malc
2010-08-19 15:40 ` Alexander Graf
2010-08-25 11:09 ` Gerd Hoffmann
2010-08-19 16:05 ` Gerd Hoffmann
2010-08-19 19:00 ` Anthony Liguori
2010-08-19 12:40 ` [Qemu-devel] [PATCH 9/9] spice: add tablet support Gerd Hoffmann
2010-08-19 14:40 ` Anthony Liguori [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4C6D4269.4030807@codemonkey.ws \
--to=anthony@codemonkey.ws \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.