qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH v4] ui/cocoa.m: Adds console items to the View menu


From: Programmingkid
Subject: [Qemu-devel] [PATCH v4] ui/cocoa.m: Adds console items to the View menu
Date: Sun, 10 May 2015 20:32:24 -0400

This patch adds the VGA, Monitor, Serial, and Parallel menu item to the view menu. 

Signed-off-by: John Arbuckle <address@hidden>

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

 

 int gArgc;
 char **gArgv;
+int graphics_console, monitor_console, serial_console, parallel_console;
+

 

 // keymap conversion
 int keymap[] =
@@ -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

 

 @implementation QemuCocoaAppController
@@ -943,8 +949,32 @@ QemuCocoaView *cocoaView;
     [[NSWorkspace sharedWorkspace] openFile:[NSString stringWithFormat:@"%@/../doc/qemu/qemu-tech.html",
         [[NSBundle mainBundle] resourcePath]] withApplication:@"Help Viewer"];
 }
address@hidden

 

+/* 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);
+}
+
address@hidden

 

 

 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+)

 

-    // View menu
-    menu = [[NSMenu alloc] initWithTitle:@"View"];
-    [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Enter Fullscreen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"] autorelease]]; // Fullscreen
-    menuItem = [[[NSMenuItem alloc] initWithTitle:@"View" action:nil keyEquivalent:@""] autorelease];
-    [menuItem setSubmenu:menu];
-    [[NSApp mainMenu] addItem:menuItem];
-
     // Window menu
     menu = [[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 = {
     .dpy_refresh = cocoa_refresh,
 };

 

+// Creates the view menu
+static void create_view_menu()
+{
+    NSMenu * menu;
+    NSMenuItem * menuItem;
+    menu = [[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 != -1)
+        [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"VGA" action:@selector(displayVGA:) keyEquivalent:@""] autorelease]]; // VGA
+    if(monitor_console != -1)
+        [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"QEMU Monitor" action:@selector(displayMonitor:) keyEquivalent:@""] autorelease]]; // QEMU Monitor
+    if(serial_console != -1)
+        [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Serial" action:@selector(displaySerial:) keyEquivalent:@""] autorelease]]; // Serial
+    if(parallel_console != -1)
+        [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Parallel" action:@selector(displayParallel:) keyEquivalent:@""] autorelease]]; // Parallel
+    menuItem = [[[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 = 0;
+    char * console_name;
+
+    // set the console variables to -1 so we know which ones do not exist
+    graphics_console = -1;
+    monitor_console = -1;
+    serial_console = -1;
+    parallel_console = -1;
+
+    // set the console variables for the consoles we have
+    while(qemu_console_lookup_by_index(index) != NULL) {
+        console_name = qemu_console_get_label(qemu_console_lookup_by_index(index));
+        if(strstr(console_name, "VGA") != NULL) {
+            graphics_console = index;
+        } else if (strstr(console_name, "monitor") != NULL) {
+            monitor_console = index;
+        } else if (strstr(console_name, "serial") != NULL) {
+            serial_console = index;
+        } else if (strstr(console_name, "parallel") != NULL) {
+            parallel_console = 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)

 

     // 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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]