Skip to contentSkip to conversation

input: rewrite qemu input layer

RFC PATCH In review Gerd Hoffmann 3 participants 21 messages Nov 28, 2013 – Dec 3, 2013

lore
Share & tools
lore
#0 lore raw

cover input: rewrite qemu input layer

Hi,

This patch series is the first draft of a input layer rewrite. New core code is largely in place. There is some windup for the legacy functions, to keep things working while switching over users one by one.

Some ui code is converted to make clear how the new input layer should be used.

No work on the device emulation side of things yet.

Main motivation for this is multihead support. Thats why QemuConsole is passed everythere, even though the code doesn't use it (yet). But some day the input layer has the should be able to process/route events depending on the source.

Easy monitor integration is on the radar too, even though none if this is coded up yet. I wanna test the data structures more before even thinking about exposing them via qmp.

In general the new way of handling events should more flexible and be easier to extend than the old code we have right now. We might want add touch support for example ...

Reviews? Comments?

cheers,
Gerd

Gerd Hoffmann (15):
console: export QemuConsole index,width,height
input: rename file to legacy
input: define event types using qapi
input: add core bits of the new input layer
input: keyboard: add helper functions to core
input: keyboard: switch legacy handlers to new core
input: keyboard: switch qmp_send_key() to new core.
input: keyboard: switch gtk ui to new core
input: keyboard: switch sdl ui to new core [wip]
input: mouse: add helpers functions to core
input: mouse: add graphic_rotate support
input: mouse: add qemu_input_is_absolute()
input: mouse: switch legacy handlers to new core
input: mouse: switch gtk ui to new core
input: mouse: switch sdl ui to new core

 include/ui/console.h |   3 +
 include/ui/input.h   |  50 ++++
 qapi-schema.json     |  29 +++
 ui/Makefile.objs     |   2 +-
 ui/console.c         |  24 ++
 ui/gtk.c             |  77 ++----
 ui/input-legacy.c    | 650 +++++++++++++++++++++++++++++++++++++++++++++++++++
 ui/input.c           | 627 +++++++++++--------------------------------------
 ui/sdl.c             |  88 +++----
 9 files changed, 965 insertions(+), 585 deletions(-)
 create mode 100644 include/ui/input.h
 create mode 100644 ui/input-legacy.c
Signature · 1 line
1.8.3.1
#1 lore raw

RFC PATCH 1/15 console: export QemuConsole index, width, height

Add functions to query QemuConsole properties.

---
 include/ui/console.h |  3 +++
 ui/console.c         | 24 ++++++++++++++++++++++++
 2 files changed, 27 insertions(+)
include/ui/console.h +3 -0
index 98edf41..09138e5 100644
@@ -290,6 +290,9 @@ QemuConsole *qemu_console_lookup_by_device(DeviceState *dev);
 bool qemu_console_is_visible(QemuConsole *con);
 bool qemu_console_is_graphic(QemuConsole *con);
 bool qemu_console_is_fixedsize(QemuConsole *con);
+int qemu_console_get_index(QemuConsole *con);
+int qemu_console_get_width(QemuConsole *con, int fallback);
+int qemu_console_get_height(QemuConsole *con, int fallback);
 
 void text_consoles_set_display(DisplayState *ds);
 void console_select(unsigned int index);
ui/console.c +24 -0
index 199ba69..8d054cd 100644
@@ -1645,6 +1645,30 @@ bool qemu_console_is_fixedsize(QemuConsole *con)
     return con && (con->console_type != TEXT_CONSOLE);
 }
 
