summary refs log tree commit diff stats
path: root/ui/input.c
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2013-11-28 11:29:33 +0100
committerGerd Hoffmann <kraxel@redhat.com>2014-03-05 09:52:02 +0100
commitd3535431e8006e8bf71229f306ea9c62d9e737e8 (patch)
treec46766cc97418b86b89de09e4b92285be5e2c927 /ui/input.c
parent43579403a3d67d6aab5ceb682dedae8fde85703c (diff)
downloadfocaccia-qemu-d3535431e8006e8bf71229f306ea9c62d9e737e8.tar.gz
focaccia-qemu-d3535431e8006e8bf71229f306ea9c62d9e737e8.zip
input: mouse: add graphic_rotate support
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>
Diffstat (limited to 'ui/input.c')
-rw-r--r--ui/input.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/ui/input.c b/ui/input.c
index a02172e36a..fd2293b399 100644
--- a/ui/input.c
+++ b/ui/input.c
@@ -50,6 +50,31 @@ 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;
+        } else if (evt->abs->axis == INPUT_AXIS_Y) {
+            evt->abs->axis = INPUT_AXIS_X;
+            evt->abs->value = INPUT_EVENT_ABS_SIZE - 1 - evt->abs->value;
+        }
+        break;
+    case 180:
+        evt->abs->value = INPUT_EVENT_ABS_SIZE - 1 - evt->abs->value;
+        break;
+    case 270:
+        if (evt->abs->axis == INPUT_AXIS_X) {
+            evt->abs->axis = INPUT_AXIS_Y;
+            evt->abs->value = INPUT_EVENT_ABS_SIZE - 1 - evt->abs->value;
+        } else 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 +83,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++;