From patchwork Tue May 19 08:23:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 48735 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 216DF21411 for ; Tue, 19 May 2015 08:27:55 +0000 (UTC) Received: by wgwl7 with SMTP id l7sf3064951wgw.0 for ; Tue, 19 May 2015 01:27:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=RLBJW8vbTc+dkUy8lloKv5SpvJA4PoSDR7yR1l4DQpc=; b=YecL1P+oXgMCh/ikti7gY2j4XsJxpFv+luYk8K/jerUuo5SaEWyRMUuxKv/y/aXyBD Mjm1f8qeuBla6mFT6HSTzQUmsoepK4t+JNkf3opI8lNSL5Rla94fMDx1d32WZ5sG/3HX DW8rGATq5qO9uH1qy26RNRMrxlz9pxaE4Bzi+m2T5VXNN24nzWp2J3DDw+TbJxknSwEf SBCwU/TVvbo/GB1qFRudCEdXP83dcKct5ncYRbDK0mNs+pqgrNi2kPyCkK2QeW/paDtM LN9FlBrozCNGlwbPC9xyO1nKhM2qVDDmJGdsGwl2VJ2SpY2qrZQG0ZnQYmZXWpdX92vg oObw== X-Gm-Message-State: ALoCoQme+UnbMKtyART7HkqnWHQ0iXtd0+U6eGCHwqYPhmP/787SsNGSEDU4qmGZAWhl9woF4bYb X-Received: by 10.112.29.39 with SMTP id g7mr21012361lbh.1.1432024074460; Tue, 19 May 2015 01:27:54 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.45.6 with SMTP id i6ls26454lam.4.gmail; Tue, 19 May 2015 01:27:54 -0700 (PDT) X-Received: by 10.152.87.164 with SMTP id az4mr20731095lab.123.1432024074180; Tue, 19 May 2015 01:27:54 -0700 (PDT) Received: from mail-la0-f41.google.com (mail-la0-f41.google.com. [209.85.215.41]) by mx.google.com with ESMTPS id tp6si8376426lbb.97.2015.05.19.01.27.54 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 May 2015 01:27:54 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.41 as permitted sender) client-ip=209.85.215.41; Received: by laat2 with SMTP id t2so11705939laa.1 for ; Tue, 19 May 2015 01:27:54 -0700 (PDT) X-Received: by 10.152.27.105 with SMTP id s9mr10473348lag.86.1432024074068; Tue, 19 May 2015 01:27:54 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp627028lbb; Tue, 19 May 2015 01:27:53 -0700 (PDT) X-Received: by 10.55.24.39 with SMTP id j39mr43233599qkh.60.1432024072781; Tue, 19 May 2015 01:27:52 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id c7si11424460qcc.48.2015.05.19.01.27.52 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 19 May 2015 01:27:52 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:44440 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YucsR-0004Ps-O9 for patch@linaro.org; Tue, 19 May 2015 04:27:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33822) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yucol-0006G7-6a for qemu-devel@nongnu.org; Tue, 19 May 2015 04:24:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yucoh-0006Gz-Sr for qemu-devel@nongnu.org; Tue, 19 May 2015 04:24:03 -0400 Received: from mnementh.archaic.org.uk ([2001:8b0:1d0::1]:34176) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yucoh-0006GF-LM for qemu-devel@nongnu.org; Tue, 19 May 2015 04:23:59 -0400 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1Yucod-0000bC-TE; Tue, 19 May 2015 09:23:55 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Tue, 19 May 2015 09:23:46 +0100 Message-Id: <1432023835-2274-2-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1432023835-2274-1-git-send-email-peter.maydell@linaro.org> References: <1432023835-2274-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:8b0:1d0::1 Cc: =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [PULL 01/10] ui/cocoa: Fix several full screen issues on Mac OS X X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.41 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Programmingkid 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 [PMM: minor whitespace tweaks, remove incorrectly duplicated use of 'f' menu accelerator key] Signed-off-by: Peter Maydell --- ui/cocoa.m | 49 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index d37c29b..351b71f 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -64,6 +64,7 @@ static int last_buttons; int gArgc; char **gArgv; +bool stretch_video; // keymap conversion int keymap[] = @@ -418,6 +419,18 @@ QemuCocoaView *cocoaView; if (isFullscreen) { cdx = [[NSScreen mainScreen] frame].size.width / (float)screen.width; 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; ch = screen.height * cdy; cx = ([[NSScreen mainScreen] frame].size.width - cw) / 2.0; @@ -502,6 +515,7 @@ QemuCocoaView *cocoaView; #endif } else { // switch from desktop to fullscreen isFullscreen = TRUE; + [normalWindow orderOut: nil]; /* Hide the window */ [self grabMouse]; [self setContentDimensions]; // test if host supports "enterFullScreenMode:withOptions" at compile time @@ -518,8 +532,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 >= MAC_OS_X_VERSION_10_5) } @@ -561,7 +578,7 @@ QemuCocoaView *cocoaView; } // 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 +815,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 @implementation QemuCocoaAppController @@ -832,7 +851,7 @@ QemuCocoaView *cocoaView; [normalWindow useOptimizedDrawing:YES]; [normalWindow makeKeyAndOrderFront:self]; [normalWindow center]; - + stretch_video = false; } return self; } @@ -921,6 +940,16 @@ 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 +972,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 = !stretch_video; + if (stretch_video == true) { + [sender setState: NSOnState]; + } else { + [sender setState: NSOffState]; + } +} @end @@ -1005,7 +1045,8 @@ int main (int argc, const char * argv[]) { // View menu 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 setSubmenu:menu]; [[NSApp mainMenu] addItem:menuItem];