[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2] ui/cocoa.m: prevent stuck key situation
From: |
Programmingkid |
Subject: |
[Qemu-devel] [PATCH v2] ui/cocoa.m: prevent stuck key situation |
Date: |
Wed, 23 Sep 2015 20:17:55 -0400 |
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 <address@hidden>
---
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.
+ */
+- (void) raiseAllKeys
+{
+ int index;
+ const int max_index = 220; /* This is the highest value key */
+
+ 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 +951,14 @@ 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
- [Qemu-devel] [PATCH v2] ui/cocoa.m: prevent stuck key situation,
Programmingkid <=