Received: from eggs.gnu.org ([2001:4830:134:3::10]:59399) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yrbe5-0007tM-VT for qemu-devel@nongnu.org; Sun, 10 May 2015 20:32:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yrbe0-00068b-FG for qemu-devel@nongnu.org; Sun, 10 May 2015 20:32:33 -0400 Received: from mail-qk0-x231.google.com ([2607:f8b0:400d:c09::231]:33715) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yrbe0-00068T-7X for qemu-devel@nongnu.org; Sun, 10 May 2015 20:32:28 -0400 Received: by qkx62 with SMTP id 62so78099116qkx.0 for ; Sun, 10 May 2015 17:32:27 -0700 (PDT) From: Programmingkid Content-Type: multipart/alternative; boundary=Apple-Mail-1--121904697 Date: Sun, 10 May 2015 20:32:24 -0400 Message-Id: Mime-Version: 1.0 (Apple Message framework v1084) Subject: [Qemu-devel] [PATCH v4] ui/cocoa.m: Adds console items to the View menu List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: qemu-devel qemu-devel --Apple-Mail-1--121904697 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii This patch adds the VGA, Monitor, Serial, and Parallel menu item to the = view menu.=20 Signed-off-by: John Arbuckle --- Removed all code added in console.c. Used existing console code in place of new console code. Added several console global variables to keep track of usable consoles.=20= Simplified console switching code.=20 ui/cocoa.m | 94 = ++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 86 insertions(+), 8 deletions(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index d37c29b..8760fb0 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -64,6 +64,8 @@ static int last_buttons; =20 int gArgc; char **gArgv; +int graphics_console, monitor_console, serial_console, = parallel_console; + =20 // keymap conversion int keymap[] =3D @@ -801,6 +803,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,8 +949,32 @@ QemuCocoaView *cocoaView; [[NSWorkspace sharedWorkspace] openFile:[NSString = stringWithFormat:@"%@/../doc/qemu/qemu-tech.html", [[NSBundle mainBundle] resourcePath]] withApplication:@"Help = Viewer"]; } -@end =20 +/* Displays the VGA screen */ +- (void)displayVGA:(id)sender +{ + console_select(graphics_console); +} + +/* Displays the QEMU Monitor screen */ +- (void)displayMonitor:(id)sender +{ + console_select(monitor_console); +} + +/* Displays the serial port screen */ +- (void)displaySerial:(id)sender +{ + console_select(serial_console); +} + +/* Displays the parallel port screen */ +- (void)displayParallel:(id)sender +{ + console_select(parallel_console); +} + +@end =20 =20 int main (int argc, const char * argv[]) { @@ -1003,13 +1033,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 +1139,57 @@ 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(graphics_console !=3D -1) + [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"VGA" = action:@selector(displayVGA:) keyEquivalent:@""] autorelease]]; // VGA + if(monitor_console !=3D -1) + [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"QEMU = Monitor" action:@selector(displayMonitor:) keyEquivalent:@""] = autorelease]]; // QEMU Monitor + if(serial_console !=3D -1) + [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Serial" = action:@selector(displaySerial:) keyEquivalent:@""] autorelease]]; // = Serial + if(parallel_console !=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 +} + +// sets the console variables to the actual console' indexes +static void init_console_variables() +{ + int index =3D 0; + char * console_name; + + // set the console variables to -1 so we know which ones do not = exist + graphics_console =3D -1; + monitor_console =3D -1; + serial_console =3D -1; + parallel_console =3D -1; + + // set the console variables for the consoles we have + while(qemu_console_lookup_by_index(index) !=3D NULL) { + console_name =3D = qemu_console_get_label(qemu_console_lookup_by_index(index)); + if(strstr(console_name, "VGA") !=3D NULL) { + graphics_console =3D index; + } else if (strstr(console_name, "monitor") !=3D NULL) { + monitor_console =3D index; + } else if (strstr(console_name, "serial") !=3D NULL) { + serial_console =3D index; + } else if (strstr(console_name, "parallel") !=3D NULL) { + parallel_console =3D index; + } else { + printf("Error in initConsoleVariables(): given value %s\n", = console_name); + } + index++; + } +} + void cocoa_display_init(DisplayState *ds, int full_screen) { COCOA_DEBUG("qemu_cocoa: cocoa_display_init\n"); @@ -1128,4 +1202,8 @@ void cocoa_display_init(DisplayState *ds, int = full_screen) =20 // register cleanup function atexit(cocoa_cleanup); + + // QEMU needs to be running first before we can create the view = menu + init_console_variables(); + create_view_menu(); } --=20 1.7.5.4 --Apple-Mail-1--121904697 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii
This = patch adds the VGA, Monitor, Serial, and Parallel menu item to the view = menu. 

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

---
Removed all code added in = console.c.
Used existing console code in place of new console = code.
Added several console global variables to keep = track of usable consoles. 
Simplified console switching = code. 

 ui/cocoa.m |   94 = ++++++++++++++++++++++++++++++++++++++++++++++++++++++-----

diff --git a/ui/cocoa.m = b/ui/cocoa.m
index d37c29b..8760fb0 100644
--- = a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -64,6 +64,8 @@ static int = last_buttons;

 

 int gArgc;
+int graphics_console, monitor_console, = serial_console, parallel_console;
+

 

 // keymap conversion
@@ -801,6 +803,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

 

@@ = -943,8 +949,32 @@ QemuCocoaView *cocoaView;
     = [[NSWorkspace sharedWorkspace] openFile:[NSString = stringWithFormat:@"%@/../doc/qemu/qemu-tech.html",
-@end

 

+/* Displays the VGA screen = */
+{
+    = console_select(graphics_console);
+}
+
+/* Displays the QEMU Monitor = screen */
+- (void)displayMonitor:(id)sender
+    = console_select(monitor_console);
+}
+
+/* Displays the serial port = screen */
+- (void)displaySerial:(id)sender
+    = console_select(serial_console);
+}
+
+/* Displays the parallel port = screen */
+- (void)displayParallel:(id)sender
+    = console_select(parallel_console);
+}
+
+@end

 

 

