diff mbox series

[v2,3/7] ui/cocoa: Factor out initial menu creation

Message ID 20190214102816.3393-4-peter.maydell@linaro.org
State Superseded
Headers show
Series ui/cocoa: Use OSX's main loop | expand

Commit Message

Peter Maydell Feb. 14, 2019, 10:28 a.m. UTC
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 <peter.maydell@linaro.org>

---
 ui/cocoa.m | 78 ++++++++++++++++++++++++++++--------------------------
 1 file changed, 41 insertions(+), 37 deletions(-)

-- 
2.17.2 (Apple Git-113)

Comments

BALATON Zoltan Feb. 14, 2019, 5:11 p.m. UTC | #1
On Thu, 14 Feb 2019, Peter Maydell wrote:
> 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 <peter.maydell@linaro.org>


Reviewed-by: BALATON Zoltan <balaton@eik.bme.hu>


Regards,
BALATON Zoltan

> ---

> ui/cocoa.m | 78 ++++++++++++++++++++++++++++--------------------------

> 1 file changed, 41 insertions(+), 37 deletions(-)

>

> diff --git a/ui/cocoa.m b/ui/cocoa.m

> index 9d23732ff9..0b1cd31543 100644

> --- a/ui/cocoa.m

> +++ b/ui/cocoa.m

> @@ -1461,43 +1461,8 @@ - (void)adjustSpeed:(id)sender

>

> @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;

> @@ -1581,6 +1546,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];

>
Roman Bolshakov Feb. 22, 2019, 5:47 p.m. UTC | #2
On Thu, Feb 14, 2019 at 10:28:12AM +0000, Peter Maydell wrote:
> 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 <peter.maydell@linaro.org>

> ---

>  ui/cocoa.m | 78 ++++++++++++++++++++++++++++--------------------------

>  1 file changed, 41 insertions(+), 37 deletions(-)

> 


Reviewed-by: Roman Bolshakov <r.bolshakov@yadro.com>

Tested-by: Roman Bolshakov <r.bolshakov@yadro.com>


--
Roman
diff mbox series

Patch

diff --git a/ui/cocoa.m b/ui/cocoa.m
index 9d23732ff9..0b1cd31543 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -1461,43 +1461,8 @@  - (void)adjustSpeed:(id)sender
 
 @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;
@@ -1581,6 +1546,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];