qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [patch] ui/cocoa.m: Add Machine menu with pause and resume


From: Programmingkid
Subject: [Qemu-devel] [patch] ui/cocoa.m: Add Machine menu with pause and resume items
Date: Sun, 10 May 2015 23:23:24 -0400

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 <address@hidden>

---
 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"

 

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

 

 int gArgc;
 char **gArgv;
+NSTextField * pauseLabel;

 

 // keymap conversion
 int keymap[] =
@@ -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 = [[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 = [[[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.
+}

 

 /*
  ------------------------------------------------------
@@ -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 = [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 = ([normalWindow frame].size.width - [pauseLabel frame].size.width)/2;
+    yCoord = [normalWindow frame].size.height - [pauseLabel frame].size.height - ([pauseLabel frame].size.height * .5);
+    width = [pauseLabel frame].size.width;
+    height = [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

 

 

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

 

     // register cleanup function
     atexit(cocoa_cleanup);
+
+    // Creates and adds the Machine menu to the menubar
+    createMachineMenu();
 }
-- 
1.7.5.4


reply via email to

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