* [Qemu-devel] [PULL 1/3] ui/cocoa.m: verify with user before quitting QEMU
2015-09-25 22:18 [Qemu-devel] [PULL 0/3] cocoa queue Peter Maydell
@ 2015-09-25 22:18 ` Peter Maydell
2015-09-25 22:18 ` [Qemu-devel] [PULL 2/3] ui/cocoa.m: prevent stuck key situation Peter Maydell
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Peter Maydell @ 2015-09-25 22:18 UTC (permalink / raw)
To: qemu-devel
From: John Arbuckle <programmingkidx@gmail.com>
This patch prevents the user from accidentally quitting QEMU by pushing
Command-Q or by pushing the close button on the main window. When
the user does one of these two things, a dialog box appears verifying
with the user if he or she wants to quit QEMU.
Signed-off-by: John Arbuckle <programmingkidx@gmail.com>
Message-id: 29169A74-0347-47F5-934F-A5AD24C225CA@gmail.com
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
ui/cocoa.m | 39 ++++++++++++++++++++++++++++++++++++++-
1 file changed, 38 insertions(+), 1 deletion(-)
diff --git a/ui/cocoa.m b/ui/cocoa.m
index c24d9f9..7c64e1a 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -809,7 +809,7 @@ QemuCocoaView *cocoaView;
*/
@interface QemuCocoaAppController : NSObject
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
- <NSApplicationDelegate>
+ <NSWindowDelegate, NSApplicationDelegate>
#endif
{
}
@@ -829,6 +829,7 @@ QemuCocoaView *cocoaView;
- (void)powerDownQEMU:(id)sender;
- (void)ejectDeviceMedia:(id)sender;
- (void)changeDeviceMedia:(id)sender;
+- (BOOL)verifyQuit;
@end
@implementation QemuCocoaAppController
@@ -862,6 +863,7 @@ QemuCocoaView *cocoaView;
#endif
[normalWindow makeKeyAndOrderFront:self];
[normalWindow center];
+ [normalWindow setDelegate: self];
stretch_video = false;
/* Used for displaying pause on the screen */
@@ -933,6 +935,26 @@ QemuCocoaView *cocoaView;
return YES;
}
+- (NSApplicationTerminateReply)applicationShouldTerminate:
+ (NSApplication *)sender
+{
+ COCOA_DEBUG("QemuCocoaAppController: applicationShouldTerminate\n");
+ return [self verifyQuit];
+}
+
+/* Called when the user clicks on a window's close button */
+- (BOOL)windowShouldClose:(id)sender
+{
+ COCOA_DEBUG("QemuCocoaAppController: windowShouldClose\n");
+ [NSApp terminate: sender];
+ /* If the user allows the application to quit then the call to
+ * NSApp terminate will never return. If we get here then the user
+ * cancelled the quit, so we should return NO to not permit the
+ * closing of this window.
+ */
+ return NO;
+}
+
- (void)startEmulationWithArgc:(int)argc argv:(char**)argv
{
COCOA_DEBUG("QemuCocoaAppController: startEmulationWithArgc\n");
@@ -1125,6 +1147,21 @@ QemuCocoaView *cocoaView;
}
}
+/* Verifies if the user really wants to quit */
+- (BOOL)verifyQuit
+{
+ NSAlert *alert = [NSAlert new];
+ [alert autorelease];
+ [alert setMessageText: @"Are you sure you want to quit QEMU?"];
+ [alert addButtonWithTitle: @"Cancel"];
+ [alert addButtonWithTitle: @"Quit"];
+ if([alert runModal] == NSAlertSecondButtonReturn) {
+ return YES;
+ } else {
+ return NO;
+ }
+}
+
@end
--
1.9.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PULL 2/3] ui/cocoa.m: prevent stuck key situation
2015-09-25 22:18 [Qemu-devel] [PULL 0/3] cocoa queue Peter Maydell
2015-09-25 22:18 ` [Qemu-devel] [PULL 1/3] ui/cocoa.m: verify with user before quitting QEMU Peter Maydell
@ 2015-09-25 22:18 ` Peter Maydell
2015-09-25 22:18 ` [Qemu-devel] [PULL 3/3] ui/cocoa.m: remove open dialog code Peter Maydell
2015-09-29 11:04 ` [Qemu-devel] [PULL 0/3] cocoa queue Peter Maydell
3 siblings, 0 replies; 5+ messages in thread
From: Peter Maydell @ 2015-09-25 22:18 UTC (permalink / raw)
To: qemu-devel
From: John Arbuckle <programmingkidx@gmail.com>
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 <programmingkidx@gmail.com>
Message-id: 7A3FA6EE-84C8-4422-A786-C899B7229D32@gmail.com
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
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");
--
1.9.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PULL 3/3] ui/cocoa.m: remove open dialog code
2015-09-25 22:18 [Qemu-devel] [PULL 0/3] cocoa queue Peter Maydell
2015-09-25 22:18 ` [Qemu-devel] [PULL 1/3] ui/cocoa.m: verify with user before quitting QEMU Peter Maydell
2015-09-25 22:18 ` [Qemu-devel] [PULL 2/3] ui/cocoa.m: prevent stuck key situation Peter Maydell
@ 2015-09-25 22:18 ` Peter Maydell
2015-09-29 11:04 ` [Qemu-devel] [PULL 0/3] cocoa queue Peter Maydell
3 siblings, 0 replies; 5+ messages in thread
From: Peter Maydell @ 2015-09-25 22:18 UTC (permalink / raw)
To: qemu-devel
From: John Arbuckle <programmingkidx@gmail.com>
Removes the open dialog code that runs when no arguments are supplied with QEMU.
Not everyone needs a hard drive or cdrom to boot their target. A user might only
need to use their target's bios to do work. With that said, this patch removes
the unneeded open dialog code.
Signed-off-by: John Arbuckle <programmingkidx@gmail.com>
Message-id: 33856864-321C-4367-9170-FB0BF81E789B@gmail.com
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
ui/cocoa.m | 56 ++------------------------------------------------------
1 file changed, 2 insertions(+), 54 deletions(-)
diff --git a/ui/cocoa.m b/ui/cocoa.m
index d436780..a91b8bc 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -833,7 +833,6 @@ QemuCocoaView *cocoaView;
{
}
- (void)startEmulationWithArgc:(int)argc argv:(char**)argv;
-- (void)openPanelDidEnd:(NSOpenPanel *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;
- (void)doToggleFullScreen:(id)sender;
- (void)toggleFullScreen:(id)sender;
- (void)showQEMUDoc:(id)sender;
@@ -916,29 +915,8 @@ QemuCocoaView *cocoaView;
- (void)applicationDidFinishLaunching: (NSNotification *) note
{
COCOA_DEBUG("QemuCocoaAppController: applicationDidFinishLaunching\n");
-
- // Display an open dialog box if no arguments were passed or
- // if qemu was launched from the finder ( the Finder passes "-psn" )
- if( gArgc <= 1 || strncmp ((char *)gArgv[1], "-psn", 4) == 0) {
- NSOpenPanel *op = [[NSOpenPanel alloc] init];
- [op setPrompt:@"Boot image"];
- [op setMessage:@"Select the disk image you want to boot.\n\nHit the \"Cancel\" button to quit"];
-#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
- [op setAllowedFileTypes:supportedImageFileTypes];
- [op beginSheetModalForWindow:normalWindow
- completionHandler:^(NSInteger returnCode)
- { [self openPanelDidEnd:op
- returnCode:returnCode contextInfo:NULL ]; } ];
-#else
- // Compatibility code for pre-10.6, using deprecated method
- [op beginSheetForDirectory:nil file:nil types:filetypes
- modalForWindow:normalWindow modalDelegate:self
- didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:) contextInfo:NULL];
-#endif
- } else {
- // or launch QEMU, with the global args
- [self startEmulationWithArgc:gArgc argv:(char **)gArgv];
- }
+ // launch QEMU, with the global args
+ [self startEmulationWithArgc:gArgc argv:(char **)gArgv];
}
- (void)applicationWillTerminate:(NSNotification *)aNotification
@@ -990,36 +968,6 @@ QemuCocoaView *cocoaView;
exit(status);
}
-- (void)openPanelDidEnd:(NSOpenPanel *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
-{
- COCOA_DEBUG("QemuCocoaAppController: openPanelDidEnd\n");
-
- /* The NSFileHandlingPanelOKButton/NSFileHandlingPanelCancelButton values for
- * returnCode strictly only apply for the 10.6-and-up beginSheetModalForWindow
- * API. For the legacy pre-10.6 beginSheetForDirectory API they are NSOKButton
- * and NSCancelButton. However conveniently the values are the same.
- * We use the non-legacy names because the others are deprecated in OSX 10.10.
- */
- if (returnCode == NSFileHandlingPanelCancelButton) {
- exit(0);
- } else if (returnCode == NSFileHandlingPanelOKButton) {
- char *img = (char*)[ [ [ sheet URL ] path ] cStringUsingEncoding:NSASCIIStringEncoding];
-
- char **argv = g_new(char *, 4);
-
- [sheet close];
-
- argv[0] = g_strdup(gArgv[0]);
- argv[1] = g_strdup("-hda");
- argv[2] = g_strdup(img);
- argv[3] = NULL;
-
- // printf("Using argc %d argv %s -hda %s\n", 3, gArgv[0], img);
-
- [self startEmulationWithArgc:3 argv:(char**)argv];
- }
-}
-
/* We abstract the method called by the Enter Fullscreen menu item
* because Mac OS 10.7 and higher disables it. This is because of the
* menu item's old selector's name toggleFullScreen:
--
1.9.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PULL 0/3] cocoa queue
2015-09-25 22:18 [Qemu-devel] [PULL 0/3] cocoa queue Peter Maydell
` (2 preceding siblings ...)
2015-09-25 22:18 ` [Qemu-devel] [PULL 3/3] ui/cocoa.m: remove open dialog code Peter Maydell
@ 2015-09-29 11:04 ` Peter Maydell
3 siblings, 0 replies; 5+ messages in thread
From: Peter Maydell @ 2015-09-29 11:04 UTC (permalink / raw)
To: QEMU Developers
On 25 September 2015 at 23:18, Peter Maydell <peter.maydell@linaro.org> wrote:
> Flushing the cocoa queue.
>
> The following changes since commit 9e071429e649346c14b2dc76902f84f8352d2333:
>
> Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging (2015-09-25 21:52:30 +0100)
>
> are available in the git repository at:
>
>
> git://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-cocoa-20150925-1
>
> for you to fetch changes up to 365d7f3c7aacc789ead96b8eeb5ba5b0a8d93d48:
>
> ui/cocoa.m: remove open dialog code (2015-09-25 23:14:00 +0100)
>
> ----------------------------------------------------------------
> cocoa queue:
> * fix stuck-key bug if keys were down when QEMU lost focus
> * prompt the user whether they really meant to quit
> * remove the 'open image file' dialog box we used to display
> if the user started QEMU without arguments
Applied, thanks.
-- PMM
^ permalink raw reply [flat|nested] 5+ messages in thread