Received: from eggs.gnu.org ([2001:4830:134:3::10]:36932) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zd3UG-0006pn-Uy for qemu-devel@nongnu.org; Fri, 18 Sep 2015 17:46:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zd3UB-0005Pk-Ve for qemu-devel@nongnu.org; Fri, 18 Sep 2015 17:46:32 -0400 Received: from mail-qg0-x236.google.com ([2607:f8b0:400d:c04::236]:34124) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zd3UB-0005Pg-PI for qemu-devel@nongnu.org; Fri, 18 Sep 2015 17:46:27 -0400 Received: by qgez77 with SMTP id z77so50066674qge.1 for ; Fri, 18 Sep 2015 14:46:27 -0700 (PDT) From: Programmingkid Content-Type: multipart/alternative; boundary=Apple-Mail-12-449100864 Date: Fri, 18 Sep 2015 17:46:08 -0400 Message-Id: <4D622DB1-AB63-4FDE-8B40-30FE9897E510@gmail.com> Mime-Version: 1.0 (Apple Message framework v1084) Subject: [Qemu-devel] [PATCH] 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 --Apple-Mail-12-449100864 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii When the user puts QEMU in the background while holding down a key, QEMU = will=20 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 keys when QEMU goes into = the background.=20 Signed-off-by: John Arbuckle --- ui/cocoa.m | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index 334e6f6..d07b22d 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -69,6 +69,7 @@ char **gArgv; bool stretch_video; NSTextField *pauseLabel; NSArray * supportedImageFileTypes; +int modifiers_state[256]; =20 // keymap conversion int keymap[] =3D @@ -274,7 +275,6 @@ static void handleAnyDeviceErrors(Error * err) NSWindow *fullScreenWindow; float cx,cy,cw,ch,cdx,cdy; CGDataProviderRef dataProviderRef; - int modifiers_state[256]; BOOL isMouseGrabbed; BOOL isFullscreen; BOOL isAbsoluteEnabled; @@ -933,6 +933,21 @@ QemuCocoaView *cocoaView; return YES; } =20 +/* Called when QEMU goes into the background */ +- (void) applicationWillResignActive: (NSNotification *)aNotification +{ + COCOA_DEBUG("QemuCocoaAppController: = applicationWillResignActive\n"); + int keycode, index; + const int max_index =3D 126; /* This is the size of the keymap = array */ + + /* Release all the keys to prevent a stuck key situation */ + for(index =3D 0; index <=3D max_index; index++) { + keycode =3D keymap[index]; + modifiers_state[keycode] =3D 0; + qemu_input_event_send_key_number(dcl->con, keycode, false); + } +} + - (void)startEmulationWithArgc:(int)argc argv:(char**)argv { COCOA_DEBUG("QemuCocoaAppController: startEmulationWithArgc\n"); --=20 1.7.5.4 --Apple-Mail-12-449100864 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii
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 keys when QEMU goes into the

Signed-off-by: John Arbuckle = <programmingkidx@gmail.com>= ;

---
 ui/cocoa.m |   17 = ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 = deletions(-)

diff --git a/ui/cocoa.m = b/ui/cocoa.m
index 334e6f6..d07b22d 100644
--- = a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -69,6 +69,7 @@ char = **gArgv;
 bool stretch_video;
 NSArray * = supportedImageFileTypes;
+int modifiers_state[256];

 

 int keymap[] =3D
@@ = -274,7 +275,6 @@ static void handleAnyDeviceErrors(Error * = err)
     NSWindow = *fullScreenWindow;
     float = cx,cy,cw,ch,cdx,cdy;
     CGDataProviderRef = dataProviderRef;
-    int modifiers_state[256];
     BOOL = isFullscreen;
     BOOL = isAbsoluteEnabled;
@@ -933,6 +933,21 @@ QemuCocoaView = *cocoaView;
     return YES;
 

+/* Called when QEMU goes into the = background */
+- (void) applicationWillResignActive: = (NSNotification *)aNotification
+{
+    = COCOA_DEBUG("QemuCocoaAppController: = applicationWillResignActive\n");
+    int keycode, = index;
+    const int max_index =3D 126; /* This = is the size of the keymap array */
+
+    /* Release all the = keys to prevent a stuck key situation */
+    for(index =3D = 0; index <=3D max_index; index++) {
+        = keycode =3D keymap[index];
+        = modifiers_state[keycode] =3D 0;
+        = qemu_input_event_send_key_number(dcl->con, keycode, false);
+}
+
 - = (void)startEmulationWithArgc:(int)argc argv:(char**)argv
     = COCOA_DEBUG("QemuCocoaAppController: = startEmulationWithArgc\n");
-- 
1.7.5.4

= --Apple-Mail-12-449100864--