+int qemu_console_get_index(QemuConsole *con)
+{
+    if (con == NULL) {
+        con = active_console;
+    }
+    return con ? con->index : -1;
+}
+
+int qemu_console_get_width(QemuConsole *con, int fallback)
+{
+    if (con == NULL) {
+        con = active_console;
+    }
+    return con ? surface_width(con->surface) : fallback;
+}
+
+int qemu_console_get_height(QemuConsole *con, int fallback)
+{
+    if (con == NULL) {
+        con = active_console;
+    }
+    return con ? surface_height(con->surface) : fallback;
+}
+
 static void text_console_set_echo(CharDriverState *chr, bool echo)
 {
     QemuConsole *s = chr->opaque;
Signature · 1 line
1.8.3.1
#2 lore raw

RFC PATCH 2/15 input: rename file to legacy

In reply to Gerd Hoffmann

Rename ui/input.c to ui/input-legacy.c.
We are going to replace it step by step.

---
 ui/Makefile.objs               | 2 +-
 ui/{input.c => input-legacy.c} | 0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename ui/{input.c => input-legacy.c} (100%)
ui/Makefile.objs +1 -1
index f33be47..39ceadc 100644
@@ -7,7 +7,7 @@ vnc-obj-$(CONFIG_VNC_SASL) += vnc-auth-sasl.o
 vnc-obj-$(CONFIG_VNC_WS) += vnc-ws.o
 vnc-obj-y += vnc-jobs.o
 
-common-obj-y += keymaps.o console.o cursor.o input.o qemu-pixman.o
+common-obj-y += keymaps.o console.o cursor.o input-legacy.o qemu-pixman.o
 common-obj-$(CONFIG_SPICE) += spice-core.o spice-input.o spice-display.o
 common-obj-$(CONFIG_SDL) += sdl.o sdl_zoom.o x_keymap.o
 common-obj-$(CONFIG_COCOA) += cocoa.o
ui/input-legacy.c renamed from ui/input.c +0 -0
similarity index 100%
rename from ui/input.c
rename to ui/input-legacy.c
Signature · 1 line
1.8.3.1
#3 lore raw

RFC PATCH 3/15 input: define event types using qapi

In reply to Gerd Hoffmann

Define input event types, using qapi. So we get nicely autogenerated types for our input events. And when it comes to qmp support some day things will be alot easier.

Types are modeled after the linux input layer. There are separate event types for each value. There is a sync to indicate the end of a event group.

Mouse events are splitted into motion events (one for each axis) and button events, which are grouped by sync.

Keyboard events are using keycodes instead of scancodes, so we can rid of the keycode->scancode transformation everywhere in the ui code.

---
 qapi-schema.json | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
qapi-schema.json +29 -0
index 83fa485..c27c49d 100644
@@ -4213,3 +4213,32 @@
 # Since: 1.7
 ##
 { 'command': 'blockdev-add', 'data': { 'options': 'BlockdevOptions' } }
+
+
+###########################################################
+# WIP - input event data structures
+# not exposed via qmp yet, needs testing first
+
+{ 'enum'  : 'InputButton',
+  'data'  : [ 'Left', 'Middle', 'Right' ] }
+
+{ 'enum'  : 'InputAxis',
+  'data'  : [ 'X', 'Y' ] }
+
+{ 'type'  : 'InputKeyEvent',
+  'data'  : { 'keycode' : 'int',
+              'down'    : 'bool' } }
+
+{ 'type'  : 'InputBtnEvent',
+  'data'  : { 'button'  : 'InputButton',
+              'down'    : 'bool' } }
+
+{ 'type'  : 'InputMoveEvent',
+  'data'  : { 'axis'    : 'InputAxis',
+              'value'   : 'int' } }
+
+{ 'union' : 'InputEvent',
+  'data'  : { 'key'     : 'InputKeyEvent',
+              'btn'     : 'InputBtnEvent',
+              'rel'     : 'InputMoveEvent',
+              'abs'     : 'InputMoveEvent' } }
Signature · 1 line
1.8.3.1
#4 lore raw

Re: [Qemu-devel] [RFC PATCH 03/15] input: define event types using qapi

Quoted 9 lines · Gerd Hoffmann

Define input event types, using qapi. So we get nicely autogenerated types for our input events. And when it comes to qmp support some day things will be alot easier.

Types are modeled after the linux input layer. There are separate event types for each value. There is a sync to indicate the end of a event group.

Mouse events are splitted into motion events (one for each axis) and

s/splitted/split/ (yes, one of those stupid English words whose past-tense spelling is the same as its present tense)

Quoted 11 lines

button events, which are grouped by sync.

Keyboard events are using keycodes instead of scancodes, so we can rid of the keycode->scancode transformation everywhere in the ui code.

---
 qapi-schema.json | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

qapi-schema.json line 4220

Quoted 5 lines
qapi-schema.json +5 -0
+
+
+###########################################################
+# WIP - input event data structures
+# not exposed via qmp yet, needs testing first

But still worth documenting, and adding "Since 2.0" annotations to each enum and struct.

Quoted 25 lines
qapi-schema.json +24 -0
+
+{ 'enum'  : 'InputButton',
+  'data'  : [ 'Left', 'Middle', 'Right' ] }
+
+{ 'enum'  : 'InputAxis',
+  'data'  : [ 'X', 'Y' ] }
+
+{ 'type'  : 'InputKeyEvent',
+  'data'  : { 'keycode' : 'int',
+              'down'    : 'bool' } }
+
+{ 'type'  : 'InputBtnEvent',
+  'data'  : { 'button'  : 'InputButton',
+              'down'    : 'bool' } }
+
+{ 'type'  : 'InputMoveEvent',
+  'data'  : { 'axis'    : 'InputAxis',
+              'value'   : 'int' } }
+
+{ 'union' : 'InputEvent',
+  'data'  : { 'key'     : 'InputKeyEvent',
+              'btn'     : 'InputBtnEvent',
+              'rel'     : 'InputMoveEvent',
+              'abs'     : 'InputMoveEvent' } }
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#5 lore raw

Re: [Qemu-devel] [RFC PATCH 03/15] input: define event types using qapi

Quoted 5 lines · Eric Blake
Quoted 4 lines · Gerd Hoffmann

Define input event types, using qapi. So we get nicely autogenerated types for our input events. And when it comes to qmp support some day things will be alot easier.

Quoted 8 lines
Quoted 5 lines

Types are modeled after the linux input layer. There are separate event types for each value. There is a sync to indicate the end of a event group.

Mouse events are splitted into motion events (one for each axis) and

s/splitted/split/ (yes, one of those stupid English words whose past-tense spelling is the same as its present tense)

Thanks for the explanation. That hopefully makes it a bit easier to remember.

Quoted 6 lines

qapi-schema.json line 4220

Quoted 3 lines
qapi-schema.json +3 -0
+###########################################################
+# WIP - input event data structures
+# not exposed via qmp yet, needs testing first

But still worth documenting, and adding "Since 2.0" annotations to each enum and struct.

Sure, already on the todo list for the final patch version.

cheers,
Gerd

#6 lore raw

RFC PATCH 4/15 input: add core bits of the new input layer

In reply to Gerd Hoffmann

Register and unregister handlers.
Event dispatcher code.

---
 include/ui/input.h | 32 +++++++++++++++++++++
 ui/Makefile.objs   |  2 +-
 ui/input.c         | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 116 insertions(+), 1 deletion(-)
 create mode 100644 include/ui/input.h
 create mode 100644 ui/input.c
include/ui/input.h new file +32 -0
new file mode 100644
index 0000000..3cf3641
@@ -0,0 +1,32 @@
+#ifndef INPUT_H
+#define INPUT_H
+
+#include "qapi-types.h"
+
+#define INPUT_EVENT_MASK_KEY   (1<<INPUT_EVENT_KIND_KEY)
+#define INPUT_EVENT_MASK_BTN   (1<<INPUT_EVENT_KIND_BTN)
+#define INPUT_EVENT_MASK_REL   (1<<INPUT_EVENT_KIND_REL)
+#define INPUT_EVENT_MASK_ABS   (1<<INPUT_EVENT_KIND_ABS)
+
+typedef struct QemuInputHandler QemuInputHandler;
+typedef struct QemuInputHandlerState QemuInputHandlerState;
+
+typedef void (*QemuInputHandlerEvent)(DeviceState *dev, QemuConsole *src,
+                                      InputEvent *evt);
+typedef void (*QemuInputHandlerSync)(DeviceState *dev);
+
+struct QemuInputHandler {
+    const char             *name;
+    uint32_t               mask;
+    QemuInputHandlerEvent  event;
+    QemuInputHandlerSync   sync;
+};
+
+QemuInputHandlerState *qemu_input_handler_register(DeviceState *dev,
+                                                   QemuInputHandler *handler);
+void qemu_input_handler_activate(QemuInputHandlerState *s);
+void qemu_input_handler_unregister(QemuInputHandlerState *s);
+void qemu_input_event_send(QemuConsole *src, InputEvent *evt);
+void qemu_input_event_sync(void);
+
+#endif /* INPUT_H */
ui/Makefile.objs +1 -1
index 39ceadc..27af551 100644
@@ -7,7 +7,7 @@ vnc-obj-$(CONFIG_VNC_SASL) += vnc-auth-sasl.o
 vnc-obj-$(CONFIG_VNC_WS) += vnc-ws.o
 vnc-obj-y += vnc-jobs.o
 
-common-obj-y += keymaps.o console.o cursor.o input-legacy.o qemu-pixman.o
+common-obj-y += keymaps.o console.o cursor.o input.o input-legacy.o qemu-pixman.o
 common-obj-$(CONFIG_SPICE) += spice-core.o spice-input.o spice-display.o
 common-obj-$(CONFIG_SDL) += sdl.o sdl_zoom.o x_keymap.o
 common-obj-$(CONFIG_COCOA) += cocoa.o
ui/input.c new file +83 -0

83 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#7 lore raw

RFC PATCH 5/15 input: keyboard: add helper functions to core

In reply to Gerd Hoffmann

A bunch of helper functions to manage keyboard events, to make life simpler for the ui code when submitting keyboard events.

---
 include/ui/input.h |  3 +++
 ui/input.c         | 19 +++++++++++++++++++
 2 files changed, 22 insertions(+)
include/ui/input.h +3 -0
index 3cf3641..12a964c 100644
@@ -29,4 +29,7 @@ void qemu_input_handler_unregister(QemuInputHandlerState *s);
 void qemu_input_event_send(QemuConsole *src, InputEvent *evt);
 void qemu_input_event_sync(void);
 
+InputEvent *qemu_input_event_new_key(int keycode, bool down);
+void qemu_input_event_send_key(QemuConsole *src, int keycode, bool down);
+
 #endif /* INPUT_H */
ui/input.c +19 -0
index 23c84f7..284bd1f 100644
@@ -81,3 +81,22 @@ void qemu_input_event_sync(void)
         s->events = 0;
     }
 }