@@ = -1003,13 +1033,6 @@ int main (int argc, const char * argv[]) {
 

-    // View menu
-    [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 addItem: = [[[NSMenuItem alloc] initWithTitle:@"Minimize" = action:@selector(performMiniaturize:) keyEquivalent:@"m"] autorelease]]; = // Miniaturize
@@ -1116,6 +1139,57 @@ static const = DisplayChangeListenerOps dcl_ops =3D {
     = .dpy_refresh =3D cocoa_refresh,
 };

 

+// = Creates the view menu
+static void create_view_menu()
+    NSMenu * menu;
+    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(graphics_console !=3D= -1)
+        [menu addItem: = [[[NSMenuItem alloc] initWithTitle:@"VGA" action:@selector(displayVGA:) = keyEquivalent:@""] autorelease]]; // VGA
+    = if(monitor_console !=3D -1)
+        [menu = addItem: [[[NSMenuItem alloc] initWithTitle:@"QEMU Monitor" = action:@selector(displayMonitor:) keyEquivalent:@""] autorelease]]; // = QEMU Monitor
+    if(serial_console !=3D -1)
+    = if(parallel_console !=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
+}
+
+// sets the console variables to the = actual console' indexes
+static void = init_console_variables()
+{
+    int index =3D = 0;
+
+    // set the = console variables to -1 so we know which ones do not exist
+    monitor_console = =3D -1;
+    serial_console =3D -1;
+
+    // set the = console variables for the consoles we have
+    = while(qemu_console_lookup_by_index(index) !=3D NULL) {
+        } else if = (strstr(console_name, "monitor") !=3D NULL) {
+        } else if = (strstr(console_name, "serial") !=3D NULL) {
+        } else if = (strstr(console_name, "parallel") !=3D NULL) {
+        } else {
+        = index++;
+    }
+}
 void cocoa_display_init(DisplayState *ds, int = full_screen)
 {
     = COCOA_DEBUG("qemu_cocoa: cocoa_display_init\n");
@@ = -1128,4 +1202,8 @@ void cocoa_display_init(DisplayState *ds, int = full_screen)

 

     // register = cleanup function
     = atexit(cocoa_cleanup);
+
+    // QEMU needs to be running first = before we can create the view menu
+    = init_console_variables();
+    = create_view_menu();
 }
-- 
1.7.5.4

= --Apple-Mail-1--121904697--