From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52552) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZeuVO-0005C0-3L for qemu-devel@nongnu.org; Wed, 23 Sep 2015 20:35:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZeuVJ-0001jL-0e for qemu-devel@nongnu.org; Wed, 23 Sep 2015 20:35:21 -0400 Received: from mail-vk0-f51.google.com ([209.85.213.51]:33442) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZeuVI-0001jH-T9 for qemu-devel@nongnu.org; Wed, 23 Sep 2015 20:35:16 -0400 Received: by vkgd64 with SMTP id d64so38558495vkg.0 for ; Wed, 23 Sep 2015 17:35:16 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: Peter Maydell Date: Wed, 23 Sep 2015 17:34:57 -0700 Message-ID: Content-Type: text/plain; charset=UTF-8 Subject: Re: [Qemu-devel] [PATCH v2] ui/cocoa.m: prevent stuck key situation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Programmingkid Cc: qemu-devel qemu-devel On 23 September 2015 at 17:17, Programmingkid wrote: > 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 > > --- > Removed the modifiers_state global variable. > Added a raiseAllKeys method. > > ui/cocoa.m | 26 ++++++++++++++++++++++++++ > 1 files changed, 26 insertions(+), 0 deletions(-) > > diff --git a/ui/cocoa.m b/ui/cocoa.m > index 334e6f6..4d15553 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,23 @@ 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 = 220; /* This is the highest value key */ No, you need to use ARRAY_SIZE. > + > + 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); > + } > + } -- PMM