+
+InputEvent *qemu_input_event_new_key(int keycode, bool down)
+{
+    InputEvent *evt = g_new0(InputEvent, 1);
+    evt->key = g_new0(InputKeyEvent, 1);
+    evt->kind = INPUT_EVENT_KIND_KEY;
+    evt->key->keycode = keycode;
+    evt->key->down = down;
+    return evt;
+}
+
+void qemu_input_event_send_key(QemuConsole *src, int keycode, bool down)
+{
+    InputEvent *evt;
+    evt = qemu_input_event_new_key(keycode, down);
+    qemu_input_event_send(src, evt);
+    qemu_input_event_sync();
+    qapi_free_InputEvent(evt);
+}
Signature · 1 line
1.8.3.1
#8 lore raw

RFC PATCH 6/15 input: keyboard: switch legacy handlers to new core

In reply to Gerd Hoffmann

legacy kbd event handlers are registered in the new core, so they receive events from the new input core code. keycode -> scancode translation needed here.

legacy kbd_put_keycode() sends events to the new core. scancode -> keycode translation needed here.

So with this patch the new input core is fully functional for keyboard events. New + legacy interfaces can be mixed in any way.

---
 ui/input-legacy.c | 54 ++++++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 44 insertions(+), 10 deletions(-)
ui/input-legacy.c +44 -10
index 10d8c05..0163a46 100644
@@ -29,6 +29,7 @@
 #include "qmp-commands.h"
 #include "qapi-types.h"
 #include "ui/keymaps.h"
