qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH] This patch adds a Priority and a Machine menu to th


From: G 3
Subject: [Qemu-devel] [PATCH] This patch adds a Priority and a Machine menu to the menu bar.
Date: Thu, 12 Nov 2009 13:15:37 -0500

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 <address@hidden>
---
cocoa.m | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++ +--------
 1 files changed, 79 insertions(+), 12 deletions(-)

diff --git a/cocoa.m b/cocoa.m
index 55ff2b4..14a3004 100644
--- a/cocoa.m
+++ b/cocoa.m
@@ -23,11 +23,17 @@
  */

 #import <Cocoa/Cocoa.h>
-
 #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 "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();
 }
--
1.6.5.2





reply via email to

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