2010-01-13 14:05:34 +01:00
|
|
|
/*
|
|
|
|
* QEMU System Emulator
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003-2008 Fabrice Bellard
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2016-01-29 18:49:51 +01:00
|
|
|
#include "qemu/osdep.h"
|
2022-01-08 16:39:47 +01:00
|
|
|
#include "qemu/log.h"
|
2018-02-11 10:36:01 +01:00
|
|
|
#include "qapi/qapi-commands-ui.h"
|
2012-11-28 12:06:30 +01:00
|
|
|
#include "ui/console.h"
|
2018-05-03 21:51:00 +02:00
|
|
|
#include "keymaps.h"
|
2013-11-27 11:59:25 +01:00
|
|
|
#include "ui/input.h"
|
2010-01-13 14:05:34 +01:00
|
|
|
|
2013-04-24 12:08:37 +02:00
|
|
|
struct QEMUPutMouseEntry {
|
|
|
|
QEMUPutMouseEvent *qemu_put_mouse_event;
|
|
|
|
void *qemu_put_mouse_event_opaque;
|
|
|
|
int qemu_put_mouse_event_absolute;
|
2013-11-27 17:41:40 +01:00
|
|
|
|
|
|
|
/* new input core */
|
|
|
|
QemuInputHandler h;
|
|
|
|
QemuInputHandlerState *s;
|
qapi: Don't let implicit enum MAX member collide
Now that we guarantee the user doesn't have any enum values
beginning with a single underscore, we can use that for our
own purposes. Renaming ENUM_MAX to ENUM__MAX makes it obvious
that the sentinel is generated.
This patch was mostly generated by applying a temporary patch:
|diff --git a/scripts/qapi.py b/scripts/qapi.py
|index e6d014b..b862ec9 100644
|--- a/scripts/qapi.py
|+++ b/scripts/qapi.py
|@@ -1570,6 +1570,7 @@ const char *const %(c_name)s_lookup[] = {
| max_index = c_enum_const(name, 'MAX', prefix)
| ret += mcgen('''
| [%(max_index)s] = NULL,
|+// %(max_index)s
| };
| ''',
| max_index=max_index)
then running:
$ cat qapi-{types,event}.c tests/test-qapi-types.c |
sed -n 's,^// \(.*\)MAX,s|\1MAX|\1_MAX|g,p' > list
$ git grep -l _MAX | xargs sed -i -f list
The only things not generated are the changes in scripts/qapi.py.
Rejecting enum members named 'MAX' is now useless, and will be dropped
in the next patch.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1447836791-369-23-git-send-email-eblake@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
[Rebased to current master, commit message tweaked]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-11-18 09:52:57 +01:00
|
|
|
int axis[INPUT_AXIS__MAX];
|
2013-11-27 17:41:40 +01:00
|
|
|
int buttons;
|
2013-04-24 12:08:37 +02:00
|
|
|
};
|
|
|
|
|
2013-04-24 12:08:38 +02:00
|
|
|
struct QEMUPutKbdEntry {
|
|
|
|
QEMUPutKBDEvent *put_kbd;
|
|
|
|
void *opaque;
|
2013-11-27 11:59:25 +01:00
|
|
|
QemuInputHandlerState *s;
|
2013-04-24 12:08:38 +02:00
|
|
|
};
|
|
|
|
|
2013-04-24 12:08:37 +02:00
|
|
|
struct QEMUPutLEDEntry {
|
|
|
|
QEMUPutLEDEvent *put_led;
|
|
|
|
void *opaque;
|
|
|
|
QTAILQ_ENTRY(QEMUPutLEDEntry) next;
|
|
|
|
};
|
|
|
|
|
2013-04-24 12:08:38 +02:00
|
|
|
static QTAILQ_HEAD(, QEMUPutLEDEntry) led_handlers =
|
|
|
|
QTAILQ_HEAD_INITIALIZER(led_handlers);
|
2010-01-13 14:05:34 +01:00
|
|
|
|
2016-01-13 09:09:58 +01:00
|
|
|
int index_from_key(const char *key, size_t key_length)
|
2012-08-31 04:56:25 +02:00
|
|
|
{
|
2012-09-20 19:47:02 +02:00
|
|
|
int i;
|
2012-08-31 04:56:25 +02:00
|
|
|
|
2017-08-24 10:46:06 +02:00
|
|
|
for (i = 0; i < Q_KEY_CODE__MAX; i++) {
|
2017-08-24 10:46:08 +02:00
|
|
|
if (!strncmp(key, QKeyCode_str(i), key_length) &&
|
|
|
|
!QKeyCode_str(i)[key_length]) {
|
2012-08-31 04:56:25 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
qapi: Don't let implicit enum MAX member collide
Now that we guarantee the user doesn't have any enum values
beginning with a single underscore, we can use that for our
own purposes. Renaming ENUM_MAX to ENUM__MAX makes it obvious
that the sentinel is generated.
This patch was mostly generated by applying a temporary patch:
|diff --git a/scripts/qapi.py b/scripts/qapi.py
|index e6d014b..b862ec9 100644
|--- a/scripts/qapi.py
|+++ b/scripts/qapi.py
|@@ -1570,6 +1570,7 @@ const char *const %(c_name)s_lookup[] = {
| max_index = c_enum_const(name, 'MAX', prefix)
| ret += mcgen('''
| [%(max_index)s] = NULL,
|+// %(max_index)s
| };
| ''',
| max_index=max_index)
then running:
$ cat qapi-{types,event}.c tests/test-qapi-types.c |
sed -n 's,^// \(.*\)MAX,s|\1MAX|\1_MAX|g,p' > list
$ git grep -l _MAX | xargs sed -i -f list
The only things not generated are the changes in scripts/qapi.py.
Rejecting enum members named 'MAX' is now useless, and will be dropped
in the next patch.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1447836791-369-23-git-send-email-eblake@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
[Rebased to current master, commit message tweaked]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-11-18 09:52:57 +01:00
|
|
|
/* Return Q_KEY_CODE__MAX if the key is invalid */
|
2012-08-31 04:56:25 +02:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2014-04-29 13:17:43 +02:00
|
|
|
static KeyValue *copy_key_value(KeyValue *src)
|
|
|
|
{
|
|
|
|
KeyValue *dst = g_new(KeyValue, 1);
|
|
|
|
memcpy(dst, src, sizeof(*src));
|
2017-10-19 16:28:41 +02:00
|
|
|
if (dst->type == KEY_VALUE_KIND_NUMBER) {
|
|
|
|
QKeyCode code = qemu_input_key_number_to_qcode(dst->u.number.data);
|
|
|
|
dst->type = KEY_VALUE_KIND_QCODE;
|
|
|
|
dst->u.qcode.data = code;
|
|
|
|
}
|
2014-04-29 13:17:43 +02:00
|
|
|
return dst;
|
2012-08-31 04:56:26 +02:00
|
|
|
}
|
|
|
|
|
2012-09-20 19:19:47 +02:00
|
|
|
void qmp_send_key(KeyValueList *keys, bool has_hold_time, int64_t hold_time,
|
2012-08-31 04:56:26 +02:00
|
|
|
Error **errp)
|
|
|
|
{
|
2012-09-20 19:19:47 +02:00
|
|
|
KeyValueList *p;
|
2014-09-26 10:02:16 +02:00
|
|
|
KeyValue **up = NULL;
|
|
|
|
int count = 0;
|
2012-08-31 04:56:26 +02:00
|
|
|
|
|
|
|
if (!has_hold_time) {
|
2014-05-28 13:03:37 +02:00
|
|
|
hold_time = 0; /* use default */
|
2012-08-31 04:56:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (p = keys; p != NULL; p = p->next) {
|
2014-04-29 13:17:43 +02:00
|
|
|
qemu_input_event_send_key(NULL, copy_key_value(p->value), true);
|
2014-05-28 13:03:37 +02:00
|
|
|
qemu_input_event_send_key_delay(hold_time);
|
2014-09-26 10:02:16 +02:00
|
|
|
up = g_realloc(up, sizeof(*up) * (count+1));
|
|
|
|
up[count] = copy_key_value(p->value);
|
|
|
|
count++;
|
2014-05-28 13:03:37 +02:00
|
|
|
}
|
2014-09-26 10:02:16 +02:00
|
|
|
while (count) {
|
|
|
|
count--;
|
|
|
|
qemu_input_event_send_key(NULL, up[count], false);
|
2014-05-28 13:03:37 +02:00
|
|
|
qemu_input_event_send_key_delay(hold_time);
|
2012-08-31 04:56:26 +02:00
|
|
|
}
|
2014-09-26 10:02:16 +02:00
|
|
|
g_free(up);
|
2012-08-31 04:56:26 +02:00
|
|
|
}
|
|
|
|
|
2013-11-27 11:59:25 +01:00
|
|
|
static void legacy_kbd_event(DeviceState *dev, QemuConsole *src,
|
|
|
|
InputEvent *evt)
|
|
|
|
{
|
|
|
|
QEMUPutKbdEntry *entry = (QEMUPutKbdEntry *)dev;
|
2014-03-11 12:15:39 +01:00
|
|
|
int scancodes[3], i, count;
|
qapi: Don't special-case simple union wrappers
Simple unions were carrying a special case that hid their 'data'
QMP member from the resulting C struct, via the hack method
QAPISchemaObjectTypeVariant.simple_union_type(). But by using
the work we started by unboxing flat union and alternate
branches, coupled with the ability to visit the members of an
implicit type, we can now expose the simple union's implicit
type in qapi-types.h:
| struct q_obj_ImageInfoSpecificQCow2_wrapper {
| ImageInfoSpecificQCow2 *data;
| };
|
| struct q_obj_ImageInfoSpecificVmdk_wrapper {
| ImageInfoSpecificVmdk *data;
| };
...
| struct ImageInfoSpecific {
| ImageInfoSpecificKind type;
| union { /* union tag is @type */
| void *data;
|- ImageInfoSpecificQCow2 *qcow2;
|- ImageInfoSpecificVmdk *vmdk;
|+ q_obj_ImageInfoSpecificQCow2_wrapper qcow2;
|+ q_obj_ImageInfoSpecificVmdk_wrapper vmdk;
| } u;
| };
Doing this removes asymmetry between QAPI's QMP side and its
C side (both sides now expose 'data'), and means that the
treatment of a simple union as sugar for a flat union is now
equivalent in both languages (previously the two approaches used
a different layer of dereferencing, where the simple union could
be converted to a flat union with equivalent C layout but
different {} on the wire, or to an equivalent QMP wire form
but with different C representation). Using the implicit type
also lets us get rid of the simple_union_type() hack.
Of course, now all clients of simple unions have to adjust from
using su->u.member to using su->u.member.data; while this touches
a number of files in the tree, some earlier cleanup patches
helped minimize the change to the initialization of a temporary
variable rather than every single member access. The generated
qapi-visit.c code is also affected by the layout change:
|@@ -7393,10 +7393,10 @@ void visit_type_ImageInfoSpecific_member
| }
| switch (obj->type) {
| case IMAGE_INFO_SPECIFIC_KIND_QCOW2:
|- visit_type_ImageInfoSpecificQCow2(v, "data", &obj->u.qcow2, &err);
|+ visit_type_q_obj_ImageInfoSpecificQCow2_wrapper_members(v, &obj->u.qcow2, &err);
| break;
| case IMAGE_INFO_SPECIFIC_KIND_VMDK:
|- visit_type_ImageInfoSpecificVmdk(v, "data", &obj->u.vmdk, &err);
|+ visit_type_q_obj_ImageInfoSpecificVmdk_wrapper_members(v, &obj->u.vmdk, &err);
| break;
| default:
| abort();
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1458254921-17042-13-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-03-17 23:48:37 +01:00
|
|
|
InputKeyEvent *key = evt->u.key.data;
|
2013-11-27 11:59:25 +01:00
|
|
|
|
|
|
|
if (!entry || !entry->put_kbd) {
|
|
|
|
return;
|
|
|
|
}
|
2016-03-03 17:16:49 +01:00
|
|
|
count = qemu_input_key_value_to_scancode(key->key,
|
|
|
|
key->down,
|
2014-03-11 12:15:39 +01:00
|
|
|
scancodes);
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
entry->put_kbd(entry->opaque, scancodes[i]);
|
2013-11-27 11:59:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static QemuInputHandler legacy_kbd_handler = {
|
|
|
|
.name = "legacy-kbd",
|
|
|
|
.mask = INPUT_EVENT_MASK_KEY,
|
|
|
|
.event = legacy_kbd_event,
|
|
|
|
};
|
|
|
|
|
2013-04-24 12:08:38 +02:00
|
|
|
QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque)
|
2010-01-13 14:05:34 +01:00
|
|
|
{
|
2013-04-24 12:08:38 +02:00
|
|
|
QEMUPutKbdEntry *entry;
|
|
|
|
|
2013-11-27 11:59:25 +01:00
|
|
|
entry = g_new0(QEMUPutKbdEntry, 1);
|
2013-04-24 12:08:38 +02:00
|
|
|
entry->put_kbd = func;
|
|
|
|
entry->opaque = opaque;
|
2013-11-27 11:59:25 +01:00
|
|
|
entry->s = qemu_input_handler_register((DeviceState *)entry,
|
|
|
|
&legacy_kbd_handler);
|
2014-03-11 14:08:31 +01:00
|
|
|
qemu_input_handler_activate(entry->s);
|
2013-04-24 12:08:38 +02:00
|
|
|
return entry;
|
2010-01-13 14:05:34 +01:00
|
|
|
}
|
|
|
|
|
2013-11-27 17:41:40 +01:00
|
|
|
static void legacy_mouse_event(DeviceState *dev, QemuConsole *src,
|
|
|
|
InputEvent *evt)
|
|
|
|
{
|
qapi: Don't let implicit enum MAX member collide
Now that we guarantee the user doesn't have any enum values
beginning with a single underscore, we can use that for our
own purposes. Renaming ENUM_MAX to ENUM__MAX makes it obvious
that the sentinel is generated.
This patch was mostly generated by applying a temporary patch:
|diff --git a/scripts/qapi.py b/scripts/qapi.py
|index e6d014b..b862ec9 100644
|--- a/scripts/qapi.py
|+++ b/scripts/qapi.py
|@@ -1570,6 +1570,7 @@ const char *const %(c_name)s_lookup[] = {
| max_index = c_enum_const(name, 'MAX', prefix)
| ret += mcgen('''
| [%(max_index)s] = NULL,
|+// %(max_index)s
| };
| ''',
| max_index=max_index)
then running:
$ cat qapi-{types,event}.c tests/test-qapi-types.c |
sed -n 's,^// \(.*\)MAX,s|\1MAX|\1_MAX|g,p' > list
$ git grep -l _MAX | xargs sed -i -f list
The only things not generated are the changes in scripts/qapi.py.
Rejecting enum members named 'MAX' is now useless, and will be dropped
in the next patch.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1447836791-369-23-git-send-email-eblake@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
[Rebased to current master, commit message tweaked]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-11-18 09:52:57 +01:00
|
|
|
static const int bmap[INPUT_BUTTON__MAX] = {
|
2013-11-27 17:41:40 +01:00
|
|
|
[INPUT_BUTTON_LEFT] = MOUSE_EVENT_LBUTTON,
|
|
|
|
[INPUT_BUTTON_MIDDLE] = MOUSE_EVENT_MBUTTON,
|
|
|
|
[INPUT_BUTTON_RIGHT] = MOUSE_EVENT_RBUTTON,
|
|
|
|
};
|
|
|
|
QEMUPutMouseEntry *s = (QEMUPutMouseEntry *)dev;
|
2016-03-03 17:16:49 +01:00
|
|
|
InputBtnEvent *btn;
|
|
|
|
InputMoveEvent *move;
|
2013-11-27 17:41:40 +01:00
|
|
|
|
2015-10-26 23:34:58 +01:00
|
|
|
switch (evt->type) {
|
2013-11-27 17:41:40 +01:00
|
|
|
case INPUT_EVENT_KIND_BTN:
|
qapi: Don't special-case simple union wrappers
Simple unions were carrying a special case that hid their 'data'
QMP member from the resulting C struct, via the hack method
QAPISchemaObjectTypeVariant.simple_union_type(). But by using
the work we started by unboxing flat union and alternate
branches, coupled with the ability to visit the members of an
implicit type, we can now expose the simple union's implicit
type in qapi-types.h:
| struct q_obj_ImageInfoSpecificQCow2_wrapper {
| ImageInfoSpecificQCow2 *data;
| };
|
| struct q_obj_ImageInfoSpecificVmdk_wrapper {
| ImageInfoSpecificVmdk *data;
| };
...
| struct ImageInfoSpecific {
| ImageInfoSpecificKind type;
| union { /* union tag is @type */
| void *data;
|- ImageInfoSpecificQCow2 *qcow2;
|- ImageInfoSpecificVmdk *vmdk;
|+ q_obj_ImageInfoSpecificQCow2_wrapper qcow2;
|+ q_obj_ImageInfoSpecificVmdk_wrapper vmdk;
| } u;
| };
Doing this removes asymmetry between QAPI's QMP side and its
C side (both sides now expose 'data'), and means that the
treatment of a simple union as sugar for a flat union is now
equivalent in both languages (previously the two approaches used
a different layer of dereferencing, where the simple union could
be converted to a flat union with equivalent C layout but
different {} on the wire, or to an equivalent QMP wire form
but with different C representation). Using the implicit type
also lets us get rid of the simple_union_type() hack.
Of course, now all clients of simple unions have to adjust from
using su->u.member to using su->u.member.data; while this touches
a number of files in the tree, some earlier cleanup patches
helped minimize the change to the initialization of a temporary
variable rather than every single member access. The generated
qapi-visit.c code is also affected by the layout change:
|@@ -7393,10 +7393,10 @@ void visit_type_ImageInfoSpecific_member
| }
| switch (obj->type) {
| case IMAGE_INFO_SPECIFIC_KIND_QCOW2:
|- visit_type_ImageInfoSpecificQCow2(v, "data", &obj->u.qcow2, &err);
|+ visit_type_q_obj_ImageInfoSpecificQCow2_wrapper_members(v, &obj->u.qcow2, &err);
| break;
| case IMAGE_INFO_SPECIFIC_KIND_VMDK:
|- visit_type_ImageInfoSpecificVmdk(v, "data", &obj->u.vmdk, &err);
|+ visit_type_q_obj_ImageInfoSpecificVmdk_wrapper_members(v, &obj->u.vmdk, &err);
| break;
| default:
| abort();
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1458254921-17042-13-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-03-17 23:48:37 +01:00
|
|
|
btn = evt->u.btn.data;
|
2016-03-03 17:16:49 +01:00
|
|
|
if (btn->down) {
|
|
|
|
s->buttons |= bmap[btn->button];
|
2013-11-27 17:41:40 +01:00
|
|
|
} else {
|
2016-03-03 17:16:49 +01:00
|
|
|
s->buttons &= ~bmap[btn->button];
|
2013-11-27 17:41:40 +01:00
|
|
|
}
|
2016-03-03 17:16:49 +01:00
|
|
|
if (btn->down && btn->button == INPUT_BUTTON_WHEEL_UP) {
|
2014-03-10 09:31:01 +01:00
|
|
|
s->qemu_put_mouse_event(s->qemu_put_mouse_event_opaque,
|
|
|
|
s->axis[INPUT_AXIS_X],
|
|
|
|
s->axis[INPUT_AXIS_Y],
|
|
|
|
-1,
|
|
|
|
s->buttons);
|
|
|
|
}
|
2016-03-03 17:16:49 +01:00
|
|
|
if (btn->down && btn->button == INPUT_BUTTON_WHEEL_DOWN) {
|
2014-03-10 09:31:01 +01:00
|
|
|
s->qemu_put_mouse_event(s->qemu_put_mouse_event_opaque,
|
|
|
|
s->axis[INPUT_AXIS_X],
|
|
|
|
s->axis[INPUT_AXIS_Y],
|
|
|
|
1,
|
|
|
|
s->buttons);
|
|
|
|
}
|
2022-01-08 16:39:47 +01:00
|
|
|
if (btn->down && btn->button == INPUT_BUTTON_WHEEL_RIGHT) {
|
|
|
|
s->qemu_put_mouse_event(s->qemu_put_mouse_event_opaque,
|
|
|
|
s->axis[INPUT_AXIS_X],
|
|
|
|
s->axis[INPUT_AXIS_Y],
|
|
|
|
-2,
|
|
|
|
s->buttons);
|
|
|
|
}
|
|
|
|
if (btn->down && btn->button == INPUT_BUTTON_WHEEL_LEFT) {
|
|
|
|
s->qemu_put_mouse_event(s->qemu_put_mouse_event_opaque,
|
|
|
|
s->axis[INPUT_AXIS_X],
|
|
|
|
s->axis[INPUT_AXIS_Y],
|
|
|
|
2,
|
|
|
|
s->buttons);
|
|
|
|
}
|
2013-11-27 17:41:40 +01:00
|
|
|
break;
|
|
|
|
case INPUT_EVENT_KIND_ABS:
|
qapi: Don't special-case simple union wrappers
Simple unions were carrying a special case that hid their 'data'
QMP member from the resulting C struct, via the hack method
QAPISchemaObjectTypeVariant.simple_union_type(). But by using
the work we started by unboxing flat union and alternate
branches, coupled with the ability to visit the members of an
implicit type, we can now expose the simple union's implicit
type in qapi-types.h:
| struct q_obj_ImageInfoSpecificQCow2_wrapper {
| ImageInfoSpecificQCow2 *data;
| };
|
| struct q_obj_ImageInfoSpecificVmdk_wrapper {
| ImageInfoSpecificVmdk *data;
| };
...
| struct ImageInfoSpecific {
| ImageInfoSpecificKind type;
| union { /* union tag is @type */
| void *data;
|- ImageInfoSpecificQCow2 *qcow2;
|- ImageInfoSpecificVmdk *vmdk;
|+ q_obj_ImageInfoSpecificQCow2_wrapper qcow2;
|+ q_obj_ImageInfoSpecificVmdk_wrapper vmdk;
| } u;
| };
Doing this removes asymmetry between QAPI's QMP side and its
C side (both sides now expose 'data'), and means that the
treatment of a simple union as sugar for a flat union is now
equivalent in both languages (previously the two approaches used
a different layer of dereferencing, where the simple union could
be converted to a flat union with equivalent C layout but
different {} on the wire, or to an equivalent QMP wire form
but with different C representation). Using the implicit type
also lets us get rid of the simple_union_type() hack.
Of course, now all clients of simple unions have to adjust from
using su->u.member to using su->u.member.data; while this touches
a number of files in the tree, some earlier cleanup patches
helped minimize the change to the initialization of a temporary
variable rather than every single member access. The generated
qapi-visit.c code is also affected by the layout change:
|@@ -7393,10 +7393,10 @@ void visit_type_ImageInfoSpecific_member
| }
| switch (obj->type) {
| case IMAGE_INFO_SPECIFIC_KIND_QCOW2:
|- visit_type_ImageInfoSpecificQCow2(v, "data", &obj->u.qcow2, &err);
|+ visit_type_q_obj_ImageInfoSpecificQCow2_wrapper_members(v, &obj->u.qcow2, &err);
| break;
| case IMAGE_INFO_SPECIFIC_KIND_VMDK:
|- visit_type_ImageInfoSpecificVmdk(v, "data", &obj->u.vmdk, &err);
|+ visit_type_q_obj_ImageInfoSpecificVmdk_wrapper_members(v, &obj->u.vmdk, &err);
| break;
| default:
| abort();
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1458254921-17042-13-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-03-17 23:48:37 +01:00
|
|
|
move = evt->u.abs.data;
|
2016-03-03 17:16:49 +01:00
|
|
|
s->axis[move->axis] = move->value;
|
2013-11-27 17:41:40 +01:00
|
|
|
break;
|
|
|
|
case INPUT_EVENT_KIND_REL:
|
qapi: Don't special-case simple union wrappers
Simple unions were carrying a special case that hid their 'data'
QMP member from the resulting C struct, via the hack method
QAPISchemaObjectTypeVariant.simple_union_type(). But by using
the work we started by unboxing flat union and alternate
branches, coupled with the ability to visit the members of an
implicit type, we can now expose the simple union's implicit
type in qapi-types.h:
| struct q_obj_ImageInfoSpecificQCow2_wrapper {
| ImageInfoSpecificQCow2 *data;
| };
|
| struct q_obj_ImageInfoSpecificVmdk_wrapper {
| ImageInfoSpecificVmdk *data;
| };
...
| struct ImageInfoSpecific {
| ImageInfoSpecificKind type;
| union { /* union tag is @type */
| void *data;
|- ImageInfoSpecificQCow2 *qcow2;
|- ImageInfoSpecificVmdk *vmdk;
|+ q_obj_ImageInfoSpecificQCow2_wrapper qcow2;
|+ q_obj_ImageInfoSpecificVmdk_wrapper vmdk;
| } u;
| };
Doing this removes asymmetry between QAPI's QMP side and its
C side (both sides now expose 'data'), and means that the
treatment of a simple union as sugar for a flat union is now
equivalent in both languages (previously the two approaches used
a different layer of dereferencing, where the simple union could
be converted to a flat union with equivalent C layout but
different {} on the wire, or to an equivalent QMP wire form
but with different C representation). Using the implicit type
also lets us get rid of the simple_union_type() hack.
Of course, now all clients of simple unions have to adjust from
using su->u.member to using su->u.member.data; while this touches
a number of files in the tree, some earlier cleanup patches
helped minimize the change to the initialization of a temporary
variable rather than every single member access. The generated
qapi-visit.c code is also affected by the layout change:
|@@ -7393,10 +7393,10 @@ void visit_type_ImageInfoSpecific_member
| }
| switch (obj->type) {
| case IMAGE_INFO_SPECIFIC_KIND_QCOW2:
|- visit_type_ImageInfoSpecificQCow2(v, "data", &obj->u.qcow2, &err);
|+ visit_type_q_obj_ImageInfoSpecificQCow2_wrapper_members(v, &obj->u.qcow2, &err);
| break;
| case IMAGE_INFO_SPECIFIC_KIND_VMDK:
|- visit_type_ImageInfoSpecificVmdk(v, "data", &obj->u.vmdk, &err);
|+ visit_type_q_obj_ImageInfoSpecificVmdk_wrapper_members(v, &obj->u.vmdk, &err);
| break;
| default:
| abort();
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1458254921-17042-13-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-03-17 23:48:37 +01:00
|
|
|
move = evt->u.rel.data;
|
2016-03-03 17:16:49 +01:00
|
|
|
s->axis[move->axis] += move->value;
|
2013-11-27 17:41:40 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-13 14:05:34 +01:00
|
|
|
QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
|
|
|
|
void *opaque, int absolute,
|
|
|
|
const char *name)
|
|
|
|
{
|
2010-03-10 03:52:22 +01:00
|
|
|
QEMUPutMouseEntry *s;
|
2010-01-13 14:05:34 +01:00
|
|
|
|
2015-11-03 17:12:03 +01:00
|
|
|
s = g_new0(QEMUPutMouseEntry, 1);
|
2010-01-13 14:05:34 +01:00
|
|
|
|
|
|
|
s->qemu_put_mouse_event = func;
|
|
|
|
s->qemu_put_mouse_event_opaque = opaque;
|
|
|
|
s->qemu_put_mouse_event_absolute = absolute;
|
|
|
|
|
2013-11-27 17:41:40 +01:00
|
|
|
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);
|
|
|
|
|
2010-01-13 14:05:34 +01:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2010-03-10 03:52:22 +01:00
|
|
|
void qemu_activate_mouse_event_handler(QEMUPutMouseEntry *entry)
|
2010-01-13 14:05:34 +01:00
|
|
|
{
|
2013-11-27 17:41:40 +01:00
|
|
|
qemu_input_handler_activate(entry->s);
|
2010-03-10 03:52:22 +01:00
|
|
|
}
|
2010-01-13 14:05:34 +01:00
|
|
|
|
2010-03-10 03:52:22 +01:00
|
|
|
void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry)
|
|
|
|
{
|
2013-11-27 17:41:40 +01:00
|
|
|
qemu_input_handler_unregister(entry->s);
|
|
|
|
|
2011-08-21 05:09:37 +02:00
|
|
|
g_free(entry);
|
2010-01-13 14:05:34 +01:00
|
|
|
}
|
|
|
|
|
2010-02-26 17:17:36 +01:00
|
|
|
QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
QEMUPutLEDEntry *s;
|
|
|
|
|
2015-11-03 17:12:03 +01:00
|
|
|
s = g_new0(QEMUPutLEDEntry, 1);
|
2010-02-26 17:17:36 +01:00
|
|
|
|
|
|
|
s->put_led = func;
|
|
|
|
s->opaque = opaque;
|
|
|
|
QTAILQ_INSERT_TAIL(&led_handlers, s, next);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry)
|
|
|
|
{
|
|
|
|
if (entry == NULL)
|
|
|
|
return;
|
|
|
|
QTAILQ_REMOVE(&led_handlers, entry, next);
|
2011-08-21 05:09:37 +02:00
|
|
|
g_free(entry);
|
2010-02-26 17:17:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void kbd_put_ledstate(int ledstate)
|
|
|
|
{
|
|
|
|
QEMUPutLEDEntry *cursor;
|
|
|
|
|
|
|
|
QTAILQ_FOREACH(cursor, &led_handlers, next) {
|
|
|
|
cursor->put_led(cursor->opaque, ledstate);
|
|
|
|
}
|
|
|
|
}
|