Received: from eggs.gnu.org ([2001:4830:134:3::10]:56824) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YE0ts-00025H-Fl for qemu-devel@nongnu.org; Wed, 21 Jan 2015 14:25:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YE0tn-00041V-9n for qemu-devel@nongnu.org; Wed, 21 Jan 2015 14:25:12 -0500 Received: from mail-qc0-x22e.google.com ([2607:f8b0:400d:c01::22e]:61531) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YE0tn-0003ye-4a for qemu-devel@nongnu.org; Wed, 21 Jan 2015 14:25:07 -0500 Received: by mail-qc0-f174.google.com with SMTP id s11so17331633qcv.5 for ; Wed, 21 Jan 2015 11:25:06 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Apple Message framework v1084) From: Programmingkid Date: Wed, 21 Jan 2015 14:25:03 -0500 Content-Transfer-Encoding: quoted-printable Message-Id: References: Subject: [Qemu-devel] [PATCH v3] Fixes several full screen issues on Mac OS X List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: qemu-devel qemu-devel 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 --- Changes in version 2: - Completely rewritten. - Eliminated depreciated API's. - Does not change host monitor resolution. Change in version 3: - Fixed full screen window not receiving mouse moved events. ui/cocoa.m | 49 ++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 44 insertions(+), 5 deletions(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index d37c29b..35ab195 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -64,6 +64,7 @@ static int last_buttons; =20 int gArgc; char **gArgv; +bool stretch_video; =20 // keymap conversion int keymap[] =3D @@ -414,10 +415,21 @@ QemuCocoaView *cocoaView; - (void) setContentDimensions { COCOA_DEBUG("QemuCocoaView: setContentDimensions\n"); - if (isFullscreen) { cdx =3D [[NSScreen mainScreen] frame].size.width / = (float)screen.width; cdy =3D [[NSScreen mainScreen] frame].size.height / = (float)screen.height; + + /* stretches video, but keeps same aspect ratio */ + if(stretch_video =3D=3D true) { + /* use smallest stretch value - prevents clipping on sides = */ + if (MIN(cdx, cdy) =3D=3D cdx) { + cdy =3D cdx; + } else { + cdx =3D cdy; + } + } else { /* No stretching */ + cdx =3D cdy =3D 1; + } cw =3D screen.width * cdx; ch =3D screen.height * cdy; cx =3D ([[NSScreen mainScreen] frame].size.width - cw) / 2.0; @@ -502,6 +514,7 @@ QemuCocoaView *cocoaView; #endif } else { // switch from desktop to fullscreen isFullscreen =3D TRUE; + [normalWindow orderOut: nil]; /* Hide the window */ [self grabMouse]; [self setContentDimensions]; // test if host supports "enterFullScreenMode:withOptions" at compile = time @@ -518,8 +531,11 @@ QemuCocoaView *cocoaView; styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]; + [fullScreenWindow setAcceptsMouseMovedEvents: YES]; [fullScreenWindow setHasShadow:NO]; - [fullScreenWindow setContentView:self]; + [fullScreenWindow setBackgroundColor: [NSColor = blackColor]]; + [self setFrame:NSMakeRect(cx, cy, cw, ch)]; + [[fullScreenWindow contentView] addSubview: self]; [fullScreenWindow makeKeyAndOrderFront:self]; #if (MAC_OS_X_VERSION_MAX_ALLOWED >=3D MAC_OS_X_VERSION_10_5) } @@ -561,7 +577,7 @@ QemuCocoaView *cocoaView; } =20 // release Mouse grab when pressing ctrl+alt - if (!isFullscreen && ([event modifierFlags] & = NSControlKeyMask) && ([event modifierFlags] & NSAlternateKeyMask)) { + if (([event modifierFlags] & NSControlKeyMask) && ([event = modifierFlags] & NSAlternateKeyMask)) { [self ungrabMouse]; } break; @@ -798,9 +814,11 @@ QemuCocoaView *cocoaView; } - (void)startEmulationWithArgc:(int)argc argv:(char**)argv; - (void)openPanelDidEnd:(NSOpenPanel *)sheet returnCode:(int)returnCode = contextInfo:(void *)contextInfo; +- (void)doToggleFullScreen:(id)sender; - (void)toggleFullScreen:(id)sender; - (void)showQEMUDoc:(id)sender; - (void)showQEMUTec:(id)sender; +- (void)zoomToFit:(id) sender; @end =20 @implementation QemuCocoaAppController @@ -832,7 +850,7 @@ QemuCocoaView *cocoaView; [normalWindow useOptimizedDrawing:YES]; [normalWindow makeKeyAndOrderFront:self]; [normalWindow center]; - + stretch_video =3D false; } return self; } @@ -921,6 +939,15 @@ QemuCocoaView *cocoaView; [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 { COCOA_DEBUG("QemuCocoaAppController: toggleFullScreen\n"); @@ -943,6 +970,17 @@ QemuCocoaView *cocoaView; [[NSWorkspace sharedWorkspace] openFile:[NSString = stringWithFormat:@"%@/../doc/qemu/qemu-tech.html", [[NSBundle mainBundle] resourcePath]] withApplication:@"Help = Viewer"]; } + +/* Stretches video to fit host monitor size */ +- (void)zoomToFit:(id) sender +{ + stretch_video =3D !stretch_video; + if (stretch_video =3D=3D true) { + [sender setState: NSOnState]; + } else { + [sender setState: NSOffState]; + } +} @end =20 =20 @@ -1005,7 +1043,8 @@ int main (int argc, const char * argv[]) { =20 // View menu menu =3D [[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:@"f"] autorelease]]; menuItem =3D [[[NSMenuItem alloc] initWithTitle:@"View" action:nil = keyEquivalent:@""] autorelease]; [menuItem setSubmenu:menu]; [[NSApp mainMenu] addItem:menuItem]; --=20 1.7.5.4