+#include "ui/input.h"
 
 struct QEMUPutMouseEntry {
     QEMUPutMouseEvent *qemu_put_mouse_event;
@@ -45,7 +46,7 @@ struct QEMUPutMouseEntry {
 struct QEMUPutKbdEntry {
     QEMUPutKBDEvent *put_kbd;
     void *opaque;
-    QTAILQ_ENTRY(QEMUPutKbdEntry) next;
+    QemuInputHandlerState *s;
 };
 
 struct QEMUPutLEDEntry {
@@ -56,8 +57,6 @@ struct QEMUPutLEDEntry {
 
 static QTAILQ_HEAD(, QEMUPutLEDEntry) led_handlers =
     QTAILQ_HEAD_INITIALIZER(led_handlers);
-static QTAILQ_HEAD(, QEMUPutKbdEntry) kbd_handlers =
-    QTAILQ_HEAD_INITIALIZER(kbd_handlers);
 static QTAILQ_HEAD(, QEMUPutMouseEntry) mouse_handlers =
     QTAILQ_HEAD_INITIALIZER(mouse_handlers);
 static NotifierList mouse_mode_notifiers =
@@ -312,20 +311,44 @@ void qmp_send_key(KeyValueList *keys, bool has_hold_time, int64_t hold_time,
                    muldiv64(get_ticks_per_sec(), hold_time, 1000));
 }
 
+static void legacy_kbd_event(DeviceState *dev, QemuConsole *src,
+                             InputEvent *evt)
+{
+    QEMUPutKbdEntry *entry = (QEMUPutKbdEntry *)dev;
+    int keycode = evt->key->keycode;
+
+    if (keycode & SCANCODE_GREY) {
+        entry->put_kbd(entry->opaque, SCANCODE_EMUL0);
+        keycode &= ~SCANCODE_GREY;
+    }
+    if (!evt->key->down) {
+        keycode |= SCANCODE_UP;
+    }
+    entry->put_kbd(entry->opaque, keycode);
+}
+
+static QemuInputHandler legacy_kbd_handler = {
+    .name  = "legacy-kbd",
+    .mask  = INPUT_EVENT_MASK_KEY,
+    .event = legacy_kbd_event,
+};
+
 QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque)
 {
     QEMUPutKbdEntry *entry;
 
-    entry = g_malloc0(sizeof(QEMUPutKbdEntry));
+    entry = g_new0(QEMUPutKbdEntry, 1);
     entry->put_kbd = func;
     entry->opaque = opaque;
-    QTAILQ_INSERT_HEAD(&kbd_handlers, entry, next);
+    entry->s = qemu_input_handler_register((DeviceState *)entry,
+                                           &legacy_kbd_handler);
     return entry;
 }
 
 void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry)
 {
-    QTAILQ_REMOVE(&kbd_handlers, entry, next);
+    qemu_input_handler_unregister(entry->s);
+    g_free(entry);
 }
 
 static void check_mode_change(void)
@@ -409,14 +432,25 @@ void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry)
 
 void kbd_put_keycode(int keycode)
 {
-    QEMUPutKbdEntry *entry = QTAILQ_FIRST(&kbd_handlers);
+    static bool emul0;
+    bool up;
 
-    if (!runstate_is_running() && !runstate_check(RUN_STATE_SUSPENDED)) {
+    if (keycode == SCANCODE_EMUL0) {
+        emul0 = true;
         return;
     }
-    if (entry) {
-        entry->put_kbd(entry->opaque, keycode);
+    if (keycode & SCANCODE_UP) {
+        keycode &= ~SCANCODE_UP;
+        up = true;
+    } else {
+        up = false;
+    }
+    if (emul0) {
+        keycode |= SCANCODE_GREY;
+        emul0 = false;
     }
+
+    qemu_input_event_send_key(NULL, keycode, !up);
 }
 
 void kbd_put_ledstate(int ledstate)
Signature · 1 line
1.8.3.1
#9 lore raw

RFC PATCH 7/15 input: keyboard: switch qmp_send_key() to new core.

In reply to Gerd Hoffmann
---
 ui/input-legacy.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
ui/input-legacy.c +2 -8
index 0163a46..d7dd880 100644
@@ -260,10 +260,7 @@ static void free_keycodes(void)
 static void release_keys(void *opaque)
 {
     while (keycodes_size > 0) {
-        if (keycodes[--keycodes_size] & SCANCODE_GREY) {
-            kbd_put_keycode(SCANCODE_EMUL0);
-        }
-        kbd_put_keycode(keycodes[keycodes_size] | SCANCODE_UP);
+        qemu_input_event_send_key(NULL, keycodes[--keycodes_size], false);
     }
 
     free_keycodes();
@@ -297,10 +294,7 @@ void qmp_send_key(KeyValueList *keys, bool has_hold_time, int64_t hold_time,
             return;
         }
 
-        if (keycode & SCANCODE_GREY) {
-            kbd_put_keycode(SCANCODE_EMUL0);
-        }
-        kbd_put_keycode(keycode & SCANCODE_KEYCODEMASK);
+        qemu_input_event_send_key(NULL, keycode, true);
 
         keycodes = g_realloc(keycodes, sizeof(int) * (keycodes_size + 1));
         keycodes[keycodes_size++] = keycode;
Signature · 1 line
1.8.3.1
#10 lore raw

RFC PATCH 8/15 input: keyboard: switch gtk ui to new core

In reply to Gerd Hoffmann
---
 ui/gtk.c | 19 ++++---------------
 1 file changed, 4 insertions(+), 15 deletions(-)
ui/gtk.c +4 -15
index b5f4f0b..3a97b36 100644
@@ -54,6 +54,7 @@
 #include <math.h>
 
 #include "ui/console.h"
+#include "ui/input.h"
 #include "sysemu/sysemu.h"
 #include "qmp-commands.h"
 #include "x_keymap.h"
@@ -283,10 +284,7 @@ static void gtk_release_modifiers(GtkDisplayState *s)
         if (!s->modifier_pressed[i]) {
             continue;
         }
-        if (keycode & SCANCODE_GREY) {
-            kbd_put_keycode(SCANCODE_EMUL0);
-        }
-        kbd_put_keycode(keycode | SCANCODE_UP);
+        qemu_input_event_send_key(s->dcl.con, keycode, false);
         s->modifier_pressed[i] = false;
     }
 }
@@ -742,17 +740,8 @@ static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque)
         }
     }
 
-    if (qemu_keycode & SCANCODE_GREY) {
-        kbd_put_keycode(SCANCODE_EMUL0);
-    }
-
-    if (key->type == GDK_KEY_PRESS) {
-        kbd_put_keycode(qemu_keycode & SCANCODE_KEYCODEMASK);
-    } else if (key->type == GDK_KEY_RELEASE) {
-        kbd_put_keycode(qemu_keycode | SCANCODE_UP);
-    } else {
-        g_assert_not_reached();
-    }
+    qemu_input_event_send_key(s->dcl.con, qemu_keycode,
+                              key->type == GDK_KEY_PRESS);
 
     return TRUE;
 }
Signature · 1 line
1.8.3.1
#11 lore raw

RFC PATCH 9/15 input: keyboard: switch sdl ui to new core [wip]

In reply to Gerd Hoffmann

FIXME: pause key not handled yet.

---
 ui/sdl.c | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)
ui/sdl.c +10 -13
index 9d8583c..1b1224a 100644
@@ -30,6 +30,7 @@
 
 #include "qemu-common.h"
 #include "ui/console.h"
+#include "ui/input.h"
 #include "sysemu/sysemu.h"
 #include "x_keymap.h"
 #include "sdl_zoom.h"
@@ -261,9 +262,7 @@ static void reset_keys(void)
     int i;
     for(i = 0; i < 256; i++) {
         if (modifiers_state[i]) {
-            if (i & SCANCODE_GREY)
-                kbd_put_keycode(SCANCODE_EMUL0);
-            kbd_put_keycode(i | SCANCODE_UP);
+            qemu_input_event_send_key(dcl->con, i, false);
             modifiers_state[i] = 0;
         }
     }
