From patchwork Sat Dec 1 12:30:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 152627 Delivered-To: patches@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp4762384ljp; Sat, 1 Dec 2018 04:30:59 -0800 (PST) X-Google-Smtp-Source: AFSGD/UpH+w/9YQcMxA43nfir9i9f/WH4tlyNDtZXYWSGBu4BgQSEMOLgZs2cPeNJRkICYD5lXIV X-Received: by 2002:a1c:e58c:: with SMTP id c134mr2064493wmh.124.1543667459862; Sat, 01 Dec 2018 04:30:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543667459; cv=none; d=google.com; s=arc-20160816; b=NuOqdVKnh2lzqbwMRUP/OjubeBeaSV5qlOhxYFx/vmF+r5GYsN3MmRDlLb9QEQM2/E x/yiN0vUN1/SZKVwApGi+Cm9YPzEEKAgwXHEuG2mfdWh7NSmWNBrSJOSYcw4QBEfwZvG 4jWkUU4A6epRiUIv2+Eo4oLDfOsWiKcxNkBDGcB3gcVzd0ASJ0OTUUGyo1dKzOOFApBL 71HYXKqVovrFLZZzyGcJLyoNiZ37eiSGXyAbrftdzY3o1s/sQl8jiWuIF5jPD56d5R3L npl7sgfObtM1+A0PPls7lpmOVLjdEhUN8SOjM5LbD0b7OUMmpulzCwukIrEQ2AH1LwJU argw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=aKFdDX/HMeBrcew1z6tiY+shi2lGG+U7ZN0NRALLBM4=; b=KRA9BQ74p5unjKky9peWsggMInDU1Ih+u6KV1E6iDWXIDtds8ZGxavL8wR48jy3PId buahF8kOlvgOpdpGv9NBuj27mYbP5TfMbN0DhdHAgkJ6ymcYIrGY8wkyvESaeUmtivBu tVW5HL3ULovwE8PXOXrMvYOckhHe4A4w26NGwaVknkDn+SGI0WaY3o96Qlc8aJWDF9Nu zY0oPJIGqSCa4rNLOuvbN+T6Gv3RDLMfLuBeU6CjvoN7hL3MEFKIYr9XInJImRGoHOih vUFLAGeWyA1vnih/r5DvD0ZFzf2O2l/y22vzh5KMe1Vi8xxwZld70jvlQ5onN5hbxFaz p8Tg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by mx.google.com with ESMTPS id e6si5999417wrr.345.2018.12.01.04.30.59 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 01 Dec 2018 04:30:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) client-ip=2001:8b0:1d0::2; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1gT4QF-0008NS-5k; Sat, 01 Dec 2018 12:30:59 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, John Arbuckle , Berkus Decker , Gerd Hoffmann , Roman Bolshakov Subject: [RFC 3/5] ui/cocoa: Factor out initial menu creation Date: Sat, 1 Dec 2018 12:30:54 +0000 Message-Id: <20181201123056.432-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181201123056.432-1-peter.maydell@linaro.org> References: <20181201123056.432-1-peter.maydell@linaro.org> MIME-Version: 1.0 Factor out the long code sequence in main() which creates the initial set of menus. This will make later patches which move initialization code around a bit clearer. Signed-off-by: Peter Maydell --- ui/cocoa.m | 78 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 37 deletions(-) -- 2.19.2 diff --git a/ui/cocoa.m b/ui/cocoa.m index 997b0199c6c..da511bfb4fa 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -1444,43 +1444,8 @@ QemuCocoaView *cocoaView; @end - -int main (int argc, const char * argv[]) { - - gArgc = argc; - gArgv = (char **)argv; - int i; - - /* In case we don't need to display a window, let's not do that */ - for (i = 1; i < argc; i++) { - const char *opt = argv[i]; - - if (opt[0] == '-') { - /* Treat --foo the same as -foo. */ - if (opt[1] == '-') { - opt++; - } - if (!strcmp(opt, "-h") || !strcmp(opt, "-help") || - !strcmp(opt, "-vnc") || - !strcmp(opt, "-nographic") || - !strcmp(opt, "-version") || - !strcmp(opt, "-curses") || - !strcmp(opt, "-display") || - !strcmp(opt, "-qtest")) { - return qemu_main(gArgc, gArgv, *_NSGetEnviron()); - } - } - } - - NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; - - // Pull this console process up to being a fully-fledged graphical - // app with a menubar and Dock icon - ProcessSerialNumber psn = { 0, kCurrentProcess }; - TransformProcessType(&psn, kProcessTransformToForegroundApplication); - - [NSApplication sharedApplication]; - +static void create_initial_menus(void) +{ // Add menus NSMenu *menu; NSMenuItem *menuItem; @@ -1564,6 +1529,45 @@ int main (int argc, const char * argv[]) { menuItem = [[[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""] autorelease]; [menuItem setSubmenu:menu]; [[NSApp mainMenu] addItem:menuItem]; +} + +int main (int argc, const char * argv[]) { + + gArgc = argc; + gArgv = (char **)argv; + int i; + + /* In case we don't need to display a window, let's not do that */ + for (i = 1; i < argc; i++) { + const char *opt = argv[i]; + + if (opt[0] == '-') { + /* Treat --foo the same as -foo. */ + if (opt[1] == '-') { + opt++; + } + if (!strcmp(opt, "-h") || !strcmp(opt, "-help") || + !strcmp(opt, "-vnc") || + !strcmp(opt, "-nographic") || + !strcmp(opt, "-version") || + !strcmp(opt, "-curses") || + !strcmp(opt, "-display") || + !strcmp(opt, "-qtest")) { + return qemu_main(gArgc, gArgv, *_NSGetEnviron()); + } + } + } + + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + + // Pull this console process up to being a fully-fledged graphical + // app with a menubar and Dock icon + ProcessSerialNumber psn = { 0, kCurrentProcess }; + TransformProcessType(&psn, kProcessTransformToForegroundApplication); + + [NSApplication sharedApplication]; + + create_initial_menus(); // Create an Application controller QemuCocoaAppController *appController = [[QemuCocoaAppController alloc] init];