Received: from eggs.gnu.org ([2001:4830:134:3::10]:37694) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayVgi-0003Yl-DF for qemu-devel@nongnu.org; Thu, 05 May 2016 22:40:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ayVgU-0004xO-06 for qemu-devel@nongnu.org; Thu, 05 May 2016 22:40:14 -0400 Received: from mail-io0-x241.google.com ([2607:f8b0:4001:c06::241]:35781) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayVgS-0004rE-Ou for qemu-devel@nongnu.org; Thu, 05 May 2016 22:40:05 -0400 Received: by mail-io0-x241.google.com with SMTP id u185so12774446iod.2 for ; Thu, 05 May 2016 19:39:50 -0700 (PDT) From: Programmingkid Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Date: Thu, 5 May 2016 22:39:43 -0400 Message-Id: Mime-Version: 1.0 (Apple Message framework v1084) Subject: [Qemu-devel] [PATCH v3 5/5] adb.c: add power key support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell , Gerd Hoffmann Cc: qemu-devel qemu-devel Add support for the power key. It has to be handled differently from the = other keys because it is the only 16-bit value key. Signed-off-by: John Arbuckle --- v3 change Add several suggested comments. Moved the location of an else statement in the adb_keyboard_event() = function. hw/input/adb.c | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/hw/input/adb.c b/hw/input/adb.c index 37728b3..b5e53c7 100644 --- a/hw/input/adb.c +++ b/hw/input/adb.c @@ -343,10 +343,25 @@ static int adb_kbd_poll(ADBDevice *d, uint8_t = *obuf) s->rptr =3D 0; } s->count--; - obuf[0] =3D keycode; - /* NOTE: could put a second keycode if needed */ - obuf[1] =3D 0xff; - olen =3D 2; + /* + * The power key is the only two byte value key, so it is a special = case. + * Since 0x7f is not a used keycode for ADB we overload it to = indicate the + * power button when we're storing keycodes in our internal buffer, = and + * expand it out to two bytes when we send to the guest." + */ + if (keycode =3D=3D 0x7f) { + obuf[0] =3D 0x7f; + obuf[1] =3D 0x7f; + olen =3D 2; + } else { + obuf[0] =3D keycode; + /* NOTE: the power key key-up is the two byte sequence 0xff = 0xff; + * otherwise we could in theory send a second keycode in the = second + * byte, but choose not to bother. + */ + obuf[1] =3D 0xff; + olen =3D 2; + } =20 return olen; } @@ -424,15 +439,23 @@ static void adb_keyboard_event(DeviceState *dev, = QemuConsole *src, return; } keycode =3D qcode_to_adb_keycode[qcode]; - if (keycode =3D=3D NO_KEY) { /* We don't want to send this to the = guest */ - return; - } =20 - if (evt->u.key.data->down =3D=3D false) { /* if key release event = */ - keycode =3D keycode | 0x80; /* create keyboard break code */ + /* The power button is a special case because it is a 16-bit value = */ + if (qcode =3D=3D Q_KEY_CODE_POWER) { + printf("Power Key detected\n"); + if (evt->u.key.data->down =3D=3D true) { /* Power button pushed = keycode */ + adb_kbd_put_keycode(s, 0x7f); + } else { /* Power button released = keycode */ + adb_kbd_put_keycode(s, 0xff); + } + } else if (keycode =3D=3D NO_KEY) { /* NO_KEY shouldn't be sent to = guest */ + return; + } else { /* For all non-power keys - safe for 8-bit keycodes */ + if (evt->u.key.data->down =3D=3D false) { /* if key release = event */ + keycode =3D keycode | 0x80; /* create keyboard break code = */ + } + adb_kbd_put_keycode(s, keycode); } - - adb_kbd_put_keycode(s, keycode); } =20 static const VMStateDescription vmstate_adb_kbd =3D { --=20 2.7.2