From patchwork Fri Sep 25 22:18:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 523018 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4B22C140771 for ; Sat, 26 Sep 2015 08:19:45 +1000 (AEST) Received: from localhost ([::1]:50743 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZfbLD-0000wL-AF for incoming@patchwork.ozlabs.org; Fri, 25 Sep 2015 18:19:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60270) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZfbKY-0008I7-CZ for qemu-devel@nongnu.org; Fri, 25 Sep 2015 18:19:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZfbKX-0007Rg-J8 for qemu-devel@nongnu.org; Fri, 25 Sep 2015 18:19:02 -0400 Received: from mnementh.archaic.org.uk ([2001:8b0:1d0::1]:35102) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZfbKX-0007Mt-DU for qemu-devel@nongnu.org; Fri, 25 Sep 2015 18:19:01 -0400 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1ZfbKP-0003zW-10 for qemu-devel@nongnu.org; Fri, 25 Sep 2015 23:18:53 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 25 Sep 2015 23:18:51 +0100 Message-Id: <1443219532-15309-3-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1443219532-15309-1-git-send-email-peter.maydell@linaro.org> References: <1443219532-15309-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:8b0:1d0::1 Subject: [Qemu-devel] [PULL 2/3] ui/cocoa.m: prevent stuck key situation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: John Arbuckle When the user puts QEMU in the background while holding down a key, QEMU will not receive the keyup event when the user lets go of the key. When the user goes back to QEMU, QEMU will think the key is still down causing stuck key symptoms. This patch fixes this problem by releasing all down keys when QEMU goes into the background. Signed-off-by: John Arbuckle Message-id: 7A3FA6EE-84C8-4422-A786-C899B7229D32@gmail.com Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell --- ui/cocoa.m | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/ui/cocoa.m b/ui/cocoa.m index 7c64e1a..d436780 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -304,6 +304,7 @@ static void handleAnyDeviceErrors(Error * err) - (float) cdx; - (float) cdy; - (QEMUScreen) gscreen; +- (void) raiseAllKeys; @end QemuCocoaView *cocoaView; @@ -798,6 +799,24 @@ QemuCocoaView *cocoaView; - (float) cdx {return cdx;} - (float) cdy {return cdy;} - (QEMUScreen) gscreen {return screen;} + +/* + * Makes the target think all down keys are being released. + * This prevents a stuck key problem, since we will not see + * key up events for those keys after we have lost focus. + */ +- (void) raiseAllKeys +{ + int index; + const int max_index = ARRAY_SIZE(modifiers_state); + + for (index = 0; index < max_index; index++) { + if (modifiers_state[index]) { + modifiers_state[index] = 0; + qemu_input_event_send_key_number(dcl->con, index, false); + } + } +} @end @@ -955,6 +974,13 @@ QemuCocoaView *cocoaView; return NO; } +/* Called when QEMU goes into the background */ +- (void) applicationWillResignActive: (NSNotification *)aNotification +{ + COCOA_DEBUG("QemuCocoaAppController: applicationWillResignActive\n"); + [cocoaView raiseAllKeys]; +} + - (void)startEmulationWithArgc:(int)argc argv:(char**)argv { COCOA_DEBUG("QemuCocoaAppController: startEmulationWithArgc\n");