diff options
author | Eric Blake | 2016-03-03 17:16:49 +0100 |
---|---|---|
committer | Markus Armbruster | 2016-03-05 10:41:55 +0100 |
commit | b5a1b443183f56e0b9ad0f72614bdff7ace780d5 (patch) | |
tree | 7fde6bb5891be9df92ff7ec01f1062915eed09d9 /ui | |
parent | util: Shorten references into SocketAddress (diff) | |
download | qemu-b5a1b443183f56e0b9ad0f72614bdff7ace780d5.tar.gz qemu-b5a1b443183f56e0b9ad0f72614bdff7ace780d5.tar.xz qemu-b5a1b443183f56e0b9ad0f72614bdff7ace780d5.zip |
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 'ui')
-rw-r--r-- | ui/input-legacy.c | 25 | ||||
-rw-r--r-- | ui/input.c | 54 |
2 files changed, 46 insertions, 33 deletions
diff --git a/ui/input-legacy.c b/ui/input-legacy.c index 703f0a6ed1..f1c5cb4a5e 100644 --- a/ui/input-legacy.c +++ b/ui/input-legacy.c @@ -110,12 +110,13 @@ static void legacy_kbd_event(DeviceState *dev, QemuConsole *src, { QEMUPutKbdEntry *entry = (QEMUPutKbdEntry *)dev; int scancodes[3], i, count; + InputKeyEvent *key = evt->u.key; if (!entry || !entry->put_kbd) { return; } - count = qemu_input_key_value_to_scancode(evt->u.key->key, - evt->u.key->down, + count = qemu_input_key_value_to_scancode(key->key, + key->down, scancodes); for (i = 0; i < count; i++) { entry->put_kbd(entry->opaque, scancodes[i]); @@ -150,23 +151,25 @@ static void legacy_mouse_event(DeviceState *dev, QemuConsole *src, [INPUT_BUTTON_RIGHT] = MOUSE_EVENT_RBUTTON, }; QEMUPutMouseEntry *s = (QEMUPutMouseEntry *)dev; + InputBtnEvent *btn; + InputMoveEvent *move; switch (evt->type) { case INPUT_EVENT_KIND_BTN: - if (evt->u.btn->down) { - s->buttons |= bmap[evt->u.btn->button]; + btn = evt->u.btn; + if (btn->down) { + s->buttons |= bmap[btn->button]; } else { - s->buttons &= ~bmap[evt->u.btn->button]; + s->buttons &= ~bmap[btn->button]; } - if (evt->u.btn->down && evt->u.btn->button == INPUT_BUTTON_WHEEL_UP) { + if (btn->down && btn->button == INPUT_BUTTON_WHEEL_UP) { s->qemu_put_mouse_event(s->qemu_put_mouse_event_opaque, s->axis[INPUT_AXIS_X], s->axis[INPUT_AXIS_Y], -1, s->buttons); } - if (evt->u.btn->down && - evt->u.btn->button == INPUT_BUTTON_WHEEL_DOWN) { + if (btn->down && btn->button == INPUT_BUTTON_WHEEL_DOWN) { s->qemu_put_mouse_event(s->qemu_put_mouse_event_opaque, s->axis[INPUT_AXIS_X], s->axis[INPUT_AXIS_Y], @@ -175,10 +178,12 @@ static void legacy_mouse_event(DeviceState *dev, QemuConsole *src, } break; case INPUT_EVENT_KIND_ABS: - s->axis[evt->u.abs->axis] = evt->u.abs->value; + move = evt->u.abs; + s->axis[move->axis] = move->value; break; case INPUT_EVENT_KIND_REL: - s->axis[evt->u.rel->axis] += evt->u.rel->value; + move = evt->u.rel; + s->axis[move->axis] += move->value; break; default: break; diff --git a/ui/input.c b/ui/input.c index 6fd48efb57..13ee1173cb 100644 --- a/ui/input.c +++ b/ui/input.c @@ -166,24 +166,25 @@ void qmp_input_send_event(bool has_device, const char *device, static void qemu_input_transform_abs_rotate(InputEvent *evt) { + InputMoveEvent *move = evt->u.abs; switch (graphic_rotate) { case 90: - if (evt->u.abs->axis == INPUT_AXIS_X) { - evt->u.abs->axis = INPUT_AXIS_Y; - } else if (evt->u.abs->axis == INPUT_AXIS_Y) { - evt->u.abs->axis = INPUT_AXIS_X; - evt->u.abs->value = INPUT_EVENT_ABS_SIZE - 1 - evt->u.abs->value; + if (move->axis == INPUT_AXIS_X) { + move->axis = INPUT_AXIS_Y; + } else if (move->axis == INPUT_AXIS_Y) { + move->axis = INPUT_AXIS_X; + move->value = INPUT_EVENT_ABS_SIZE - 1 - move->value; } break; case 180: - evt->u.abs->value = INPUT_EVENT_ABS_SIZE - 1 - evt->u.abs->value; + move->value = INPUT_EVENT_ABS_SIZE - 1 - move->value; break; case 270: - if (evt->u.abs->axis == INPUT_AXIS_X) { - evt->u.abs->axis = INPUT_AXIS_Y; - evt->u.abs->value = INPUT_EVENT_ABS_SIZE - 1 - evt->u.abs->value; - } else if (evt->u.abs->axis == INPUT_AXIS_Y) { - evt->u.abs->axis = INPUT_AXIS_X; + if (move->axis == INPUT_AXIS_X) { + move->axis = INPUT_AXIS_Y; + move->value = INPUT_EVENT_ABS_SIZE - 1 - move->value; + } else if (move->axis == INPUT_AXIS_Y) { + move->axis = INPUT_AXIS_X; } break; } @@ -193,22 +194,26 @@ static void qemu_input_event_trace(QemuConsole *src, InputEvent *evt) { const char *name; int qcode, idx = -1; + InputKeyEvent *key; + InputBtnEvent *btn; + InputMoveEvent *move; if (src) { idx = qemu_console_get_index(src); } switch (evt->type) { case INPUT_EVENT_KIND_KEY: - switch (evt->u.key->key->type) { + key = evt->u.key; + switch (key->key->type) { case KEY_VALUE_KIND_NUMBER: - qcode = qemu_input_key_number_to_qcode(evt->u.key->key->u.number); + qcode = qemu_input_key_number_to_qcode(key->key->u.number); name = QKeyCode_lookup[qcode]; - trace_input_event_key_number(idx, evt->u.key->key->u.number, - name, evt->u.key->down); + trace_input_event_key_number(idx, key->key->u.number, + name, key->down); break; case KEY_VALUE_KIND_QCODE: - name = QKeyCode_lookup[evt->u.key->key->u.qcode]; - trace_input_event_key_qcode(idx, name, evt->u.key->down); + name = QKeyCode_lookup[key->key->u.qcode]; + trace_input_event_key_qcode(idx, name, key->down); break; case KEY_VALUE_KIND__MAX: /* keep gcc happy */ @@ -216,16 +221,19 @@ static void qemu_input_event_trace(QemuConsole *src, InputEvent *evt) } break; case INPUT_EVENT_KIND_BTN: - name = InputButton_lookup[evt->u.btn->button]; - trace_input_event_btn(idx, name, evt->u.btn->down); + btn = evt->u.btn; + name = InputButton_lookup[btn->button]; + trace_input_event_btn(idx, name, btn->down); break; case INPUT_EVENT_KIND_REL: - name = InputAxis_lookup[evt->u.rel->axis]; - trace_input_event_rel(idx, name, evt->u.rel->value); + move = evt->u.rel; + name = InputAxis_lookup[move->axis]; + trace_input_event_rel(idx, name, move->value); break; case INPUT_EVENT_KIND_ABS: - name = InputAxis_lookup[evt->u.abs->axis]; - trace_input_event_abs(idx, name, evt->u.abs->value); + move = evt->u.abs; + name = InputAxis_lookup[move->axis]; + trace_input_event_abs(idx, name, move->value); break; case INPUT_EVENT_KIND__MAX: /* keep gcc happy */ |