From patchwork Thu Nov 12 18:15:37 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Programmingkid X-Patchwork-Id: 38264 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CF0EAB7B77 for ; Fri, 13 Nov 2009 05:16:30 +1100 (EST) Received: from localhost ([127.0.0.1]:46788 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N8eDb-00083V-Eh for incoming@patchwork.ozlabs.org; Thu, 12 Nov 2009 13:16:27 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N8eD8-000822-Ln for qemu-devel@nongnu.org; Thu, 12 Nov 2009 13:15:58 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N8eD3-0007zC-39 for qemu-devel@nongnu.org; Thu, 12 Nov 2009 13:15:57 -0500 Received: from [199.232.76.173] (port=36092 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N8eD2-0007yu-Ra for qemu-devel@nongnu.org; Thu, 12 Nov 2009 13:15:52 -0500 Received: from mail-bw0-f212.google.com ([209.85.218.212]:43150) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N8eD2-0008An-EW for qemu-devel@nongnu.org; Thu, 12 Nov 2009 13:15:52 -0500 Received: by bwz4 with SMTP id 4so2625741bwz.2 for ; Thu, 12 Nov 2009 10:15:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:mime-version :content-transfer-encoding:message-id:content-type:to:from:subject :date:x-mailer; bh=7l/uj5Cqly/EQDgiIfVuPdlkFYmdK1iDBcsoQNcmFN0=; b=pzIGFtuFdglAXB6uH695lJ/UqB26G+l+cVM4+aK4dohghxW9tahx+qUXFfKGY+3KGu YIyL5MqLe7R/UXSj6JIFD6hh9cGR2TZ9uZRiAcLNDiK/TpIeNOqc9gF9xCRJpRVANhhh h89aGzPLlyAHU3CK/RwxgoUokHDyMrQ7MYvg4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:content-transfer-encoding:message-id:content-type:to :from:subject:date:x-mailer; b=C6MP1k24mNqX/Y9Dg5l50devOg+yub1lPuT+kI8FBQpgsMRSbV4klNfrU2e3jrlhOS w1xHzCQXZLWNZWb51BAKMvWNJPiU5cI51giT5F+kLUA20kpVNFKBahnNN3fOuv82NvoY Xg0heG2o+LFfKjwWOwoNumZejnjoihN6rPKR0= Received: by 10.103.81.8 with SMTP id i8mr1192072mul.80.1258049750755; Thu, 12 Nov 2009 10:15:50 -0800 (PST) Received: from ?192.168.0.3? (adsl-99-130-35-128.dsl.sfldmi.sbcglobal.net [99.130.35.128]) by mx.google.com with ESMTPS id s10sm4913372muh.54.2009.11.12.10.15.48 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 12 Nov 2009 10:15:49 -0800 (PST) Mime-Version: 1.0 (Apple Message framework v753.1) Message-Id: To: qemu-devel@nongnu.org From: G 3 Date: Thu, 12 Nov 2009 13:15:37 -0500 X-Mailer: Apple Mail (2.753.1) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: [Qemu-devel] [PATCH] This patch adds a Priority and a Machine menu to the menu bar. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The Priority menu controls how much cpu time qemu receives, and the Machine menu has the Restart menu item for restarting the emulator. Signed-off-by: John Arbuckle --- cocoa.m | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++ +-------- 1 files changed, 79 insertions(+), 12 deletions(-) "exitFullScreenModeWithOptions" is supported on host at runtime [self exitFullScreenModeWithOptions:nil]; } else { @@ -430,7 +440,7 @@ int cocoa_keycode_to_qemu(int keycode) [normalWindow setContentView: self]; [normalWindow makeKeyAndOrderFront: self]; [NSMenu setMenuBarVisible:YES]; -#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) +#if (MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4) } #endif } else { // switch from desktop to fullscreen @@ -438,7 +448,7 @@ int cocoa_keycode_to_qemu(int keycode) [self grabMouse]; [self setContentDimensions]; // test if host support "enterFullScreenMode:withOptions" at compiletime -#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) +#if (MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4) if ([NSView respondsToSelector:@selector (enterFullScreenMode:withOptions:)]) { // test if "enterFullScreenMode:withOptions" is supported on host at runtime [self enterFullScreenMode:[NSScreen mainScreen] withOptions:[NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:NO], NSFullScreenModeAllScreens, @@ -454,7 +464,7 @@ int cocoa_keycode_to_qemu(int keycode) [fullScreenWindow setHasShadow:NO]; [fullScreenWindow setContentView:self]; [fullScreenWindow makeKeyAndOrderFront:self]; -#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) +#if (MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4) } #endif } @@ -696,6 +706,9 @@ int cocoa_keycode_to_qemu(int keycode) - (void)toggleFullScreen:(id)sender; - (void)showQEMUDoc:(id)sender; - (void)showQEMUTec:(id)sender; +- (IBAction) doHighPriorityMenuItem:(id) sender; +- (IBAction) doNormalPriorityMenuItem:(id) sender; +- (IBAction) doRestartMenuItem: (id) sender; @end @implementation QemuCocoaAppController @@ -726,7 +739,8 @@ int cocoa_keycode_to_qemu(int keycode) [normalWindow setContentView:cocoaView]; [normalWindow makeKeyAndOrderFront:self]; [normalWindow center]; - + + qemuAtHighPriority = NO; } return self; } @@ -783,11 +797,10 @@ int cocoa_keycode_to_qemu(int keycode) if(returnCode == NSCancelButton) { exit(0); } else if(returnCode == NSOKButton) { - char *bin = "qemu"; - char *img = (char*)[ [ sheet filename ] cStringUsingEncoding:NSASCIIStringEncoding]; - + char bin[5] = "qemu"; + char *img = (char*)[ [ sheet filename ] cString]; char **argv = (char**)malloc( sizeof(char*)*3 ); - + [sheet close]; asprintf(&argv[0], "%s", bin); asprintf(&argv[1], "-hda"); asprintf(&argv[2], "%s", img); @@ -819,6 +832,32 @@ int cocoa_keycode_to_qemu(int keycode) [[NSWorkspace sharedWorkspace] openFile:[NSString stringWithFormat:@"%@/../doc/qemu/qemu-tech.html", [[NSBundle mainBundle] resourcePath]] withApplication:@"Help Viewer"]; } + +// The action method to the High menu item in the Priority menu +- (IBAction) doHighPriorityMenuItem:(id) sender +{ + #define NORMAL_MENUITEM 1 + qemuAtHighPriority = YES; + [sender setState: NSOnState]; + [[[sender menu] itemAtIndex: NORMAL_MENUITEM] setState: NSOffState]; + qemu_system_reset_request(); +} + +// The action method to the Normal menu item in the Priority menu +- (IBAction) doNormalPriorityMenuItem:(id) sender +{ + #define HIGH_MENUITEM 0 + qemuAtHighPriority = NO; + [sender setState: NSOnState]; + [[[sender menu] itemAtIndex: HIGH_MENUITEM] setState: NSOffState]; +} + +// The action method to the Restart menu item in the Machine menu +- (IBAction) doRestartMenuItem: (id) sender +{ + qemu_system_reset_request(); +} + @end @@ -869,6 +908,24 @@ 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+) + // Priority menu + menu = [[NSMenu alloc] initWithTitle: @"Priority"]; + [menu addItemWithTitle:@"High" action:@selector (doHighPriorityMenuItem:) keyEquivalent:@""]; + [[menu addItemWithTitle:@"Normal" action:@selector (doNormalPriorityMenuItem:) keyEquivalent:@""] setState: NSOnState]; + + menuItem = [[[NSMenuItem alloc] initWithTitle:@"Priority" action:nil keyEquivalent:@""] autorelease]; + [menuItem setSubmenu:menu]; + [[NSApp mainMenu] addItem:menuItem]; + + // Machine menu + menu = [[NSMenu alloc] initWithTitle: @"Machine"]; + [menu addItemWithTitle:@"Restart" action:@selector (doRestartMenuItem:) keyEquivalent:@""]; + + menuItem = [[[NSMenuItem alloc] initWithTitle:@"Machine" action:nil keyEquivalent:@""] autorelease]; + [menuItem setSubmenu:menu]; + [[NSApp mainMenu] addItem:menuItem]; + + // View menu menu = [[NSMenu alloc] initWithTitle:@"View"]; [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Enter Fullscreen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"] autorelease]]; // Fullscreen @@ -947,13 +1004,23 @@ static void cocoa_refresh(DisplayState *ds) NSDate *distantPast; NSEvent *event; + int count; + + count = 0; distantPast = [NSDate distantPast]; - do { + do { + + if(qemuAtHighPriority == NO) { + sleep(1000); + } + event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:distantPast inMode: NSDefaultRunLoopMode dequeue:YES]; if (event != nil) { [cocoaView handleEvent:event]; - } + } + + } while(event != nil); vga_hw_update(); } diff --git a/cocoa.m b/cocoa.m index 55ff2b4..14a3004 100644 --- a/cocoa.m +++ b/cocoa.m @@ -23,11 +23,17 @@ */ #import - #include "qemu-common.h" #include "console.h" #include "sysemu.h" +#ifndef MAC_OS_X_VERSION_10_4 +#define MAC_OS_X_VERSION_10_4 1040 +#endif + +#ifndef __LITTLE_ENDIAN__ +#define __LITTLE_ENDIAN__ 0 /* assume PowerPC*/ +#endif //#define DEBUG @@ -55,9 +61,13 @@ typedef struct { } QEMUScreen; int qemu_main(int argc, char **argv); // main defined in qemu/vl.c +int cocoa_keycode_to_qemu(int keycode); + NSWindow *normalWindow; id cocoaView; static DisplayChangeListener *dcl; +BOOL qemuAtHighPriority; + int gArgc; char **gArgv; @@ -421,7 +431,7 @@ int cocoa_keycode_to_qemu(int keycode) [self ungrabMouse]; [self setContentDimensions]; // test if host support "enterFullScreenMode:withOptions" at compiletime -#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) +#if (MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4) if ([NSView respondsToSelector:@selector (exitFullScreenModeWithOptions:)]) { // test if