From patchwork Thu Feb 25 08:39:21 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 46222 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 844DFB7C59 for ; Thu, 25 Feb 2010 19:53:01 +1100 (EST) Received: from localhost ([127.0.0.1]:57051 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NkZSs-00020h-OP for incoming@patchwork.ozlabs.org; Thu, 25 Feb 2010 03:52:58 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NkZFr-00068Z-Pm for qemu-devel@nongnu.org; Thu, 25 Feb 2010 03:39:32 -0500 Received: from [199.232.76.173] (port=33648 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NkZFq-00067t-1v for qemu-devel@nongnu.org; Thu, 25 Feb 2010 03:39:30 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NkZFn-0007Yr-2b for qemu-devel@nongnu.org; Thu, 25 Feb 2010 03:39:29 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36940) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NkZFm-0007YZ-CP for qemu-devel@nongnu.org; Thu, 25 Feb 2010 03:39:26 -0500 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o1P8dPuL004569 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 25 Feb 2010 03:39:25 -0500 Received: from zweiblum.home.kraxel.org (vpn1-7-164.ams2.redhat.com [10.36.7.164]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o1P8dNao010928; Thu, 25 Feb 2010 03:39:23 -0500 Received: by zweiblum.home.kraxel.org (Postfix, from userid 500) id 5B8BC7010F; Thu, 25 Feb 2010 09:39:22 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Thu, 25 Feb 2010 09:39:21 +0100 Message-Id: <1267087161-15204-5-git-send-email-kraxel@redhat.com> In-Reply-To: <1267087161-15204-1-git-send-email-kraxel@redhat.com> References: <1267087161-15204-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH 4/4] kbd keds: vnc X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Use led status notification support in vnc. The qemu vnc server keeps track of the capslock and numlock states based on the key presses it receives from the vnc client. But this fails in case the guests idea of the capslock and numlock state changes for other reasons. One case is guest reboot (+ keyboard reset). Another case are more recent windows versions which reset capslock state before presenting the login screen. Usually guests use the keyboard leds to signal the capslock and numlock state to the user, so we can use this to better keep track of capslock and numlock state in the qemu vnc server. Signed-off-by: Gerd Hoffmann --- vnc.c | 20 +++++++++++++++++++- vnc.h | 1 + 2 files changed, 20 insertions(+), 1 deletions(-) diff --git a/vnc.c b/vnc.c index db34b0e..38690e2 100644 --- a/vnc.c +++ b/vnc.c @@ -1111,6 +1111,7 @@ static void vnc_disconnect_finish(VncState *vs) } vnc_remove_timer(vs->vd); + qemu_remove_led_event_handler(vs->led); qemu_free(vs); } @@ -1496,6 +1497,22 @@ static void press_key(VncState *vs, int keysym) kbd_put_keycode(keysym2scancode(vs->vd->kbd_layout, keysym) | 0x80); } +static void kbd_leds(void *opaque, int ledstate) +{ + VncState *vs = opaque; + int caps, num; + + caps = ledstate & QEMU_CAPS_LOCK_LED ? 1 : 0; + num = ledstate & QEMU_NUM_LOCK_LED ? 1 : 0; + + if (vs->modifiers_state[0x3a] != caps) { + vs->modifiers_state[0x3a] = caps; + } + if (vs->modifiers_state[0x45] != num) { + vs->modifiers_state[0x45] = num; + } +} + static void do_key_event(VncState *vs, int down, int keycode, int sym) { /* QEMU console switch */ @@ -1521,7 +1538,7 @@ static void do_key_event(VncState *vs, int down, int keycode, int sym) break; case 0x3a: /* CapsLock */ case 0x45: /* NumLock */ - if (!down) + if (down) vs->modifiers_state[keycode] ^= 1; break; } @@ -2407,6 +2424,7 @@ static void vnc_connect(VncDisplay *vd, int csock) vnc_flush(vs); vnc_read_when(vs, protocol_version, 12); reset_keys(vs); + vs->led = qemu_add_led_event_handler(kbd_leds, vs); vnc_init_timer(vd); diff --git a/vnc.h b/vnc.h index ff9a699..0fc89bd 100644 --- a/vnc.h +++ b/vnc.h @@ -161,6 +161,7 @@ struct VncState size_t read_handler_expect; /* input */ uint8_t modifiers_state[256]; + QEMUPutLEDEntry *led; Buffer zlib; Buffer zlib_tmp;