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
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1
 
 iQIcBAABCAAGBQJWBcfvAAoJEDwlJe0UNgzeU0MP/0gOy+egfcy39VGRRglEeZ+o
 0Xh22O+bN0rKUiYkT+liRBTDrvr4c0HiUZsnojpVG6NgWaNfeBbcSuWH6BZ0XQkZ
 yUD3F6oRMkR8Kckj9g0Jh4fezsI4YkZcBF2kBj+lkFdNqqDX40AFiffheiFVqVRf
 E+NHoNULovD8+vzTZoCUYXzg/6rIF1ZMMT4PyuYFDvb8l1FuF7hTBt9B6mvChVAm
 GI17k6i3aE1gaH/jJDFbO4OdXbHuaiHq1KQK+ifg+jUWd3zJFQ/Fq8fiJ+BD84l8
 /zjnW7vmOEO/cuV4wAIf8hELoMG6i61H4Rsakofz2qUqJ52g3ii5azPMnJmoRI/O
 GOMkJQ9ZaeBR/uMtwX2UP3o2SCZV/1IUFCAK6T1Wq93zb1bVIV9BtjsJr/+HPS47
 AzLhx1QKw4aBynITld+515mXUcUbYLC4xUzlovuEZEgISrmBImGobElPQWCg0j+9
 68xFmYo1j8pHTy17hCMSrVbiTQ0qLN+8vrxloFObj4Mk0rxf6ZDq6yzqbXDN7GqP
 tmOkiESSXctMoXNyT+TWNqytVwjNYVeCtQJ1tn3rZS22JXqyuYcw0OxaUX+zPts5
 xW0pPYCNiASnsfd2cvERBMwbcvkpnpvYFtPHujUzlOQufxl3hyPjRd7OSbVJyPmM
 M26Rx3lKksnkxIOVhuow
 =jTmI
 -----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/pmaydell/tags/pull-cocoa-20150925-1' into staging

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

# gpg: Signature made Fri 25 Sep 2015 23:17:19 BST using RSA key ID 14360CDE
# gpg: Good signature from "Peter Maydell <peter.maydell@linaro.org>"
# gpg:                 aka "Peter Maydell <pmaydell@gmail.com>"
# gpg:                 aka "Peter Maydell <pmaydell@chiark.greenend.org.uk>"

* remotes/pmaydell/tags/pull-cocoa-20150925-1:
  ui/cocoa.m: remove open dialog code
  ui/cocoa.m: prevent stuck key situation
  ui/cocoa.m: verify with user before quitting QEMU

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Peter Maydell 2015-09-25 23:20:06 +01:00
commit 6996a002d8

View file

@ -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
@ -809,12 +828,11 @@ QemuCocoaView *cocoaView;
*/
@interface QemuCocoaAppController : NSObject
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
<NSApplicationDelegate>
<NSWindowDelegate, NSApplicationDelegate>
#endif
{
}
- (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;
@ -829,6 +847,7 @@ QemuCocoaView *cocoaView;
- (void)powerDownQEMU:(id)sender;
- (void)ejectDeviceMedia:(id)sender;
- (void)changeDeviceMedia:(id)sender;
- (BOOL)verifyQuit;
@end
@implementation QemuCocoaAppController
@ -862,6 +881,7 @@ QemuCocoaView *cocoaView;
#endif
[normalWindow makeKeyAndOrderFront:self];
[normalWindow center];
[normalWindow setDelegate: self];
stretch_video = false;
/* Used for displaying pause on the screen */
@ -895,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
@ -933,6 +932,33 @@ 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;
}
/* 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");
@ -942,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:
@ -1125,6 +1121,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