mirror of https://github.com/xemu-project/xemu.git
ui/cocoa: Fix several full screen issues on Mac OS X
This patch makes several changes: - Minimizes distorted full screen display by respecting aspect ratios. - Makes full screen mode available on Mac OS 10.7 and higher. - Allows user to decide if video should be stretched to fill the screen, using a menu item called "Zoom To Fit". - Hides the normalWindow so it won't show up in full screen mode. - Allows user to exit full screen mode. Signed-off-by: John Arbuckle <programmingkidx@gmail.com> [PMM: minor whitespace tweaks, remove incorrectly duplicated use of 'f' menu accelerator key] Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
parent
62bf3df432
commit
5d1b2eef58
49
ui/cocoa.m
49
ui/cocoa.m
|
@ -64,6 +64,7 @@ static int last_buttons;
|
||||||
|
|
||||||
int gArgc;
|
int gArgc;
|
||||||
char **gArgv;
|
char **gArgv;
|
||||||
|
bool stretch_video;
|
||||||
|
|
||||||
// keymap conversion
|
// keymap conversion
|
||||||
int keymap[] =
|
int keymap[] =
|
||||||
|
@ -418,6 +419,18 @@ QemuCocoaView *cocoaView;
|
||||||
if (isFullscreen) {
|
if (isFullscreen) {
|
||||||
cdx = [[NSScreen mainScreen] frame].size.width / (float)screen.width;
|
cdx = [[NSScreen mainScreen] frame].size.width / (float)screen.width;
|
||||||
cdy = [[NSScreen mainScreen] frame].size.height / (float)screen.height;
|
cdy = [[NSScreen mainScreen] frame].size.height / (float)screen.height;
|
||||||
|
|
||||||
|
/* stretches video, but keeps same aspect ratio */
|
||||||
|
if (stretch_video == true) {
|
||||||
|
/* use smallest stretch value - prevents clipping on sides */
|
||||||
|
if (MIN(cdx, cdy) == cdx) {
|
||||||
|
cdy = cdx;
|
||||||
|
} else {
|
||||||
|
cdx = cdy;
|
||||||
|
}
|
||||||
|
} else { /* No stretching */
|
||||||
|
cdx = cdy = 1;
|
||||||
|
}
|
||||||
cw = screen.width * cdx;
|
cw = screen.width * cdx;
|
||||||
ch = screen.height * cdy;
|
ch = screen.height * cdy;
|
||||||
cx = ([[NSScreen mainScreen] frame].size.width - cw) / 2.0;
|
cx = ([[NSScreen mainScreen] frame].size.width - cw) / 2.0;
|
||||||
|
@ -502,6 +515,7 @@ QemuCocoaView *cocoaView;
|
||||||
#endif
|
#endif
|
||||||
} else { // switch from desktop to fullscreen
|
} else { // switch from desktop to fullscreen
|
||||||
isFullscreen = TRUE;
|
isFullscreen = TRUE;
|
||||||
|
[normalWindow orderOut: nil]; /* Hide the window */
|
||||||
[self grabMouse];
|
[self grabMouse];
|
||||||
[self setContentDimensions];
|
[self setContentDimensions];
|
||||||
// test if host supports "enterFullScreenMode:withOptions" at compile time
|
// test if host supports "enterFullScreenMode:withOptions" at compile time
|
||||||
|
@ -518,8 +532,11 @@ QemuCocoaView *cocoaView;
|
||||||
styleMask:NSBorderlessWindowMask
|
styleMask:NSBorderlessWindowMask
|
||||||
backing:NSBackingStoreBuffered
|
backing:NSBackingStoreBuffered
|
||||||
defer:NO];
|
defer:NO];
|
||||||
|
[fullScreenWindow setAcceptsMouseMovedEvents: YES];
|
||||||
[fullScreenWindow setHasShadow:NO];
|
[fullScreenWindow setHasShadow:NO];
|
||||||
[fullScreenWindow setContentView:self];
|
[fullScreenWindow setBackgroundColor: [NSColor blackColor]];
|
||||||
|
[self setFrame:NSMakeRect(cx, cy, cw, ch)];
|
||||||
|
[[fullScreenWindow contentView] addSubview: self];
|
||||||
[fullScreenWindow makeKeyAndOrderFront:self];
|
[fullScreenWindow makeKeyAndOrderFront:self];
|
||||||
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
|
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
|
||||||
}
|
}
|
||||||
|
@ -561,7 +578,7 @@ QemuCocoaView *cocoaView;
|
||||||
}
|
}
|
||||||
|
|
||||||
// release Mouse grab when pressing ctrl+alt
|
// release Mouse grab when pressing ctrl+alt
|
||||||
if (!isFullscreen && ([event modifierFlags] & NSControlKeyMask) && ([event modifierFlags] & NSAlternateKeyMask)) {
|
if (([event modifierFlags] & NSControlKeyMask) && ([event modifierFlags] & NSAlternateKeyMask)) {
|
||||||
[self ungrabMouse];
|
[self ungrabMouse];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -798,9 +815,11 @@ QemuCocoaView *cocoaView;
|
||||||
}
|
}
|
||||||
- (void)startEmulationWithArgc:(int)argc argv:(char**)argv;
|
- (void)startEmulationWithArgc:(int)argc argv:(char**)argv;
|
||||||
- (void)openPanelDidEnd:(NSOpenPanel *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo;
|
- (void)openPanelDidEnd:(NSOpenPanel *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo;
|
||||||
|
- (void)doToggleFullScreen:(id)sender;
|
||||||
- (void)toggleFullScreen:(id)sender;
|
- (void)toggleFullScreen:(id)sender;
|
||||||
- (void)showQEMUDoc:(id)sender;
|
- (void)showQEMUDoc:(id)sender;
|
||||||
- (void)showQEMUTec:(id)sender;
|
- (void)showQEMUTec:(id)sender;
|
||||||
|
- (void)zoomToFit:(id) sender;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation QemuCocoaAppController
|
@implementation QemuCocoaAppController
|
||||||
|
@ -832,7 +851,7 @@ QemuCocoaView *cocoaView;
|
||||||
[normalWindow useOptimizedDrawing:YES];
|
[normalWindow useOptimizedDrawing:YES];
|
||||||
[normalWindow makeKeyAndOrderFront:self];
|
[normalWindow makeKeyAndOrderFront:self];
|
||||||
[normalWindow center];
|
[normalWindow center];
|
||||||
|
stretch_video = false;
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -921,6 +940,16 @@ QemuCocoaView *cocoaView;
|
||||||
[self startEmulationWithArgc:3 argv:(char**)argv];
|
[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:
|
||||||
|
*/
|
||||||
|
- (void) doToggleFullScreen:(id)sender
|
||||||
|
{
|
||||||
|
[self toggleFullScreen:(id)sender];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)toggleFullScreen:(id)sender
|
- (void)toggleFullScreen:(id)sender
|
||||||
{
|
{
|
||||||
COCOA_DEBUG("QemuCocoaAppController: toggleFullScreen\n");
|
COCOA_DEBUG("QemuCocoaAppController: toggleFullScreen\n");
|
||||||
|
@ -943,6 +972,17 @@ QemuCocoaView *cocoaView;
|
||||||
[[NSWorkspace sharedWorkspace] openFile:[NSString stringWithFormat:@"%@/../doc/qemu/qemu-tech.html",
|
[[NSWorkspace sharedWorkspace] openFile:[NSString stringWithFormat:@"%@/../doc/qemu/qemu-tech.html",
|
||||||
[[NSBundle mainBundle] resourcePath]] withApplication:@"Help Viewer"];
|
[[NSBundle mainBundle] resourcePath]] withApplication:@"Help Viewer"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Stretches video to fit host monitor size */
|
||||||
|
- (void)zoomToFit:(id) sender
|
||||||
|
{
|
||||||
|
stretch_video = !stretch_video;
|
||||||
|
if (stretch_video == true) {
|
||||||
|
[sender setState: NSOnState];
|
||||||
|
} else {
|
||||||
|
[sender setState: NSOffState];
|
||||||
|
}
|
||||||
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@ -1005,7 +1045,8 @@ int main (int argc, const char * argv[]) {
|
||||||
|
|
||||||
// View menu
|
// View menu
|
||||||
menu = [[NSMenu alloc] initWithTitle:@"View"];
|
menu = [[NSMenu alloc] initWithTitle:@"View"];
|
||||||
[menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Enter Fullscreen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"] autorelease]]; // Fullscreen
|
[menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Enter Fullscreen" action:@selector(doToggleFullScreen:) keyEquivalent:@"f"] autorelease]]; // Fullscreen
|
||||||
|
[menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Zoom To Fit" action:@selector(zoomToFit:) keyEquivalent:@""] autorelease]];
|
||||||
menuItem = [[[NSMenuItem alloc] initWithTitle:@"View" action:nil keyEquivalent:@""] autorelease];
|
menuItem = [[[NSMenuItem alloc] initWithTitle:@"View" action:nil keyEquivalent:@""] autorelease];
|
||||||
[menuItem setSubmenu:menu];
|
[menuItem setSubmenu:menu];
|
||||||
[[NSApp mainMenu] addItem:menuItem];
|
[[NSApp mainMenu] addItem:menuItem];
|
||||||
|
|
Loading…
Reference in New Issue