diff mbox series

[2/2] vmmouse: use explicit code

Message ID 20230801093928.309361-2-marcandre.lureau@redhat.com
State New
Headers show
Series [1/2] vmmouse: replace DPRINTF with tracing | expand

Commit Message

Marc-André Lureau Aug. 1, 2023, 9:39 a.m. UTC
From: Marc-André Lureau <marcandre.lureau@redhat.com>

It's weird to shift x & y without obvious reason. Let's make this more
explicit and future-proof.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 hw/i386/vmmouse.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

Comments

Marc-André Lureau Sept. 11, 2023, 7:05 a.m. UTC | #1
Hi

On Tue, Aug 1, 2023 at 1:40 PM <marcandre.lureau@redhat.com> wrote:
>
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
>
> It's weird to shift x & y without obvious reason. Let's make this more
> explicit and future-proof.
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

ping

> ---
>  hw/i386/vmmouse.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/hw/i386/vmmouse.c b/hw/i386/vmmouse.c
> index fce13a5cde..cd9ac11afc 100644
> --- a/hw/i386/vmmouse.c
> +++ b/hw/i386/vmmouse.c
> @@ -46,6 +46,11 @@
>
>  #define VMMOUSE_VERSION                0x3442554a
>
> +#define VMMOUSE_MIN_X 0
> +#define VMMOUSE_MIN_Y 0
> +#define VMMOUSE_MAX_X 0xFFFF
> +#define VMMOUSE_MAX_Y 0xFFFF
> +
>  #define TYPE_VMMOUSE "vmmouse"
>  OBJECT_DECLARE_SIMPLE_TYPE(VMMouseState, VMMOUSE)
>
> @@ -106,8 +111,12 @@ static void vmmouse_mouse_event(void *opaque, int x, int y, int dz, int buttons_
>          buttons |= 0x08;
>
>      if (s->absolute) {
> -        x <<= 1;
> -        y <<= 1;
> +        x = qemu_input_scale_axis(x,
> +                                  INPUT_EVENT_ABS_MIN, INPUT_EVENT_ABS_MAX,
> +                                  VMMOUSE_MIN_X, VMMOUSE_MAX_X);
> +        y = qemu_input_scale_axis(y,
> +                                  INPUT_EVENT_ABS_MIN, INPUT_EVENT_ABS_MAX,
> +                                  VMMOUSE_MIN_Y, VMMOUSE_MAX_Y);
>      }
>
>      s->queue[s->nb_queue++] = buttons;
> --
> 2.41.0
>
>
diff mbox series

Patch

diff --git a/hw/i386/vmmouse.c b/hw/i386/vmmouse.c
index fce13a5cde..cd9ac11afc 100644
--- a/hw/i386/vmmouse.c
+++ b/hw/i386/vmmouse.c
@@ -46,6 +46,11 @@ 
 
 #define VMMOUSE_VERSION		0x3442554a
 
+#define VMMOUSE_MIN_X 0
+#define VMMOUSE_MIN_Y 0
+#define VMMOUSE_MAX_X 0xFFFF
+#define VMMOUSE_MAX_Y 0xFFFF
+
 #define TYPE_VMMOUSE "vmmouse"
 OBJECT_DECLARE_SIMPLE_TYPE(VMMouseState, VMMOUSE)
 
@@ -106,8 +111,12 @@  static void vmmouse_mouse_event(void *opaque, int x, int y, int dz, int buttons_
         buttons |= 0x08;
 
     if (s->absolute) {
-        x <<= 1;
-        y <<= 1;
+        x = qemu_input_scale_axis(x,
+                                  INPUT_EVENT_ABS_MIN, INPUT_EVENT_ABS_MAX,
+                                  VMMOUSE_MIN_X, VMMOUSE_MAX_X);
+        y = qemu_input_scale_axis(y,
+                                  INPUT_EVENT_ABS_MIN, INPUT_EVENT_ABS_MAX,
+                                  VMMOUSE_MIN_Y, VMMOUSE_MAX_Y);
     }
 
     s->queue[s->nb_queue++] = buttons;