Received: from eggs.gnu.org ([2001:4830:134:3::10]:35139) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YreJX-0007oT-Vw for qemu-devel@nongnu.org; Sun, 10 May 2015 23:23:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YreJT-0008K3-Nr for qemu-devel@nongnu.org; Sun, 10 May 2015 23:23:31 -0400 Received: from mail-qc0-x22f.google.com ([2607:f8b0:400d:c01::22f]:33706) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YreJT-0008Jv-Fm for qemu-devel@nongnu.org; Sun, 10 May 2015 23:23:27 -0400 Received: by qcvo8 with SMTP id o8so39320143qcv.0 for ; Sun, 10 May 2015 20:23:27 -0700 (PDT) From: Programmingkid Content-Type: multipart/alternative; boundary=Apple-Mail-2--111645135 Date: Sun, 10 May 2015 23:23:24 -0400 Message-Id: <7C398313-9399-4FE1-B2EA-AE710900A25B@gmail.com> Mime-Version: 1.0 (Apple Message framework v1084) Subject: [Qemu-devel] [patch] ui/cocoa.m: Add Machine menu with pause and resume items List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: qemu-devel qemu-devel --Apple-Mail-2--111645135 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Adds a Machine menu with a pause and resume menu item. Adds feature that displays the word pause on the screen when paused. Signed-off-by: John Arbuckle --- ui/cocoa.m | 79 = +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 78 insertions(+), 1 deletions(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index d37c29b..8122566 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -29,6 +29,7 @@ #include "ui/console.h" #include "ui/input.h" #include "sysemu/sysemu.h" +#include "qmp-commands.h" =20 #ifndef MAC_OS_X_VERSION_10_4 #define MAC_OS_X_VERSION_10_4 1040 @@ -64,6 +65,7 @@ static int last_buttons; =20 int gArgc; char **gArgv; +NSTextField * pauseLabel; =20 // keymap conversion int keymap[] =3D @@ -239,7 +241,26 @@ static int cocoa_keycode_to_qemu(int keycode) return keymap[keycode]; } =20 - +/* + Adds the Machine menu to the menu bar. + Has to be added separately because QEMU needs + to be running to determine used items. +*/ +static void createMachineMenu() +{ + NSMenu * menu; + NSMenuItem * menuItem; + + // Machine menu + menu =3D [[NSMenu alloc] initWithTitle: @"Machine"]; + [menu setAutoenablesItems: NO]; + [menu addItem: [[[NSMenuItem alloc] initWithTitle: @"Pause" action: = @selector(pauseQemu:) keyEquivalent: @""] autorelease]]; + [menu addItem: [[[NSMenuItem alloc] initWithTitle: @"Resume" = action: @selector(resumeQemu:) keyEquivalent: @""] autorelease]]; + menuItem =3D [[[NSMenuItem alloc] initWithTitle: @"Machine" = action:nil keyEquivalent:@""] autorelease]; + [menuItem setSubmenu:menu]; + [[NSApp mainMenu] insertItem: menuItem atIndex: 2]; // Insert after = View menu + [[menu itemWithTitle: @"Resume"] setEnabled: NO]; // Disables the = Resume menu item because it isn't needed right now. +} =20 /* ------------------------------------------------------ @@ -801,6 +822,10 @@ QemuCocoaView *cocoaView; - (void)toggleFullScreen:(id)sender; - (void)showQEMUDoc:(id)sender; - (void)showQEMUTec:(id)sender; +- (void)pauseQemu:(id)sender; +- (void)resumeQemu: (id) sender; +- (void)displayPause; +- (void)removePause; @end =20 @implementation QemuCocoaAppController @@ -833,6 +858,17 @@ QemuCocoaView *cocoaView; [normalWindow makeKeyAndOrderFront:self]; [normalWindow center]; =20 + /* Used for displaying pause on the screen */ + pauseLabel =3D [NSTextField new]; + [pauseLabel setBezeled:YES]; + [pauseLabel setDrawsBackground:YES]; + [pauseLabel setBackgroundColor: [NSColor whiteColor]]; + [pauseLabel setEditable:NO]; + [pauseLabel setSelectable:NO]; + [pauseLabel setStringValue: @"Paused"]; + [pauseLabel setFont: [NSFont fontWithName: @"Helvetica" size: = 90]]; + [pauseLabel setTextColor: [NSColor blackColor]]; + [pauseLabel sizeToFit]; } return self; } @@ -943,6 +979,44 @@ QemuCocoaView *cocoaView; [[NSWorkspace sharedWorkspace] openFile:[NSString = stringWithFormat:@"%@/../doc/qemu/qemu-tech.html", [[NSBundle mainBundle] resourcePath]] withApplication:@"Help = Viewer"]; } + +/* Pause the guest */ +- (void)pauseQemu:(id)sender +{ + qmp_stop(NULL); + [sender setEnabled: NO]; + [[[sender menu] itemWithTitle: @"Resume"] setEnabled: YES]; + [self displayPause]; +} + +/* Resume running the guest operating system */ +- (void)resumeQemu: (id) sender +{ + qmp_cont(NULL); + [sender setEnabled: NO]; + [[[sender menu] itemWithTitle: @"Pause"] setEnabled: YES]; + [self removePause]; +} + +/* Displays the word pause on the screen */ +- (void)displayPause +{ + /* Coordinates have to be calculated each time because the window = can change its size */ + int xCoord, yCoord, width, height; + xCoord =3D ([normalWindow frame].size.width - [pauseLabel = frame].size.width)/2; + yCoord =3D [normalWindow frame].size.height - [pauseLabel = frame].size.height - ([pauseLabel frame].size.height * .5); + width =3D [pauseLabel frame].size.width; + height =3D [pauseLabel frame].size.height; + [pauseLabel setFrame: NSMakeRect(xCoord, yCoord, width, height)]; + [cocoaView addSubview: pauseLabel]; +} + +/* Removes the word pause from the screen */ +- (void)removePause +{ + [pauseLabel removeFromSuperview]; +} + @end =20 =20 @@ -1128,4 +1202,7 @@ void cocoa_display_init(DisplayState *ds, int = full_screen) =20 // register cleanup function atexit(cocoa_cleanup); + + // Creates and adds the Machine menu to the menubar + createMachineMenu(); } --=20 1.7.5.4 --Apple-Mail-2--111645135 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii
Adds a Machine menu with a pause and = resume menu item.
Adds feature that displays the word pause on the = screen when paused.

programmingkidx@gmail.com>= ;

---
 ui/cocoa.m |   79 = +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-

diff --git a/ui/cocoa.m = b/ui/cocoa.m
index d37c29b..8122566 100644
--- = a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -29,6 +29,7 @@
 #include "ui/input.h"
+#include "qmp-commands.h"

 

 #define = MAC_OS_X_VERSION_10_4 1040
@@ -64,6 +65,7 @@ static int = last_buttons;

 

 int gArgc;
+NSTextField * pauseLabel;

 

 int keymap[] =3D
@@ = -239,7 +241,26 @@ static int cocoa_keycode_to_qemu(int = keycode)
     return = keymap[keycode];
 }

 