@@ -271,11 +270,12 @@ static void reset_keys(void)
 
 static void sdl_process_key(SDL_KeyboardEvent *ev)
 {
-    int keycode, v;
+    int keycode;
 
+#if 0
     if (ev->keysym.sym == SDLK_PAUSE) {
         /* specific case */
-        v = 0;
+        int v = 0;
         if (ev->type == SDL_KEYUP)
             v |= SCANCODE_UP;
         kbd_put_keycode(0xe1);
@@ -283,6 +283,7 @@ static void sdl_process_key(SDL_KeyboardEvent *ev)
         kbd_put_keycode(0x45 | v);
         return;
     }
+#endif
 
     if (kbd_layout) {
         keycode = sdl_keyevent_to_keycode_generic(ev);
@@ -312,19 +313,15 @@ static void sdl_process_key(SDL_KeyboardEvent *ev)
     case 0x45: /* num lock */
     case 0x3a: /* caps lock */
         /* SDL does not send the key up event, so we generate it */
-        kbd_put_keycode(keycode);
-        kbd_put_keycode(keycode | SCANCODE_UP);
+        qemu_input_event_send_key(dcl->con, keycode, true);
+        qemu_input_event_send_key(dcl->con, keycode, false);
         return;
 #endif
     }
 
     /* now send the key code */
-    if (keycode & SCANCODE_GREY)
-        kbd_put_keycode(SCANCODE_EMUL0);
-    if (ev->type == SDL_KEYUP)
-        kbd_put_keycode(keycode | SCANCODE_UP);
-    else
-        kbd_put_keycode(keycode & SCANCODE_KEYCODEMASK);
+    qemu_input_event_send_key(dcl->con, keycode,
+                              ev->type == SDL_KEYDOWN);
 }
 
 static void sdl_update_caption(void)
Signature · 1 line
1.8.3.1
#12 lore raw

RFC PATCH 10/15 input: mouse: add helpers functions to core

In reply to Gerd Hoffmann

Likewise a bunch of helper functions to manage mouse button and movement events, again to make life easier for the ui code.

---
 include/ui/input.h | 14 +++++++++++
 ui/input.c         | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 85 insertions(+)
include/ui/input.h +14 -0
index 12a964c..0d79342 100644
@@ -8,6 +8,8 @@
 #define INPUT_EVENT_MASK_REL   (1<<INPUT_EVENT_KIND_REL)
 #define INPUT_EVENT_MASK_ABS   (1<<INPUT_EVENT_KIND_ABS)
 
+#define INPUT_EVENT_ABS_SIZE   0x8000
+
 typedef struct QemuInputHandler QemuInputHandler;
 typedef struct QemuInputHandlerState QemuInputHandlerState;
 
@@ -32,4 +34,16 @@ void qemu_input_event_sync(void);
 InputEvent *qemu_input_event_new_key(int keycode, bool down);
 void qemu_input_event_send_key(QemuConsole *src, int keycode, bool down);
 
+InputEvent *qemu_input_event_new_btn(InputButton btn, bool down);
+void qemu_input_queue_btn(QemuConsole *src, InputButton btn, bool down);
+void qemu_input_update_buttons(QemuConsole *src, uint32_t *button_map,
+                               uint32_t button_old, uint32_t button_new);
+
+int qemu_input_scale_axis(int value, int size_in, int size_out);
+InputEvent *qemu_input_event_new_move(InputEventKind kind,
+                                      InputAxis axis, int value);
+void qemu_input_queue_rel(QemuConsole *src, InputAxis axis, int value);
+void qemu_input_queue_abs(QemuConsole *src, InputAxis axis,
+                          int value, int size);
+
 #endif /* INPUT_H */
ui/input.c +71 -0

74 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#13 lore raw

RFC PATCH 11/15 input: mouse: add graphic_rotate support

In reply to Gerd Hoffmann

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.

---
 ui/input.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
ui/input.c +33 -0
index fa6d677..abfe3a3 100644
@@ -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++;
Signature · 1 line
1.8.3.1
#14 lore raw

Re: [Qemu-devel] [RFC PATCH 11/15] input: mouse: add graphic_rotate support

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.

Quoted 62 lines · Gerd Hoffmann

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.

---
  ui/input.c | 33 +++++++++++++++++++++++++++++++++
  1 file changed, 33 insertions(+)
ui/input.c +33 -0
index fa6d677..abfe3a3 100644
@@ -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++;
#15 lore raw

Re: [Qemu-devel] [RFC PATCH 11/15] input: mouse: add graphic_rotate support

Quoted 2 lines · John Baboval

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

#16 lore raw

RFC PATCH 12/15 input: mouse: add qemu_input_is_absolute()

In reply to Gerd Hoffmann

Same as kbd_mouse_is_absolute(), but using new input core.

---
 include/ui/input.h | 1 +
 ui/input.c         | 8 ++++++++
 2 files changed, 9 insertions(+)
include/ui/input.h +1 -0
index 0d79342..43b9afc 100644
@@ -39,6 +39,7 @@ void qemu_input_queue_btn(QemuConsole *src, InputButton btn, bool down);
 void qemu_input_update_buttons(QemuConsole *src, uint32_t *button_map,
                                uint32_t button_old, uint32_t button_new);
 
+bool qemu_input_is_absolute(void);
 int qemu_input_scale_axis(int value, int size_in, int size_out);
 InputEvent *qemu_input_event_new_move(InputEventKind kind,
                                       InputAxis axis, int value);
ui/input.c +8 -0
index abfe3a3..719c427 100644
@@ -167,6 +167,14 @@ void qemu_input_update_buttons(QemuConsole *src, uint32_t *button_map,
     }
 }
 
