From patchwork Sat Feb 14 05:48:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Programmingkid X-Patchwork-Id: 439699 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 50AAF140145 for ; Sat, 14 Feb 2015 16:48:40 +1100 (AEDT) Received: from localhost ([::1]:58859 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YMVao-0000xr-JA for incoming@patchwork.ozlabs.org; Sat, 14 Feb 2015 00:48:38 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47249) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YMVaW-0000cw-Lv for qemu-devel@nongnu.org; Sat, 14 Feb 2015 00:48:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YMVaS-0004nG-Ml for qemu-devel@nongnu.org; Sat, 14 Feb 2015 00:48:20 -0500 Received: from mail-qc0-x22f.google.com ([2607:f8b0:400d:c01::22f]:48029) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YMVaS-0004nA-Hz for qemu-devel@nongnu.org; Sat, 14 Feb 2015 00:48:16 -0500 Received: by mail-qc0-f175.google.com with SMTP id b13so11331302qcw.6 for ; Fri, 13 Feb 2015 21:48:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:mime-version:content-type:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=xzWei++rJLFYNO3tE1qQhMvpfGMDThMfiREvT15PMhk=; b=z4MdyvGR6Ky5xMgB8mCaSl2iHCrgDgSlrXpUzFD/0atvVtAnKh+kwGeNBMeg11eDdq lpXhCeta5wtFXD64y1tiHTj/cGdA3xtPN267fY+4eJCPPVLxrR7jFF0H0MfOBrdBvLVn zm+D1+badPEQf1PPfSzMyEkRpA512Fjjv2+MZX6LqglRPaAQXs5pg6bEflsePe8rPOPS lk5sUft8i355poCqOugNMUyk1FfhDliJe6dHyCQYLxM9KWUm7l3QJZdHbipI/n0VUiW6 lntNkq3RFDqDg/HeWMWfDueXfCzUOTvUk/V9l+D7c09+SOz2tiAex5OWYjZyLCyNGcy1 aMQQ== X-Received: by 10.140.150.144 with SMTP id 138mr3273359qhw.69.1423892896070; Fri, 13 Feb 2015 21:48:16 -0800 (PST) Received: from [192.168.0.4] (d199-74-164-53.col.wideopenwest.com. [74.199.53.164]) by mx.google.com with ESMTPSA id g51sm8844736qgf.18.2015.02.13.21.48.14 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Feb 2015 21:48:15 -0800 (PST) Mime-Version: 1.0 (Apple Message framework v1084) From: Programmingkid In-Reply-To: <1423813551.25119.6.camel@nilsson.home.kraxel.org> Date: Sat, 14 Feb 2015 00:48:13 -0500 Message-Id: <0CB6812F-9AB8-4EFC-9E77-E7DE4D95025D@gmail.com> References: <82FF5E7D-9716-476C-BBA5-56223DCB6023@gmail.com> <1423813551.25119.6.camel@nilsson.home.kraxel.org> To: Gerd Hoffmann X-Mailer: Apple Mail (2.1084) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400d:c01::22f Cc: Peter Maydell , qemu-devel qemu-devel Subject: [Qemu-devel] [PATCH v2] ui/cocoa.m: Adds console items to the View menu X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Adds these items to the View menu: VGA Monitor Serial Parallel Signed-off-by: John Arbuckle --- Implemented new function that gives you the index for a given console name. Moved View menu code to its own function. Console menu items are now checked before being adding to the View menu. include/ui/console.h | 1 + ui/cocoa.m | 61 ++++++++++++++++++++++++++++++++++++++++++++----- ui/console.c | 38 +++++++++++++++++++++++++++++++ 3 files changed, 93 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..54012b6 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,32 @@ 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(1); + 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 +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,27 @@ 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(get_console_index("graphic") != -1) + [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"VGA" action:@selector(displayVGA:) keyEquivalent:@""] autorelease]]; // VGA + if(get_console_index("monitor") != -1) + [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"QEMU Monitor" action:@selector(displayMonitor:) keyEquivalent:@""] autorelease]]; // QEMU Monitor + if (get_console_index("serial") != -1) + [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Serial" action:@selector(displaySerial:) keyEquivalent:@""] autorelease]]; // Serial + if(get_console_index("parallel") != -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 +} + void cocoa_display_init(DisplayState *ds, int full_screen) { COCOA_DEBUG("qemu_cocoa: cocoa_display_init\n"); @@ -1128,4 +1172,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) } 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) == 0) { + for (i = 0; i < nb_consoles; i++) { + /* If we found the console */ + if (consoles[i]->console_type == 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 = 0; i < nb_consoles; i++) { + chr = consoles[i]->chr; + + /* Can't do anything but skip it */ + if (chr == NULL) { + continue; + } + /* If we found the console */ + if (strstr(chr->label, name)) { + return i; + } + } + + /* Could not find console */ + return -1; +}