Received: from eggs.gnu.org ([2001:4830:134:3::10]:37233) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZevDv-0002LC-LP for qemu-devel@nongnu.org; Wed, 23 Sep 2015 21:21:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZevDq-00073H-Hl for qemu-devel@nongnu.org; Wed, 23 Sep 2015 21:21:23 -0400 Received: from mail-qg0-x22e.google.com ([2607:f8b0:400d:c04::22e]:34509) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZevDq-00073B-Cd for qemu-devel@nongnu.org; Wed, 23 Sep 2015 21:21:18 -0400 Received: by qgez77 with SMTP id z77so34080273qge.1 for ; Wed, 23 Sep 2015 18:21:17 -0700 (PDT) From: Programmingkid Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Wed, 23 Sep 2015 21:21:15 -0400 Message-Id: <7A3FA6EE-84C8-4422-A786-C899B7229D32@gmail.com> Mime-Version: 1.0 (Apple Message framework v1084) Subject: [Qemu-devel] [PATCH v3] ui/cocoa.m: prevent stuck key situation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell , qemu-devel qemu-devel 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 --- Changed value of max_index variable. Added more to raiseAllKeys method's comment. ui/cocoa.m | 26 ++++++++++++++++++++++++++ 1 files changed, 26 insertions(+), 0 deletions(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index 334e6f6..ee88a9e 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 @@ -933,6 +952,13 @@ QemuCocoaView *cocoaView; return YES; } +/* 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"); -- 1.7.5.4