diff mbox

This patch adds a Priority and a Machine menu to the menu bar.

Message ID F725E15C-31D1-40A1-A4E1-79957274496E@gmail.com
State New
Headers show

Commit Message

Programmingkid Nov. 12, 2009, 6:15 p.m. UTC
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 <programmingkidx@gmail.com>
---
  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();
  }

Comments

Andreas Färber Dec. 6, 2009, 4:25 p.m. UTC | #1
Hello,

Am 12.11.2009 um 19:15 schrieb G 3:

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

Please do not combine unrelated changes into one large patch.

I'm not sure if adding more menus to QEMU is the way to go,  
considering that this has traditionally been the job of frontends like  
Q. I haven't noticed such options in the SDL frontend either.
What I am missing though is the system-provided Services menu item in  
the application menu.

> diff --git a/cocoa.m b/cocoa.m
> index 55ff2b4..14a3004 100644
> --- a/cocoa.m
> +++ b/cocoa.m

> @@ -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];
> -        }

What exactly are you trying to accomplish with this patch?

This is most certainly the wrong way, you are blocking the event loop  
during a pending update for one second.
If you want to throttle events like screen updates or reduce the QEMU- 
induced CPU load, this likely needs to be done in another way, putting  
less events into the queue in the first place, no?

> +		}
> +
> +		
>     } while(event != nil);
>     vga_hw_update();
> }

Andreas
diff mbox

Patch

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