From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K3xWN-0002Op-RO for qemu-devel@nongnu.org; Wed, 04 Jun 2008 14:15:40 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K3xWM-0002M7-39 for qemu-devel@nongnu.org; Wed, 04 Jun 2008 14:15:38 -0400 Received: from [199.232.76.173] (port=35979 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K3xWL-0002Lg-RC for qemu-devel@nongnu.org; Wed, 04 Jun 2008 14:15:37 -0400 Received: from fmmailgate03.web.de ([217.72.192.234]:35253) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1K3xWL-0006Uh-IF for qemu-devel@nongnu.org; Wed, 04 Jun 2008 14:15:37 -0400 Received: from smtp08.web.de (fmsmtp08.dlan.cinetic.de [172.20.5.216]) by fmmailgate03.web.de (Postfix) with ESMTP id A531FDE2F03D for ; Wed, 4 Jun 2008 20:13:36 +0200 (CEST) Received: from [88.65.37.28] (helo=[139.25.109.167]) by smtp08.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.109 #226) id 1K3xUN-0000TM-00 for qemu-devel@nongnu.org; Wed, 04 Jun 2008 20:13:36 +0200 Message-ID: <4846DB4C.20504@web.de> Date: Wed, 04 Jun 2008 20:13:32 +0200 From: Jan Kiszka MIME-Version: 1.0 References: <48357281.1090501@web.de> In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig71E5E639F9CD49D4E78F3CF3" Sender: jan.kiszka@web.de Subject: [Qemu-devel] Re: [PATCH 2/2] Enhance sendkey with key hold time Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig71E5E639F9CD49D4E78F3CF3 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable andrzej zaborowski wrote: > On 22/05/2008, Jan Kiszka wrote: >> Current key injection via the monitor basically generates no key hold >> time. This is fine for keyboard emulations that have their own queues= , >> but it causes troubles for those how don't (like the MusicPal - it >> simply does not work with injected keys). Moreover, I would like to u= se >> this mechanism to simulate pressed buttons during power-up. >> >> Therefore, this patch enhances the key injection with a configurable >> release delay (by default 100 virtual milliseconds). >> >> This feature allows to get rid of the initial sleep() in musicpal_ini= t >> because one can now simply start qemu with -S and issue "sendkey m 10= 00" >> and "continue" in the monitor to achieve the desired effect of a pres= sed >> menu button during power-up. So there is no need for a per-musicpal o= r >> even qemu-wide "-hold-button" switch. >> >> Signed-off-by: Jan Kiszka >> --- >> hw/musicpal.c | 6 ------ >> monitor.c | 57 ++++++++++++++++++++++++++++++++++++++---------= ---------- >> 2 files changed, 38 insertions(+), 25 deletions(-) >> >> Index: b/hw/musicpal.c >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> --- a/hw/musicpal.c >> +++ b/hw/musicpal.c >> @@ -1504,12 +1504,6 @@ static void musicpal_init(ram_addr_t ram >> >> qemu_add_kbd_event_handler(musicpal_key_event, pic[MP_GPIO_IRQ]);= >> >> - /* >> - * Wait a bit to catch menu button during U-Boot start-up >> - * (to trigger emergency update). >> - */ >> - sleep(1); >> - >> mv88w8618_eth_init(&nd_table[0], MP_ETH_BASE, pic[MP_ETH_IRQ]); >> >> mixer_i2c =3D musicpal_audio_init(MP_AUDIO_BASE, pic[MP_AUDIO_IRQ= ]); >> Index: b/monitor.c >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> --- a/monitor.c >> +++ b/monitor.c >> @@ -35,10 +35,7 @@ >> #include "audio/audio.h" >> #include "disas.h" >> #include >> - >> -#ifdef CONFIG_PROFILER >> -#include "qemu-timer.h" /* for ticks_per_sec */ >> -#endif >> +#include "qemu-timer.h" >> >> //#define DEBUG >> //#define DEBUG_COMPLETION >> @@ -925,14 +922,37 @@ static int get_keycode(const char *key) >> return -1; >> } >> >> -static void do_sendkey(const char *string) >> +#define MAX_KEYCODES 16 >> +static uint8_t keycodes[MAX_KEYCODES]; >> +static int nb_pending_keycodes; >> +static QEMUTimer *key_timer; >> + >> +static void release_keys(void *opaque) >> +{ >> + int keycode; >> + >> + while (nb_pending_keycodes > 0) { >> + keycode =3D keycodes[nb_pending_keycodes-1]; >> + if (keycode & 0x80) >> + kbd_put_keycode(0xe0); >> + kbd_put_keycode(keycode | 0x80); >> + nb_pending_keycodes--; >> + } >> +} >> + >> +static void do_sendkey(const char *string, int has_hold_time, int ho= ld_time) >> { >> - uint8_t keycodes[16]; >> - int nb_keycodes =3D 0; >> char keyname_buf[16]; >> char *separator; >> int keyname_len, keycode, i; >> >> + if (nb_pending_keycodes > 0) { >> + qemu_del_timer(key_timer); >> + release_keys(NULL); >> + } >> + if (!has_hold_time) >> + hold_time =3D 100; >> + i =3D 0; >> while (1) { >> separator =3D strchr(string, '-'); >> keyname_len =3D separator ? separator-string : strlen(string)= ; >> @@ -943,7 +963,7 @@ static void do_sendkey(const char *strin >> term_printf("invalid key: '%s...'\n", keyname_buf); >> return; >> } >> - if (nb_keycodes =3D=3D sizeof(keycodes)) { >> + if (i =3D=3D MAX_KEYCODES) { >> term_printf("too many keys\n"); >> return; >> } >> @@ -953,26 +973,22 @@ static void do_sendkey(const char *strin >> term_printf("unknown key: '%s'\n", keyname_buf); >> return; >> } >> - keycodes[nb_keycodes++] =3D keycode; >> + keycodes[i++] =3D keycode; >> } >> if (!separator) >> break; >> string =3D separator + 1; >> } >> + nb_pending_keycodes =3D i; >> /* key down events */ >> - for(i =3D 0; i < nb_keycodes; i++) { >> + for (i =3D 0; i < nb_pending_keycodes; i++) { >> keycode =3D keycodes[i]; >> if (keycode & 0x80) >> kbd_put_keycode(0xe0); >> kbd_put_keycode(keycode & 0x7f); >> } >> - /* key up events */ >> - for(i =3D nb_keycodes - 1; i >=3D 0; i--) { >> - keycode =3D keycodes[i]; >> - if (keycode & 0x80) >> - kbd_put_keycode(0xe0); >> - kbd_put_keycode(keycode | 0x80); >> - } >> + /* delayed key up events */ >> + qemu_mod_timer(key_timer, qemu_get_clock(vm_clock) + 1000000LL*h= old_time); >=20 > This should use ticks_per_sec. Will fix. >=20 > Also, 100ms seems high for the default value, I think you rarely press > keys for that long. That's what I measured for human-typed keys in the monitor, so I simply applied that value to keep things consistent for kbd consumers. Thanks, Jan --------------enig71E5E639F9CD49D4E78F3CF3 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.4-svn0 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iD8DBQFIRttPniDOoMHTA+kRAr3TAJ9yGDnKAaxAFnKZEDtedMr+mGTgJACdGFd3 kYCxAdumbFj7UJxdiJrPAIE= =J+bP -----END PGP SIGNATURE----- --------------enig71E5E639F9CD49D4E78F3CF3--