Received: from eggs.gnu.org ([2001:4830:134:3::10]:52356) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YMezs-0003pm-F5 for qemu-devel@nongnu.org; Sat, 14 Feb 2015 10:51:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YMezo-00082p-9a for qemu-devel@nongnu.org; Sat, 14 Feb 2015 10:51:08 -0500 Received: from mail-qa0-x22a.google.com ([2607:f8b0:400d:c00::22a]:44950) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YMezo-00082f-3R for qemu-devel@nongnu.org; Sat, 14 Feb 2015 10:51:04 -0500 Received: by mail-qa0-f42.google.com with SMTP id w8so16337684qac.1 for ; Sat, 14 Feb 2015 07:51:03 -0800 (PST) Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: multipart/alternative; boundary=Apple-Mail-1--1054738944 From: Programmingkid In-Reply-To: Date: Sat, 14 Feb 2015 10:50:59 -0500 Message-Id: <6B2F4FEE-33BA-45A5-97E1-09213E2AF1E6@gmail.com> References: Subject: [Qemu-devel] [PATCH v3] ui/cocoa.m: Adds console items to the View menu List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell --Apple-Mail-1--1054738944 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Adds these items to the View menu: VGA Monitor Serial Parallel Signed-off-by: John Arbuckle --- Removed commented out code. include/ui/console.h | 1 + ui/cocoa.m | 60 = ++++++++++++++++++++++++++++++++++++++++++++----- ui/console.c | 38 +++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 7 deletions(-) diff --git a/include/ui/console.h b/include/ui/console.h index 8a4d671..efe5517 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -323,6 +323,7 @@ void qemu_console_copy(QemuConsole *con, int src_x, = int src_y, int dst_x, int dst_y, int w, int h); DisplaySurface *qemu_console_surface(QemuConsole *con); DisplayState *qemu_console_displaystate(QemuConsole *console); +int get_console_index(const char *name); =20 /* sdl.c */ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame); diff --git a/ui/cocoa.m b/ui/cocoa.m index d37c29b..14f0503 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -801,6 +801,10 @@ QemuCocoaView *cocoaView; - (void)toggleFullScreen:(id)sender; - (void)showQEMUDoc:(id)sender; - (void)showQEMUTec:(id)sender; +- (void)displayVGA:(id)sender; +- (void)displayMonitor:(id)sender; +- (void)displayParallel:(id)sender; +- (void)displaySerial:(id)sender; @end =20 @implementation QemuCocoaAppController @@ -943,6 +947,31 @@ QemuCocoaView *cocoaView; [[NSWorkspace sharedWorkspace] openFile:[NSString = stringWithFormat:@"%@/../doc/qemu/qemu-tech.html", [[NSBundle mainBundle] resourcePath]] withApplication:@"Help = Viewer"]; } + +/* Displays the VGA screen */ +- (void)displayVGA:(id)sender +{ + console_select(get_console_index("graphic")); +} + +/* Displays the QEMU Monitor screen */ +- (void)displayMonitor:(id)sender +{ + console_select(get_console_index("monitor")); +} + +/* Displays the serial port screen */ +- (void)displaySerial:(id)sender +{ + console_select(get_console_index("serial")); +} + +/* Displays the parallel port screen */ +- (void)displayParallel:(id)sender +{ + console_select(get_console_index("parallel")); +} + @end =20 =20 @@ -1003,13 +1032,6 @@ int main (int argc, const char * argv[]) { [[NSApp mainMenu] addItem:menuItem]; [NSApp performSelector:@selector(setAppleMenu:) withObject:menu]; = // Workaround (this method is private since 10.4+) =20 - // View menu - menu =3D [[NSMenu alloc] initWithTitle:@"View"]; - [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Enter = Fullscreen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"] = autorelease]]; // Fullscreen - menuItem =3D [[[NSMenuItem alloc] initWithTitle:@"View" action:nil = keyEquivalent:@""] autorelease]; - [menuItem setSubmenu:menu]; - [[NSApp mainMenu] addItem:menuItem]; - // Window menu menu =3D [[NSMenu alloc] initWithTitle:@"Window"]; [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Minimize" = action:@selector(performMiniaturize:) keyEquivalent:@"m"] autorelease]]; = // Miniaturize @@ -1116,6 +1138,27 @@ static const DisplayChangeListenerOps dcl_ops =3D = { .dpy_refresh =3D cocoa_refresh, }; =20 +// Creates the view menu +static void create_view_menu() +{ + NSMenu * menu; + NSMenuItem * menuItem; + menu =3D [[NSMenu alloc] initWithTitle:@"View"]; + [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Enter = Fullscreen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"] = autorelease]]; // Fullscreen + [menu addItem:[NSMenuItem separatorItem]]; //Separator + if(get_console_index("graphic") !=3D -1) + [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"VGA" = action:@selector(displayVGA:) keyEquivalent:@""] autorelease]]; // VGA + if(get_console_index("monitor") !=3D -1) + [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"QEMU = Monitor" action:@selector(displayMonitor:) keyEquivalent:@""] = autorelease]]; // QEMU Monitor + if (get_console_index("serial") !=3D -1) + [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Serial" = action:@selector(displaySerial:) keyEquivalent:@""] autorelease]]; // = Serial + if(get_console_index("parallel") !=3D -1) + [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Parallel" = action:@selector(displayParallel:) keyEquivalent:@""] autorelease]]; // = Parallel + menuItem =3D [[[NSMenuItem alloc] initWithTitle:@"View" action:nil = keyEquivalent:@""] autorelease]; + [menuItem setSubmenu:menu]; + [[NSApp mainMenu] insertItem: menuItem atIndex: 1]; // insert View = menu after Application menu +} + void cocoa_display_init(DisplayState *ds, int full_screen) { COCOA_DEBUG("qemu_cocoa: cocoa_display_init\n"); @@ -1128,4 +1171,7 @@ void cocoa_display_init(DisplayState *ds, int = full_screen) =20 // register cleanup function atexit(cocoa_cleanup); + + // called here because QEMU needs to be running first + create_view_menu(); } diff --git a/ui/console.c b/ui/console.c index 87574a7..620a029 100644 --- a/ui/console.c +++ b/ui/console.c @@ -2071,3 +2071,41 @@ static void register_types(void) } =20 type_init(register_types); + +/* + Returns the console index associated with the name. + name can be graphic, monitor, serial, or parallel. +*/ +int get_console_index(const char *name) +{ + int i; + /* If looking for the graphic console */ + if (strcmp("graphic", name) =3D=3D 0) { + for (i =3D 0; i < nb_consoles; i++) { + /* If we found the console */ + if (consoles[i]->console_type =3D=3D GRAPHIC_CONSOLE) { + return i; + } + } + /* If we failed to find the console */ + return -1; + } + + /* If looking for QEMU monitor, serial, or parallel console */ + CharDriverState *chr; + for (i =3D 0; i < nb_consoles; i++) { + chr =3D consoles[i]->chr; + + /* Can't do anything but skip it */ + if (chr =3D=3D NULL) { + continue; + } + /* If we found the console */ + if (strstr(chr->label, name)) { + return i; + } + } + + /* Could not find console */ + return -1; +} --=20 1.7.5.4 --Apple-Mail-1--1054738944 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii Adds these = items to the View = menu:
VGA
Monitor
Serial
Parallel

Signed-off-by: John = Arbuckle <programmingkidx@gmail.com>= ;

---
Removed commented out = code.

 include/ui/console.h |   =  1 +
 ui/cocoa.m           = |   60 = ++++++++++++++++++++++++++++++++++++++++++++-----
 ui/conso= le.c         |   38 = +++++++++++++++++++++++++++++++
 3 files changed, 92 = insertions(+), 7 deletions(-)

diff --git = a/include/ui/console.h b/include/ui/console.h
index = 8a4d671..efe5517 100644
--- = a/include/ui/console.h
+++ b/include/ui/console.h
@@ = -323,6 +323,7 @@ void qemu_console_copy(QemuConsole *con, int src_x, int = src_y,
                =         int dst_x, int dst_y, int w, int = h);
 DisplaySurface *qemu_console_surface(QemuConsole = *con);
 DisplayState = *qemu_console_displaystate(QemuConsole *console);
+int = get_console_index(const char *name);
 
 /* = sdl.c */
 void sdl_display_init(DisplayState *ds, int = full_screen, int no_frame);
diff --git a/ui/cocoa.m = b/ui/cocoa.m
index d37c29b..14f0503 100644
--- = a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -801,6 +801,10 @@ = QemuCocoaView *cocoaView;
 - = (void)toggleFullScreen:(id)sender;
 - = (void)showQEMUDoc:(id)sender;
 - = (void)showQEMUTec:(id)sender;
+- = (void)displayVGA:(id)sender;
+- = (void)displayMonitor:(id)sender;
+- = (void)displayParallel:(id)sender;
+- = (void)displaySerial:(id)sender;
 @end
 
 @implementation QemuCocoaAppController
@@ -943,6 = +947,31 @@ QemuCocoaView *cocoaView;
    =  [[NSWorkspace sharedWorkspace] openFile:[NSString = stringWithFormat:@"%@/../doc/qemu/qemu-tech.html",
  =        [[NSBundle mainBundle] resourcePath]] = withApplication:@"Help = Viewer"];
 }