+bool qemu_input_is_absolute(void)
+{
+    QemuInputHandlerState *s;
+
+    s = qemu_input_find_handler(INPUT_EVENT_MASK_REL | INPUT_EVENT_MASK_ABS);
+    return (s != NULL) && (s->handler->mask & INPUT_EVENT_MASK_ABS);
+}
+
 int qemu_input_scale_axis(int value, int size_in, int size_out)
 {
     if (size_in < 2) {
Signature · 1 line
1.8.3.1
#17 lore raw

Re: [Qemu-devel] [RFC PATCH 12/15] input: mouse: add qemu_input_is_absolute()

Perhaps this should just return the mask instead of a boolean? It would be nice at some point to handle a USB HID style device that can send both relative and absolute events, for example.

Though perhaps that would be better as future work, since this is a nice drop-in replacement for the old call.

Quoted 39 lines · Gerd Hoffmann

Same as kbd_mouse_is_absolute(), but using new input core.

---
  include/ui/input.h | 1 +
  ui/input.c         | 8 ++++++++
  2 files changed, 9 insertions(+)
include/ui/input.h +1 -0
index 0d79342..43b9afc 100644
@@ -39,6 +39,7 @@ void qemu_input_queue_btn(QemuConsole *src, InputButton btn, bool down);
  void qemu_input_update_buttons(QemuConsole *src, uint32_t *button_map,
                                 uint32_t button_old, uint32_t button_new);
 
+bool qemu_input_is_absolute(void);
  int qemu_input_scale_axis(int value, int size_in, int size_out);
  InputEvent *qemu_input_event_new_move(InputEventKind kind,
                                        InputAxis axis, int value);
ui/input.c +8 -0
index abfe3a3..719c427 100644
@@ -167,6 +167,14 @@ void qemu_input_update_buttons(QemuConsole *src, uint32_t *button_map,
      }
  }
 
+bool qemu_input_is_absolute(void)
+{
+    QemuInputHandlerState *s;
+
+    s = qemu_input_find_handler(INPUT_EVENT_MASK_REL | INPUT_EVENT_MASK_ABS);
+    return (s != NULL) && (s->handler->mask & INPUT_EVENT_MASK_ABS);
+}
+
  int qemu_input_scale_axis(int value, int size_in, int size_out)
  {
      if (size_in < 2) {
#18 lore raw

RFC PATCH 13/15 input: mouse: switch legacy handlers to new core

In reply to Gerd Hoffmann

legacy mouse event handlers are registered in the new core, so they receive events submitted to the new input core.

legacy kbd_mouse_event() continues to use the old code paths. So new-core event handlers wouldn't see events submitted via kbd_mouse_event.

This leads to the constrain that we we must transition all kbd_mouse_event() users first to keep things working. But that is easier to handle than translating legacy mouse events into new-core mouse events ;)

---
 ui/input-legacy.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)
ui/input-legacy.c +63 -0
index d7dd880..323a66c 100644
@@ -41,6 +41,12 @@ struct QEMUPutMouseEntry {
 
     /* used internally by qemu for handling mice */
     QTAILQ_ENTRY(QEMUPutMouseEntry) node;
+
+    /* new input core */
+    QemuInputHandler h;
+    QemuInputHandlerState *s;
+    int axis[INPUT_AXIS_MAX];
+    int buttons;
 };
 
 struct QEMUPutKbdEntry {
@@ -363,6 +369,51 @@ static void check_mode_change(void)
     current_has_absolute = has_absolute;
 }
 
+static void legacy_mouse_event(DeviceState *dev, QemuConsole *src,
+                               InputEvent *evt)
+{
+    static const int bmap[INPUT_BUTTON_MAX] = {
+        [INPUT_BUTTON_LEFT]   = MOUSE_EVENT_LBUTTON,
+        [INPUT_BUTTON_MIDDLE] = MOUSE_EVENT_MBUTTON,
+        [INPUT_BUTTON_RIGHT]  = MOUSE_EVENT_RBUTTON,
+    };
+    QEMUPutMouseEntry *s = (QEMUPutMouseEntry *)dev;
+
+    switch (evt->kind) {
+    case INPUT_EVENT_KIND_BTN:
+        if (evt->btn->down) {
+            s->buttons |= bmap[evt->btn->button];
+        } else {
+            s->buttons &= ~bmap[evt->btn->button];
+        }
+        break;
+    case INPUT_EVENT_KIND_ABS:
+        s->axis[evt->abs->axis] = evt->abs->value;
+        break;
+    case INPUT_EVENT_KIND_REL:
+        s->axis[evt->rel->axis] += evt->rel->value;
+        break;
+    default:
+        break;
+    }
+}
+
+static void legacy_mouse_sync(DeviceState *dev)
+{
+    QEMUPutMouseEntry *s = (QEMUPutMouseEntry *)dev;
+
+    s->qemu_put_mouse_event(s->qemu_put_mouse_event_opaque,
+                            s->axis[INPUT_AXIS_X],
+                            s->axis[INPUT_AXIS_Y],
+                            0,
+                            s->buttons);
+
+    if (!s->qemu_put_mouse_event_absolute) {
+        s->axis[INPUT_AXIS_X] = 0;
+        s->axis[INPUT_AXIS_Y] = 0;
+    }
+}
+
 QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
                                                 void *opaque, int absolute,
                                                 const char *name)
@@ -380,6 +431,14 @@ QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
 
     QTAILQ_INSERT_TAIL(&mouse_handlers, s, node);
 
+    s->h.name = name;
+    s->h.mask = INPUT_EVENT_MASK_BTN |
+        (absolute ? INPUT_EVENT_MASK_ABS : INPUT_EVENT_MASK_REL);
+    s->h.event = legacy_mouse_event;
+    s->h.sync = legacy_mouse_sync;
+    s->s = qemu_input_handler_register((DeviceState *)s,
+                                       &s->h);
+
     check_mode_change();
 
     return s;
@@ -390,6 +449,8 @@ void qemu_activate_mouse_event_handler(QEMUPutMouseEntry *entry)
     QTAILQ_REMOVE(&mouse_handlers, entry, node);
     QTAILQ_INSERT_HEAD(&mouse_handlers, entry, node);
 
+    qemu_input_handler_activate(entry->s);
+
     check_mode_change();
 }
 
