[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 12/15] input: qmp_send_key(): simplify
From: |
Luiz Capitulino |
Subject: |
[Qemu-devel] [PULL 12/15] input: qmp_send_key(): simplify |
Date: |
Thu, 27 Sep 2012 10:28:26 -0300 |
The current code duplicates the QKeyCodeList keys in order to store
the key values for release_keys() late run. This is a bit complicated
though, as we have to care about correct ordering and then release_keys()
will have to index key_defs[] over again.
Switch to an array of integers, which is dynamically allocated and stores
the already converted key value.
This simplifies the current code and the next commit.
Signed-off-by: Luiz Capitulino <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Reviewed-by: Markus Armbruster <address@hidden>
---
input.c | 36 ++++++++++++++----------------------
1 file changed, 14 insertions(+), 22 deletions(-)
diff --git a/input.c b/input.c
index c4b0619..32c6057 100644
--- a/input.c
+++ b/input.c
@@ -224,30 +224,31 @@ int index_from_keycode(int code)
return i;
}
-static QKeyCodeList *keycodes;
+static int *keycodes;
+static int keycodes_size;
static QEMUTimer *key_timer;
static void release_keys(void *opaque)
{
- int keycode;
- QKeyCodeList *p;
+ int i;
- for (p = keycodes; p != NULL; p = p->next) {
- keycode = key_defs[p->value];
- if (keycode & 0x80) {
+ for (i = 0; i < keycodes_size; i++) {
+ if (keycodes[i] & 0x80) {
kbd_put_keycode(0xe0);
}
- kbd_put_keycode(keycode | 0x80);
+ kbd_put_keycode(keycodes[i]| 0x80);
}
- qapi_free_QKeyCodeList(keycodes);
+
+ g_free(keycodes);
keycodes = NULL;
+ keycodes_size = 0;
}
void qmp_send_key(QKeyCodeList *keys, bool has_hold_time, int64_t hold_time,
Error **errp)
{
int keycode;
- QKeyCodeList *p, *keylist, *head = NULL, *tmp = NULL;
+ QKeyCodeList *p;
if (!key_timer) {
key_timer = qemu_new_timer_ns(vm_clock, release_keys, NULL);
@@ -257,31 +258,22 @@ void qmp_send_key(QKeyCodeList *keys, bool has_hold_time,
int64_t hold_time,
qemu_del_timer(key_timer);
release_keys(NULL);
}
+
if (!has_hold_time) {
hold_time = 100;
}
for (p = keys; p != NULL; p = p->next) {
- keylist = g_malloc0(sizeof(*keylist));
- keylist->value = p->value;
- keylist->next = NULL;
-
- if (!head) {
- head = keylist;
- }
- if (tmp) {
- tmp->next = keylist;
- }
- tmp = keylist;
-
/* key down events */
keycode = key_defs[p->value];
if (keycode & 0x80) {
kbd_put_keycode(0xe0);
}
kbd_put_keycode(keycode & 0x7f);
+
+ keycodes = g_realloc(keycodes, sizeof(int) * (keycodes_size + 1));
+ keycodes[keycodes_size++] = keycode;
}
- keycodes = head;
/* delayed key up events */
qemu_mod_timer(key_timer, qemu_get_clock_ns(vm_clock) +
--
1.7.12.315.g682ce8b
- [Qemu-devel] [PULL 01/15] Make negotiation optional in QEMUMonitorProtocol, (continued)
- [Qemu-devel] [PULL 01/15] Make negotiation optional in QEMUMonitorProtocol, Luiz Capitulino, 2012/09/27
- [Qemu-devel] [PULL 04/15] qapi: do not protect enum values from namespace pollution, Luiz Capitulino, 2012/09/27
- [Qemu-devel] [PULL 02/15] Support settimeout in QEMUMonitorProtocol, Luiz Capitulino, 2012/09/27
- [Qemu-devel] [PULL 08/15] qapi: convert add_client, Luiz Capitulino, 2012/09/27
- [Qemu-devel] [PULL 07/15] monitor: add Error * argument to monitor_get_fd, Luiz Capitulino, 2012/09/27
- [Qemu-devel] [PULL 11/15] hmp: dump-guest-memory: hardcode protocol argument to "file:", Luiz Capitulino, 2012/09/27
- [Qemu-devel] [PULL 09/15] qmp: dump-guest-memory: improve schema doc (again), Luiz Capitulino, 2012/09/27
- [Qemu-devel] [PULL 13/15] qmp: qmp_send_key(): accept key codes in hex, Luiz Capitulino, 2012/09/27
- [Qemu-devel] [PULL 10/15] qmp: dump-guest-memory: don't spin if non-blocking fd would block, Luiz Capitulino, 2012/09/27
- [Qemu-devel] [PULL 14/15] input: index_from_key(): drop unused code, Luiz Capitulino, 2012/09/27
- [Qemu-devel] [PULL 12/15] input: qmp_send_key(): simplify,
Luiz Capitulino <=
- [Qemu-devel] [PULL 15/15] block: live snapshot documentation tweaks, Luiz Capitulino, 2012/09/27