summaryrefslogtreecommitdiffstats
path: root/hw/input/virtio-input-hid.c
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2016-03-03 09:16:49 -0700
committerTimothy Pearson <tpearson@raptorengineering.com>2019-11-29 19:49:12 -0600
commit705341301bafc5ae3dc947b9217c7a763e52f5b6 (patch)
tree14c812f89fcb0c583225b8cf32b999a379356dc1 /hw/input/virtio-input-hid.c
parent6bfa9411dc89d590dee8dcdc1e689d5dc48de76c (diff)
downloadhqemu-705341301bafc5ae3dc947b9217c7a763e52f5b6.zip
hqemu-705341301bafc5ae3dc947b9217c7a763e52f5b6.tar.gz
ui: Shorten references into InputEvent
An upcoming patch will alter how simple unions, like InputEvent, are laid out, which will impact all lines of the form 'evt->u.XXX' (expanding it to the longer 'evt->u.XXX.data'). For better legibility in that patch, and less need for line wrapping, it's better to use a temporary variable to reduce the effect of a layout change to just the variable initializations, rather than every reference within an InputEvent. There was one instance in hid.c:hid_pointer_event() where the code was referring to evt->u.rel inside the case label where evt->u.abs is the correct name; thankfully, both members of the union have the same type, so it happened to work, but it is now cleaner. Signed-off-by: Eric Blake <eblake@redhat.com> Message-Id: <1457021813-10704-8-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'hw/input/virtio-input-hid.c')
-rw-r--r--hw/input/virtio-input-hid.c33
1 files changed, 20 insertions, 13 deletions
diff --git a/hw/input/virtio-input-hid.c b/hw/input/virtio-input-hid.c
index 9ca5395..e5480c3 100644
--- a/hw/input/virtio-input-hid.c
+++ b/hw/input/virtio-input-hid.c
@@ -191,46 +191,53 @@ static void virtio_input_handle_event(DeviceState *dev, QemuConsole *src,
VirtIOInput *vinput = VIRTIO_INPUT(dev);
virtio_input_event event;
int qcode;
+ InputKeyEvent *key;
+ InputMoveEvent *move;
+ InputBtnEvent *btn;
switch (evt->type) {
case INPUT_EVENT_KIND_KEY:
- qcode = qemu_input_key_value_to_qcode(evt->u.key->key);
+ key = evt->u.key;
+ qcode = qemu_input_key_value_to_qcode(key->key);
if (qcode && keymap_qcode[qcode]) {
event.type = cpu_to_le16(EV_KEY);
event.code = cpu_to_le16(keymap_qcode[qcode]);
- event.value = cpu_to_le32(evt->u.key->down ? 1 : 0);
+ event.value = cpu_to_le32(key->down ? 1 : 0);
virtio_input_send(vinput, &event);
} else {
- if (evt->u.key->down) {
+ if (key->down) {
fprintf(stderr, "%s: unmapped key: %d [%s]\n", __func__,
qcode, QKeyCode_lookup[qcode]);
}
}
break;
case INPUT_EVENT_KIND_BTN:
- if (keymap_button[evt->u.btn->button]) {
+ btn = evt->u.btn;
+ if (keymap_button[btn->button]) {
event.type = cpu_to_le16(EV_KEY);
- event.code = cpu_to_le16(keymap_button[evt->u.btn->button]);
- event.value = cpu_to_le32(evt->u.btn->down ? 1 : 0);
+ event.code = cpu_to_le16(keymap_button[btn->button]);
+ event.value = cpu_to_le32(btn->down ? 1 : 0);
virtio_input_send(vinput, &event);
} else {
- if (evt->u.btn->down) {
+ if (btn->down) {
fprintf(stderr, "%s: unmapped button: %d [%s]\n", __func__,
- evt->u.btn->button,
- InputButton_lookup[evt->u.btn->button]);
+ btn->button,
+ InputButton_lookup[btn->button]);
}
}
break;
case INPUT_EVENT_KIND_REL:
+ move = evt->u.rel;
event.type = cpu_to_le16(EV_REL);
- event.code = cpu_to_le16(axismap_rel[evt->u.rel->axis]);
- event.value = cpu_to_le32(evt->u.rel->value);
+ event.code = cpu_to_le16(axismap_rel[move->axis]);
+ event.value = cpu_to_le32(move->value);
virtio_input_send(vinput, &event);
break;
case INPUT_EVENT_KIND_ABS:
+ move = evt->u.abs;
event.type = cpu_to_le16(EV_ABS);
- event.code = cpu_to_le16(axismap_abs[evt->u.abs->axis]);
- event.value = cpu_to_le32(evt->u.abs->value);
+ event.code = cpu_to_le16(axismap_abs[move->axis]);
+ event.value = cpu_to_le32(move->value);
virtio_input_send(vinput, &event);
break;
default:
OpenPOWER on IntegriCloud