@@ -397,6 +458,8 @@ void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry)
 {
     QTAILQ_REMOVE(&mouse_handlers, entry, node);
 
+    qemu_input_handler_unregister(entry->s);
+
     g_free(entry->qemu_put_mouse_event_name);
     g_free(entry);
 
Signature · 1 line
1.8.3.1
#19 lore raw

RFC PATCH 14/15 input: mouse: switch gtk ui to new core

In reply to Gerd Hoffmann
---
 ui/gtk.c | 58 +++++++++++++++++++---------------------------------------
 1 file changed, 19 insertions(+), 39 deletions(-)
ui/gtk.c +19 -39
index 3a97b36..3c37d2e 100644
@@ -197,7 +197,7 @@ static void gd_update_cursor(GtkDisplayState *s, gboolean override)
     on_vga = gd_on_vga(s);
 
     if ((override || on_vga) &&
-        (s->full_screen || kbd_mouse_is_absolute() || gd_is_grab_active(s))) {
+        (s->full_screen || qemu_input_is_absolute() || gd_is_grab_active(s))) {
         gdk_window_set_cursor(window, s->null_cursor);
     } else {
         gdk_window_set_cursor(window, NULL);
@@ -584,7 +584,6 @@ static gboolean gd_motion_event(GtkWidget *widget, GdkEventMotion *motion,
                                 void *opaque)
 {
     GtkDisplayState *s = opaque;
-    int dx, dy;
     int x, y;
     int mx, my;
     int fbh, fbw;
@@ -612,25 +611,21 @@ static gboolean gd_motion_event(GtkWidget *widget, GdkEventMotion *motion,
         return TRUE;
     }
 
-    if (kbd_mouse_is_absolute()) {
-        dx = x * 0x7FFF / (surface_width(s->ds) - 1);
-        dy = y * 0x7FFF / (surface_height(s->ds) - 1);
-    } else if (s->last_x == -1 || s->last_y == -1) {
-        dx = 0;
-        dy = 0;
-    } else {
-        dx = x - s->last_x;
-        dy = y - s->last_y;
+    if (qemu_input_is_absolute()) {
+        qemu_input_queue_abs(s->dcl.con, INPUT_AXIS_X, x,
+                             surface_width(s->ds));
+        qemu_input_queue_abs(s->dcl.con, INPUT_AXIS_Y, y,
+                             surface_height(s->ds));
+        qemu_input_event_sync();
+    } else if (s->last_x != -1 && s->last_y != -1 && gd_is_grab_active(s)) {
+        qemu_input_queue_rel(s->dcl.con, INPUT_AXIS_X, x - s->last_x);
+        qemu_input_queue_rel(s->dcl.con, INPUT_AXIS_Y, y - s->last_y);
+        qemu_input_event_sync();
     }
-
     s->last_x = x;
     s->last_y = y;
 
-    if (kbd_mouse_is_absolute() || gd_is_grab_active(s)) {
-        kbd_mouse_event(dx, dy, 0, s->button_mask);
-    }
-
-    if (!kbd_mouse_is_absolute() && gd_is_grab_active(s)) {
+    if (!qemu_input_is_absolute() && gd_is_grab_active(s)) {
         GdkScreen *screen = gtk_widget_get_screen(s->drawing_area);
         int x = (int)motion->x_root;
         int y = (int)motion->y_root;
@@ -675,35 +670,20 @@ static gboolean gd_button_event(GtkWidget *widget, GdkEventButton *button,
                                 void *opaque)
 {
     GtkDisplayState *s = opaque;
-    int dx, dy;
-    int n;
+    InputButton btn;
 
     if (button->button == 1) {
-        n = 0x01;
+        btn = INPUT_BUTTON_LEFT;
     } else if (button->button == 2) {
-        n = 0x04;
+        btn = INPUT_BUTTON_MIDDLE;
     } else if (button->button == 3) {
-        n = 0x02;
-    } else {
-        n = 0x00;
-    }
-
-    if (button->type == GDK_BUTTON_PRESS) {
-        s->button_mask |= n;
-    } else if (button->type == GDK_BUTTON_RELEASE) {
-        s->button_mask &= ~n;
-    }
-
-    if (kbd_mouse_is_absolute()) {
-        dx = s->last_x * 0x7FFF / (surface_width(s->ds) - 1);
-        dy = s->last_y * 0x7FFF / (surface_height(s->ds) - 1);
+        btn = INPUT_BUTTON_RIGHT;
     } else {
-        dx = 0;
-        dy = 0;
+        return TRUE;
     }
 
-    kbd_mouse_event(dx, dy, 0, s->button_mask);
-        
+    qemu_input_queue_btn(s->dcl.con, btn, button->type == GDK_BUTTON_PRESS);
+    qemu_input_event_sync();
     return TRUE;
 }
 
Signature · 1 line
1.8.3.1
#20 lore raw

RFC PATCH 15/15 input: mouse: switch sdl ui to new core

In reply to Gerd Hoffmann
---
 ui/sdl.c | 65 +++++++++++++++++++++++++++++++++-------------------------------
 1 file changed, 34 insertions(+), 31 deletions(-)
ui/sdl.c +34 -31
index 1b1224a..13076e3 100644
@@ -357,7 +357,7 @@ static void sdl_hide_cursor(void)
     if (!cursor_hide)
         return;
 
-    if (kbd_mouse_is_absolute()) {
+    if (qemu_input_is_absolute()) {
         SDL_ShowCursor(1);
         SDL_SetCursor(sdl_cursor_hidden);
     } else {
@@ -370,10 +370,10 @@ static void sdl_show_cursor(void)
     if (!cursor_hide)
         return;
 
-    if (!kbd_mouse_is_absolute() || !qemu_console_is_graphic(NULL)) {
+    if (!qemu_input_is_absolute() || !qemu_console_is_graphic(NULL)) {
         SDL_ShowCursor(1);
         if (guest_cursor &&
-                (gui_grab || kbd_mouse_is_absolute() || absolute_enabled))
+                (gui_grab || qemu_input_is_absolute() || absolute_enabled))
             SDL_SetCursor(guest_sprite);
         else
             SDL_SetCursor(sdl_cursor_normal);
@@ -392,8 +392,9 @@ static void sdl_grab_start(void)
     }
     if (guest_cursor) {
         SDL_SetCursor(guest_sprite);
-        if (!kbd_mouse_is_absolute() && !absolute_enabled)
+        if (!qemu_input_is_absolute() && !absolute_enabled) {
             SDL_WarpMouse(guest_x, guest_y);
+        }
     } else
         sdl_hide_cursor();
     SDL_WM_GrabInput(SDL_GRAB_ON);
@@ -422,7 +423,7 @@ static void absolute_mouse_grab(void)
 
 static void sdl_mouse_mode_change(Notifier *notify, void *data)
 {
-    if (kbd_mouse_is_absolute()) {
+    if (qemu_input_is_absolute()) {
         if (!absolute_enabled) {
             absolute_enabled = 1;
             if (qemu_console_is_graphic(NULL)) {
@@ -439,31 +440,32 @@ static void sdl_mouse_mode_change(Notifier *notify, void *data)
 
 static void sdl_send_mouse_event(int dx, int dy, int dz, int x, int y, int state)
 {
-    int buttons = 0;
-
-    if (state & SDL_BUTTON(SDL_BUTTON_LEFT)) {
-        buttons |= MOUSE_EVENT_LBUTTON;
-    }
-    if (state & SDL_BUTTON(SDL_BUTTON_RIGHT)) {
-        buttons |= MOUSE_EVENT_RBUTTON;
-    }
-    if (state & SDL_BUTTON(SDL_BUTTON_MIDDLE)) {
-        buttons |= MOUSE_EVENT_MBUTTON;
-    }
-
-    if (kbd_mouse_is_absolute()) {
-        dx = x * 0x7FFF / (real_screen->w - 1);
-        dy = y * 0x7FFF / (real_screen->h - 1);
+    static uint32_t bmap[INPUT_BUTTON_MAX] = {
+        [INPUT_BUTTON_LEFT]   = SDL_BUTTON(SDL_BUTTON_LEFT),
+        [INPUT_BUTTON_MIDDLE] = SDL_BUTTON(SDL_BUTTON_MIDDLE),
+        [INPUT_BUTTON_RIGHT]  = SDL_BUTTON(SDL_BUTTON_RIGHT),
+    };
+    static uint32_t prev_state;
+
+    if (prev_state != state) {
+        qemu_input_update_buttons(dcl->con, bmap, prev_state, state);
+        prev_state = state;
+    }
+
+    if (qemu_input_is_absolute()) {
+        qemu_input_queue_abs(dcl->con, INPUT_AXIS_X, x,
+                             real_screen->w);
+        qemu_input_queue_abs(dcl->con, INPUT_AXIS_Y, y,
+                             real_screen->h);
     } else if (guest_cursor) {
         x -= guest_x;
         y -= guest_y;
         guest_x += x;
         guest_y += y;
-        dx = x;
-        dy = y;
+        qemu_input_queue_rel(dcl->con, INPUT_AXIS_X, x);
+        qemu_input_queue_rel(dcl->con, INPUT_AXIS_Y, y);
     }
-
-    kbd_mouse_event(dx, dy, dz, buttons);
+    qemu_input_event_sync();
 }
 
 static void sdl_scale(int width, int height)
@@ -691,7 +693,7 @@ static void handle_mousemotion(SDL_Event *ev)
     int max_x, max_y;
 
     if (qemu_console_is_graphic(NULL) &&
-        (kbd_mouse_is_absolute() || absolute_enabled)) {
+        (qemu_input_is_absolute() || absolute_enabled)) {
         max_x = real_screen->w - 1;
         max_y = real_screen->h - 1;
         if (gui_grab && (ev->motion.x == 0 || ev->motion.y == 0 ||
@@ -704,7 +706,7 @@ static void handle_mousemotion(SDL_Event *ev)
             sdl_grab_start();
         }
     }
-    if (gui_grab || kbd_mouse_is_absolute() || absolute_enabled) {
+    if (gui_grab || qemu_input_is_absolute() || absolute_enabled) {
         sdl_send_mouse_event(ev->motion.xrel, ev->motion.yrel, 0,
                              ev->motion.x, ev->motion.y, ev->motion.state);
     }
@@ -721,7 +723,7 @@ static void handle_mousebutton(SDL_Event *ev)
     }
 
     bev = &ev->button;
-    if (!gui_grab && !kbd_mouse_is_absolute()) {
+    if (!gui_grab && !qemu_input_is_absolute()) {
         if (ev->type == SDL_MOUSEBUTTONUP && bev->button == SDL_BUTTON_LEFT) {
             /* start grabbing all events */
             sdl_grab_start();
@@ -757,7 +759,7 @@ static void handle_activation(SDL_Event *ev)
     }
 #endif
     if (!gui_grab && ev->active.gain && qemu_console_is_graphic(NULL) &&
-        (kbd_mouse_is_absolute() || absolute_enabled)) {
+        (qemu_input_is_absolute() || absolute_enabled)) {
         absolute_mouse_grab();
     }
     if (ev->active.state & SDL_APPACTIVE) {
@@ -829,10 +831,11 @@ static void sdl_mouse_warp(DisplayChangeListener *dcl,
     if (on) {
         if (!guest_cursor)
             sdl_show_cursor();
-        if (gui_grab || kbd_mouse_is_absolute() || absolute_enabled) {
+        if (gui_grab || qemu_input_is_absolute() || absolute_enabled) {
             SDL_SetCursor(guest_sprite);
-            if (!kbd_mouse_is_absolute() && !absolute_enabled)
+            if (!qemu_input_is_absolute() && !absolute_enabled) {
                 SDL_WarpMouse(x, y);
+            }
         }
     } else if (gui_grab)
         sdl_hide_cursor();
@@ -860,7 +863,7 @@ static void sdl_mouse_define(DisplayChangeListener *dcl,
     g_free(mask);
 
     if (guest_cursor &&
-            (gui_grab || kbd_mouse_is_absolute() || absolute_enabled))
+            (gui_grab || qemu_input_is_absolute() || absolute_enabled))
         SDL_SetCursor(guest_sprite);
 }
 
Signature · 1 line
1.8.3.1