+
+/* Displays the VGA = screen */
+- = (void)displayVGA:(id)sender
+{
+   =  console_select(get_console_index("graphic"));
+}
+
+/* Displays the QEMU Monitor screen */
+- = (void)displayMonitor:(id)sender
+{
+   =  console_select(get_console_index("monitor"));
+}
+
+/* Displays the serial port screen */
+- = (void)displaySerial:(id)sender
+{
+   =  console_select(get_console_index("serial"));
+}
= +
+/* Displays the parallel port screen */
+- = (void)displayParallel:(id)sender
+{
+   =  console_select(get_console_index("parallel"));
+}
+
 @end
 
 
@@ = -1003,13 +1032,6 @@ int main (int argc, const char * argv[]) = {
     [[NSApp mainMenu] = addItem:menuItem];
     [NSApp = performSelector:@selector(setAppleMenu:) withObject:menu]; // Workaround = (this method is private since 10.4+)
 
-   =  // View menu
-    menu =3D [[NSMenu alloc] = initWithTitle:@"View"];
-    [menu addItem: = [[[NSMenuItem alloc] initWithTitle:@"Enter Fullscreen" = action:@selector(toggleFullScreen:) keyEquivalent:@"f"] autorelease]]; = // Fullscreen
-    menuItem =3D [[[NSMenuItem alloc] = initWithTitle:@"View" action:nil keyEquivalent:@""] = autorelease];
-    [menuItem = setSubmenu:menu];
-    [[NSApp mainMenu] = addItem:menuItem];
-
     // Window = menu
     menu =3D [[NSMenu alloc] = initWithTitle:@"Window"];
     [menu addItem: = [[[NSMenuItem alloc] initWithTitle:@"Minimize" = action:@selector(performMiniaturize:) keyEquivalent:@"m"] autorelease]]; = // Miniaturize
@@ -1116,6 +1138,27 @@ static const = DisplayChangeListenerOps dcl_ops =3D {
    =  .dpy_refresh =3D = cocoa_refresh,
 };
 
+// Creates = the view menu
+static void = create_view_menu()
+{
+    NSMenu * = menu;
+    NSMenuItem * menuItem;
+   =  menu =3D [[NSMenu alloc] initWithTitle:@"View"];
+ =    [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Enter = Fullscreen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"] = autorelease]]; // Fullscreen
+    [menu = addItem:[NSMenuItem separatorItem]]; //Separator
+   =  if(get_console_index("graphic") !=3D -1)
+     =    [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"VGA" = action:@selector(displayVGA:) keyEquivalent:@""] autorelease]]; // = VGA
+    if(get_console_index("monitor") !=3D = -1)
+        [menu addItem: [[[NSMenuItem = alloc] initWithTitle:@"QEMU Monitor" action:@selector(displayMonitor:) = keyEquivalent:@""] autorelease]]; // QEMU Monitor
+   =  if (get_console_index("serial") !=3D -1)
+     =    [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Serial" = action:@selector(displaySerial:) keyEquivalent:@""] autorelease]]; // = Serial
+    if(get_console_index("parallel") !=3D = -1)
+        [menu addItem: [[[NSMenuItem = alloc] initWithTitle:@"Parallel" action:@selector(displayParallel:) = keyEquivalent:@""] autorelease]]; // Parallel
+   =  menuItem =3D [[[NSMenuItem alloc] initWithTitle:@"View" action:nil = keyEquivalent:@""] autorelease];
+    [menuItem = setSubmenu:menu];
+    [[NSApp mainMenu] insertItem: = menuItem atIndex: 1]; // insert View menu after Application = menu
+}
+
 void = cocoa_display_init(DisplayState *ds, int = full_screen)
 {
    =  COCOA_DEBUG("qemu_cocoa: cocoa_display_init\n");
@@ = -1128,4 +1171,7 @@ void cocoa_display_init(DisplayState *ds, int = full_screen)
 
     // register = cleanup function
    =  atexit(cocoa_cleanup);
+
+    // = called here because QEMU needs to be running first
+   =  create_view_menu();
 }
diff --git = a/ui/console.c b/ui/console.c
index 87574a7..620a029 = 100644
--- a/ui/console.c
+++ = b/ui/console.c
@@ -2071,3 +2071,41 @@ static void = register_types(void)
 }
 
 ty= pe_init(register_types);
+
+/*
+   =  Returns the console index associated with the name.
+ =    name can be graphic, monitor, serial, or = parallel.
+*/
+int get_console_index(const char = *name)
+{
+    int i;
+   =  /* If looking for the graphic console */
+   =  if (strcmp("graphic", name) =3D=3D 0) {
+     =    for (i =3D 0; i < nb_consoles; i++) {
+   =          /* If we found the console = */
+            if = (consoles[i]->console_type =3D=3D GRAPHIC_CONSOLE) {
+ =                return = i;
+            }
+ =        }
+        /* = If we failed to find the console */
+       =  return -1;
+    }
+
+ =    /* If looking for QEMU monitor, serial, or parallel console = */
+    CharDriverState *chr;
+   =  for (i =3D 0; i < nb_consoles; i++) {
+     =    chr =3D consoles[i]->chr;
+
+   =      /* Can't do anything but skip it */
+ =        if (chr =3D=3D NULL) {
+   =          continue;
+     =    }
+        /* If we found the = console */
+        if = (strstr(chr->label, name)) {
+         =    return i;
+       =  }
+    }
+
+   =  /* Could not find console */
+    return = -1;
+}
-- 
1.7.5.4

= = --Apple-Mail-1--1054738944--