diff mbox

[RFC,11/15] input: mouse: add graphic_rotate support

Message ID 1385649010-7034-12-git-send-email-kraxel@redhat.com
State New
Headers show

Commit Message

Gerd Hoffmann Nov. 28, 2013, 2:30 p.m. UTC
Transform absolute mouse events according to graphic_rotate.

Legacy input code does it for both absolute and relative events,
but the logic is broken for relative coordinates, so this is
most likely not used anyway.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 ui/input.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

Comments

John Baboval Dec. 2, 2013, 7 p.m. UTC | #1
I'm not sure this is correct. Generally when the display gets rotated, 
the input device coordinates do not, and the in-guest code handles the math.

On 11/28/2013 09:30 AM, Gerd Hoffmann wrote:
> Transform absolute mouse events according to graphic_rotate.
>
> Legacy input code does it for both absolute and relative events,
> but the logic is broken for relative coordinates, so this is
> most likely not used anyway.
>
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>   ui/input.c | 33 +++++++++++++++++++++++++++++++++
>   1 file changed, 33 insertions(+)
>
> diff --git a/ui/input.c b/ui/input.c
> index fa6d677..abfe3a3 100644
> --- a/ui/input.c
> +++ b/ui/input.c
> @@ -50,6 +50,33 @@ qemu_input_find_handler(uint32_t mask)
>       return NULL;
>   }
>   
> +static void qemu_input_transform_abs_rotate(InputEvent *evt)
> +{
> +    switch (graphic_rotate) {
> +    case 90:
> +        if (evt->abs->axis == INPUT_AXIS_X) {
> +            evt->abs->axis = INPUT_AXIS_Y;
> +        }
> +        if (evt->abs->axis == INPUT_AXIS_Y) {
> +            evt->abs->axis = INPUT_AXIS_X;
> +            evt->abs->axis = INPUT_EVENT_ABS_SIZE - 1 - evt->abs->axis;
> +        }
> +        break;
> +    case 180:
> +        evt->abs->axis = INPUT_EVENT_ABS_SIZE - 1 - evt->abs->axis;
> +        break;
> +    case 270:
> +        if (evt->abs->axis == INPUT_AXIS_X) {
> +            evt->abs->axis = INPUT_AXIS_Y;
> +            evt->abs->axis = INPUT_EVENT_ABS_SIZE - 1 - evt->abs->axis;
> +        }
> +        if (evt->abs->axis == INPUT_AXIS_Y) {
> +            evt->abs->axis = INPUT_AXIS_X;
> +        }
> +        break;
> +    }
> +}
> +
>   void qemu_input_event_send(QemuConsole *src, InputEvent *evt)
>   {
>       QemuInputHandlerState *s;
> @@ -58,6 +85,12 @@ void qemu_input_event_send(QemuConsole *src, InputEvent *evt)
>           return;
>       }
>   
> +    /* pre processing */
> +    if (graphic_rotate && (evt->kind == INPUT_EVENT_KIND_ABS)) {
> +            qemu_input_transform_abs_rotate(evt);
> +    }
> +
> +    /* send event */
>       s = qemu_input_find_handler(1 << evt->kind);
>       s->handler->event(s->dev, src, evt);
>       s->events++;
Gerd Hoffmann Dec. 3, 2013, 8:58 a.m. UTC | #2
On Mo, 2013-12-02 at 14:00 -0500, John Baboval wrote:
> I'm not sure this is correct. Generally when the display gets rotated, 
> the input device coordinates do not, and the in-guest code handles the math.

This just mimics what kbd_mouse_event() does today.  I guess there is a
reason this code was added.

I suspect it's some embedded target which depend on this stuff.
Anyone knows?

cheers,
  Gerd
diff mbox

Patch

diff --git a/ui/input.c b/ui/input.c
index fa6d677..abfe3a3 100644
--- a/ui/input.c
+++ b/ui/input.c
@@ -50,6 +50,33 @@  qemu_input_find_handler(uint32_t mask)
     return NULL;
 }
 
+static void qemu_input_transform_abs_rotate(InputEvent *evt)
+{
+    switch (graphic_rotate) {
+    case 90:
+        if (evt->abs->axis == INPUT_AXIS_X) {
+            evt->abs->axis = INPUT_AXIS_Y;
+        }
+        if (evt->abs->axis == INPUT_AXIS_Y) {
+            evt->abs->axis = INPUT_AXIS_X;
+            evt->abs->axis = INPUT_EVENT_ABS_SIZE - 1 - evt->abs->axis;
+        }
+        break;
+    case 180:
+        evt->abs->axis = INPUT_EVENT_ABS_SIZE - 1 - evt->abs->axis;
+        break;
+    case 270:
+        if (evt->abs->axis == INPUT_AXIS_X) {
+            evt->abs->axis = INPUT_AXIS_Y;
+            evt->abs->axis = INPUT_EVENT_ABS_SIZE - 1 - evt->abs->axis;
+        }
+        if (evt->abs->axis == INPUT_AXIS_Y) {
+            evt->abs->axis = INPUT_AXIS_X;
+        }
+        break;
+    }
+}
+
 void qemu_input_event_send(QemuConsole *src, InputEvent *evt)
 {
     QemuInputHandlerState *s;
@@ -58,6 +85,12 @@  void qemu_input_event_send(QemuConsole *src, InputEvent *evt)
         return;
     }
 
+    /* pre processing */
+    if (graphic_rotate && (evt->kind == INPUT_EVENT_KIND_ABS)) {
+            qemu_input_transform_abs_rotate(evt);
+    }
+
+    /* send event */
     s = qemu_input_find_handler(1 << evt->kind);
     s->handler->event(s->dev, src, evt);
     s->events++;