-
+/*
+   Adds the Machine menu = to the menu bar.
+   Has to be added separately because QEMU = needs
+   to be running to determine used = items.
+*/
+static void = createMachineMenu()
+{
+    NSMenu * = menu;
+    NSMenuItem * menuItem;
+    // Machine menu
+ =     menu =3D [[NSMenu alloc] initWithTitle: = @"Machine"];
+    [menu setAutoenablesItems: = NO];
+    [menu addItem: [[[NSMenuItem alloc] = initWithTitle: @"Pause" action: @selector(pauseQemu:) keyEquivalent: = @""] autorelease]];
+    [menu addItem: [[[NSMenuItem alloc] = initWithTitle: @"Resume" action: @selector(resumeQemu:) keyEquivalent: = @""] autorelease]];
+    menuItem =3D [[[NSMenuItem alloc] = initWithTitle: @"Machine" action:nil keyEquivalent:@""] = autorelease];
+    [menuItem = setSubmenu:menu];
+    [[NSApp mainMenu] insertItem: = menuItem atIndex: 2]; // Insert after View menu
+}

 

 /*
  = ------------------------------------------------------
@@ = -801,6 +822,10 @@ QemuCocoaView *cocoaView;
 - = (void)toggleFullScreen:(id)sender;
 - = (void)showQEMUDoc:(id)sender;
 - = (void)showQEMUTec:(id)sender;
+- = (void)pauseQemu:(id)sender;
+- (void)resumeQemu: (id) = sender;
+- (void)displayPause;
+- = (void)removePause;
 @end

 

 @implementation = QemuCocoaAppController
@@ -833,6 +858,17 @@ QemuCocoaView = *cocoaView;
         [normalWindow = makeKeyAndOrderFront:self];
         = [normalWindow center];

 

+        /* Used = for displaying pause on the screen */
+        = pauseLabel =3D [NSTextField new];
+        = [pauseLabel setBezeled:YES];
+        = [pauseLabel setDrawsBackground:YES];
+        = [pauseLabel setBackgroundColor: [NSColor whiteColor]];
+        [pauseLabel setFont: = [NSFont fontWithName: @"Helvetica" size: 90]];
+        [pauseLabel = sizeToFit];
     }
     return = self;
 }
@@ -943,6 +979,44 @@ QemuCocoaView = *cocoaView;
     [[NSWorkspace sharedWorkspace] = openFile:[NSString = stringWithFormat:@"%@/../doc/qemu/qemu-tech.html",
+
+/* Pause the guest */
+- = (void)pauseQemu:(id)sender
+{
+    = qmp_stop(NULL);
+    [sender setEnabled: NO];
+    [self displayPause];
+
+/* Resume running the guest operating system = */
+{
+    = qmp_cont(NULL);
+    [sender setEnabled: NO];
+    [self removePause];
+
+/* Displays the word pause on the screen = */
+{
+    /* Coordinates = have to be calculated each time because the window can change its size = */
+    yCoord =3D = [normalWindow frame].size.height - [pauseLabel frame].size.height - = ([pauseLabel frame].size.height * .5);
+    width =3D = [pauseLabel frame].size.width;
+    height =3D [pauseLabel = frame].size.height;
+    [pauseLabel setFrame: = NSMakeRect(xCoord, yCoord, width, height)];
+    [cocoaView = addSubview: pauseLabel];
+}
+
+/* Removes the word pause = from the screen */
+- (void)removePause
+{
+
 @end

 

 

@@ -1128,4 +1202,7 @@ void = cocoa_display_init(DisplayState *ds, int full_screen)

 

+    // Creates and adds the Machine menu = to the menubar
+    createMachineMenu();
-- 
1.7.5.4