#include "ui/console.h"
#include "ui/input.h"
#include "sysemu/sysemu.h"
-#include "qmp-commands.h"
+#include "qapi/error.h"
+#include "qapi/qapi-commands.h"
#include "sysemu/blockdev.h"
+#include "qemu-version.h"
#include <Carbon/Carbon.h>
+#include "qom/cpu.h"
#ifndef MAC_OS_X_VERSION_10_5
#define MAC_OS_X_VERSION_10_5 1050
#ifndef MAC_OS_X_VERSION_10_10
#define MAC_OS_X_VERSION_10_10 101000
#endif
+#ifndef MAC_OS_X_VERSION_10_12
+#define MAC_OS_X_VERSION_10_12 101200
+#endif
+/* macOS 10.12 deprecated many constants, #define the new names for older SDKs */
+#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_12
+#define NSEventMaskAny NSAnyEventMask
+#define NSEventModifierFlagCapsLock NSAlphaShiftKeyMask
+#define NSEventModifierFlagShift NSShiftKeyMask
+#define NSEventModifierFlagCommand NSCommandKeyMask
+#define NSEventModifierFlagControl NSControlKeyMask
+#define NSEventModifierFlagOption NSAlternateKeyMask
+#define NSEventTypeFlagsChanged NSFlagsChanged
+#define NSEventTypeKeyUp NSKeyUp
+#define NSEventTypeKeyDown NSKeyDown
+#define NSEventTypeMouseMoved NSMouseMoved
+#define NSEventTypeLeftMouseDown NSLeftMouseDown
+#define NSEventTypeRightMouseDown NSRightMouseDown
+#define NSEventTypeOtherMouseDown NSOtherMouseDown
+#define NSEventTypeLeftMouseDragged NSLeftMouseDragged
+#define NSEventTypeRightMouseDragged NSRightMouseDragged
+#define NSEventTypeOtherMouseDragged NSOtherMouseDragged
+#define NSEventTypeLeftMouseUp NSLeftMouseUp
+#define NSEventTypeRightMouseUp NSRightMouseUp
+#define NSEventTypeOtherMouseUp NSOtherMouseUp
+#define NSEventTypeScrollWheel NSScrollWheel
+#define NSTextAlignmentCenter NSCenterTextAlignment
+#define NSWindowStyleMaskBorderless NSBorderlessWindowMask
+#define NSWindowStyleMaskClosable NSClosableWindowMask
+#define NSWindowStyleMaskMiniaturizable NSMiniaturizableWindowMask
+#define NSWindowStyleMaskTitled NSTitledWindowMask
+#endif
//#define DEBUG
int bitsPerPixel;
} QEMUScreen;
-NSWindow *normalWindow;
+NSWindow *normalWindow, *about_window;
static DisplayChangeListener *dcl;
static int last_buttons;
NSWindow *fullScreenWindow;
float cx,cy,cw,ch,cdx,cdy;
CGDataProviderRef dataProviderRef;
- int modifiers_state[256];
+ BOOL modifiers_state[256];
BOOL isMouseGrabbed;
BOOL isFullscreen;
BOOL isAbsoluteEnabled;
- (void) grabMouse;
- (void) ungrabMouse;
- (void) toggleFullScreen:(id)sender;
+- (void) handleMonitorInput:(NSEvent *)event;
- (void) handleEvent:(NSEvent *)event;
- (void) setAbsoluteEnabled:(BOOL)tIsAbsoluteEnabled;
/* The state surrounding mouse grabbing is potentially confusing.
} else {
[NSMenu setMenuBarVisible:NO];
fullScreenWindow = [[NSWindow alloc] initWithContentRect:[[NSScreen mainScreen] frame]
- styleMask:NSBorderlessWindowMask
+ styleMask:NSWindowStyleMaskBorderless
backing:NSBackingStoreBuffered
defer:NO];
[fullScreenWindow setAcceptsMouseMovedEvents: YES];
}
}
+- (void) toggleModifier: (int)keycode {
+ // Toggle the stored state.
+ modifiers_state[keycode] = !modifiers_state[keycode];
+ // Send a keyup or keydown depending on the state.
+ qemu_input_event_send_key_qcode(dcl->con, keycode, modifiers_state[keycode]);
+}
+
+- (void) toggleStatefulModifier: (int)keycode {
+ // Toggle the stored state.
+ modifiers_state[keycode] = !modifiers_state[keycode];
+ // Generate keydown and keyup.
+ qemu_input_event_send_key_qcode(dcl->con, keycode, true);
+ qemu_input_event_send_key_qcode(dcl->con, keycode, false);
+}
+
+// Does the work of sending input to the monitor
+- (void) handleMonitorInput:(NSEvent *)event
+{
+ int keysym = 0;
+ int control_key = 0;
+
+ // if the control key is down
+ if ([event modifierFlags] & NSEventModifierFlagControl) {
+ control_key = 1;
+ }
+
+ /* translates Macintosh keycodes to QEMU's keysym */
+
+ int without_control_translation[] = {
+ [0 ... 0xff] = 0, // invalid key
+
+ [kVK_UpArrow] = QEMU_KEY_UP,
+ [kVK_DownArrow] = QEMU_KEY_DOWN,
+ [kVK_RightArrow] = QEMU_KEY_RIGHT,
+ [kVK_LeftArrow] = QEMU_KEY_LEFT,
+ [kVK_Home] = QEMU_KEY_HOME,
+ [kVK_End] = QEMU_KEY_END,
+ [kVK_PageUp] = QEMU_KEY_PAGEUP,
+ [kVK_PageDown] = QEMU_KEY_PAGEDOWN,
+ [kVK_ForwardDelete] = QEMU_KEY_DELETE,
+ [kVK_Delete] = QEMU_KEY_BACKSPACE,
+ };
+
+ int with_control_translation[] = {
+ [0 ... 0xff] = 0, // invalid key
+
+ [kVK_UpArrow] = QEMU_KEY_CTRL_UP,
+ [kVK_DownArrow] = QEMU_KEY_CTRL_DOWN,
+ [kVK_RightArrow] = QEMU_KEY_CTRL_RIGHT,
+ [kVK_LeftArrow] = QEMU_KEY_CTRL_LEFT,
+ [kVK_Home] = QEMU_KEY_CTRL_HOME,
+ [kVK_End] = QEMU_KEY_CTRL_END,
+ [kVK_PageUp] = QEMU_KEY_CTRL_PAGEUP,
+ [kVK_PageDown] = QEMU_KEY_CTRL_PAGEDOWN,
+ };
+
+ if (control_key != 0) { /* If the control key is being used */
+ if ([event keyCode] < ARRAY_SIZE(with_control_translation)) {
+ keysym = with_control_translation[[event keyCode]];
+ }
+ } else {
+ if ([event keyCode] < ARRAY_SIZE(without_control_translation)) {
+ keysym = without_control_translation[[event keyCode]];
+ }
+ }
+
+ // if not a key that needs translating
+ if (keysym == 0) {
+ NSString *ks = [event characters];
+ if ([ks length] > 0) {
+ keysym = [ks characterAtIndex:0];
+ }
+ }
+
+ if (keysym) {
+ kbd_put_keysym(keysym);
+ }
+}
+
- (void) handleEvent:(NSEvent *)event
{
COCOA_DEBUG("QemuCocoaView: handleEvent\n");
int buttons = 0;
- int keycode;
+ int keycode = 0;
bool mouse_event = false;
NSPoint p = [event locationInWindow];
switch ([event type]) {
- case NSFlagsChanged:
- keycode = cocoa_keycode_to_qemu([event keyCode]);
+ case NSEventTypeFlagsChanged:
+ if ([event keyCode] == 0) {
+ // When the Cocoa keyCode is zero that means keys should be
+ // synthesized based on the values in in the eventModifiers
+ // bitmask.
+
+ if (qemu_console_is_graphic(NULL)) {
+ NSUInteger modifiers = [event modifierFlags];
+
+ if (!!(modifiers & NSEventModifierFlagCapsLock) != !!modifiers_state[Q_KEY_CODE_CAPS_LOCK]) {
+ [self toggleStatefulModifier:Q_KEY_CODE_CAPS_LOCK];
+ }
+ if (!!(modifiers & NSEventModifierFlagShift) != !!modifiers_state[Q_KEY_CODE_SHIFT]) {
+ [self toggleModifier:Q_KEY_CODE_SHIFT];
+ }
+ if (!!(modifiers & NSEventModifierFlagControl) != !!modifiers_state[Q_KEY_CODE_CTRL]) {
+ [self toggleModifier:Q_KEY_CODE_CTRL];
+ }
+ if (!!(modifiers & NSEventModifierFlagOption) != !!modifiers_state[Q_KEY_CODE_ALT]) {
+ [self toggleModifier:Q_KEY_CODE_ALT];
+ }
+ if (!!(modifiers & NSEventModifierFlagCommand) != !!modifiers_state[Q_KEY_CODE_META_L]) {
+ [self toggleModifier:Q_KEY_CODE_META_L];
+ }
+ }
+ } else {
+ keycode = cocoa_keycode_to_qemu([event keyCode]);
+ }
if ((keycode == Q_KEY_CODE_META_L || keycode == Q_KEY_CODE_META_R)
&& !isMouseGrabbed) {
// emulate caps lock and num lock keydown and keyup
if (keycode == Q_KEY_CODE_CAPS_LOCK ||
keycode == Q_KEY_CODE_NUM_LOCK) {
- qemu_input_event_send_key_qcode(dcl->con, keycode, true);
- qemu_input_event_send_key_qcode(dcl->con, keycode, false);
+ [self toggleStatefulModifier:keycode];
} else if (qemu_console_is_graphic(NULL)) {
- if (modifiers_state[keycode] == 0) { // keydown
- qemu_input_event_send_key_qcode(dcl->con, keycode, true);
- modifiers_state[keycode] = 1;
- } else { // keyup
- qemu_input_event_send_key_qcode(dcl->con, keycode, false);
- modifiers_state[keycode] = 0;
- }
+ [self toggleModifier:keycode];
}
}
- // release Mouse grab when pressing ctrl+alt
- if (([event modifierFlags] & NSControlKeyMask) && ([event modifierFlags] & NSAlternateKeyMask)) {
- [self ungrabMouse];
- }
break;
- case NSKeyDown:
+ case NSEventTypeKeyDown:
keycode = cocoa_keycode_to_qemu([event keyCode]);
// forward command key combos to the host UI unless the mouse is grabbed
- if (!isMouseGrabbed && ([event modifierFlags] & NSCommandKeyMask)) {
+ if (!isMouseGrabbed && ([event modifierFlags] & NSEventModifierFlagCommand)) {
[NSApp sendEvent:event];
return;
}
// default
- // handle control + alt Key Combos (ctrl+alt is reserved for QEMU)
- if (([event modifierFlags] & NSControlKeyMask) && ([event modifierFlags] & NSAlternateKeyMask)) {
- switch (keycode) {
-
- // enable graphic console
- case Q_KEY_CODE_1 ... Q_KEY_CODE_9: // '1' to '9' keys
- console_select(keycode - 11);
- break;
+ // handle control + alt Key Combos (ctrl+alt+[1..9,g] is reserved for QEMU)
+ if (([event modifierFlags] & NSEventModifierFlagControl) && ([event modifierFlags] & NSEventModifierFlagOption)) {
+ NSString *keychar = [event charactersIgnoringModifiers];
+ if ([keychar length] == 1) {
+ char key = [keychar characterAtIndex:0];
+ switch (key) {
+
+ // enable graphic console
+ case '1' ... '9':
+ console_select(key - '0' - 1); /* ascii math */
+ return;
+
+ // release the mouse grab
+ case 'g':
+ [self ungrabMouse];
+ return;
+ }
}
+ }
- // handle keys for graphic console
- } else if (qemu_console_is_graphic(NULL)) {
+ if (qemu_console_is_graphic(NULL)) {
qemu_input_event_send_key_qcode(dcl->con, keycode, true);
-
- // handlekeys for Monitor
} else {
- int keysym = 0;
- switch([event keyCode]) {
- case 115:
- keysym = QEMU_KEY_HOME;
- break;
- case 117:
- keysym = QEMU_KEY_DELETE;
- break;
- case 119:
- keysym = QEMU_KEY_END;
- break;
- case 123:
- keysym = QEMU_KEY_LEFT;
- break;
- case 124:
- keysym = QEMU_KEY_RIGHT;
- break;
- case 125:
- keysym = QEMU_KEY_DOWN;
- break;
- case 126:
- keysym = QEMU_KEY_UP;
- break;
- default:
- {
- NSString *ks = [event characters];
- if ([ks length] > 0)
- keysym = [ks characterAtIndex:0];
- }
- }
- if (keysym)
- kbd_put_keysym(keysym);
+ [self handleMonitorInput: event];
}
break;
- case NSKeyUp:
+ case NSEventTypeKeyUp:
keycode = cocoa_keycode_to_qemu([event keyCode]);
// don't pass the guest a spurious key-up if we treated this
// command-key combo as a host UI action
- if (!isMouseGrabbed && ([event modifierFlags] & NSCommandKeyMask)) {
+ if (!isMouseGrabbed && ([event modifierFlags] & NSEventModifierFlagCommand)) {
return;
}
qemu_input_event_send_key_qcode(dcl->con, keycode, false);
}
break;
- case NSMouseMoved:
+ case NSEventTypeMouseMoved:
if (isAbsoluteEnabled) {
if (![self screenContainsPoint:p] || ![[self window] isKeyWindow]) {
if (isMouseGrabbed) {
}
mouse_event = true;
break;
- case NSLeftMouseDown:
- if ([event modifierFlags] & NSCommandKeyMask) {
+ case NSEventTypeLeftMouseDown:
+ if ([event modifierFlags] & NSEventModifierFlagCommand) {
buttons |= MOUSE_EVENT_RBUTTON;
} else {
buttons |= MOUSE_EVENT_LBUTTON;
}
mouse_event = true;
break;
- case NSRightMouseDown:
+ case NSEventTypeRightMouseDown:
buttons |= MOUSE_EVENT_RBUTTON;
mouse_event = true;
break;
- case NSOtherMouseDown:
+ case NSEventTypeOtherMouseDown:
buttons |= MOUSE_EVENT_MBUTTON;
mouse_event = true;
break;
- case NSLeftMouseDragged:
- if ([event modifierFlags] & NSCommandKeyMask) {
+ case NSEventTypeLeftMouseDragged:
+ if ([event modifierFlags] & NSEventModifierFlagCommand) {
buttons |= MOUSE_EVENT_RBUTTON;
} else {
buttons |= MOUSE_EVENT_LBUTTON;
}
mouse_event = true;
break;
- case NSRightMouseDragged:
+ case NSEventTypeRightMouseDragged:
buttons |= MOUSE_EVENT_RBUTTON;
mouse_event = true;
break;
- case NSOtherMouseDragged:
+ case NSEventTypeOtherMouseDragged:
buttons |= MOUSE_EVENT_MBUTTON;
mouse_event = true;
break;
- case NSLeftMouseUp:
+ case NSEventTypeLeftMouseUp:
mouse_event = true;
if (!isMouseGrabbed && [self screenContainsPoint:p]) {
- [self grabMouse];
+ if([[self window] isKeyWindow]) {
+ [self grabMouse];
+ }
}
break;
- case NSRightMouseUp:
+ case NSEventTypeRightMouseUp:
mouse_event = true;
break;
- case NSOtherMouseUp:
+ case NSEventTypeOtherMouseUp:
mouse_event = true;
break;
- case NSScrollWheel:
- if (isMouseGrabbed) {
- buttons |= ([event deltaY] < 0) ?
- MOUSE_EVENT_WHEELUP : MOUSE_EVENT_WHEELDN;
- }
- mouse_event = true;
+ case NSEventTypeScrollWheel:
+ /*
+ * Send wheel events to the guest regardless of window focus.
+ * This is in-line with standard Mac OS X UI behaviour.
+ */
+
+ /* Determine if this is a scroll up or scroll down event */
+ buttons = ([event scrollingDeltaY] > 0) ?
+ INPUT_BUTTON_WHEEL_UP : INPUT_BUTTON_WHEEL_DOWN;
+ qemu_input_queue_btn(dcl->con, buttons, true);
+ qemu_input_event_sync();
+ qemu_input_queue_btn(dcl->con, buttons, false);
+ qemu_input_event_sync();
+
+ /*
+ * Since deltaY also reports scroll wheel events we prevent mouse
+ * movement code from executing.
+ */
+ mouse_event = false;
break;
default:
[NSApp sendEvent:event];
static uint32_t bmap[INPUT_BUTTON__MAX] = {
[INPUT_BUTTON_LEFT] = MOUSE_EVENT_LBUTTON,
[INPUT_BUTTON_MIDDLE] = MOUSE_EVENT_MBUTTON,
- [INPUT_BUTTON_RIGHT] = MOUSE_EVENT_RBUTTON,
- [INPUT_BUTTON_WHEEL_UP] = MOUSE_EVENT_WHEELUP,
- [INPUT_BUTTON_WHEEL_DOWN] = MOUSE_EVENT_WHEELDN,
+ [INPUT_BUTTON_RIGHT] = MOUSE_EVENT_RBUTTON
};
qemu_input_update_buttons(dcl->con, bmap, last_buttons, buttons);
last_buttons = buttons;
* clicks in the titlebar.
*/
if ([self screenContainsPoint:p]) {
- qemu_input_queue_abs(dcl->con, INPUT_AXIS_X, p.x, screen.width);
- qemu_input_queue_abs(dcl->con, INPUT_AXIS_Y, screen.height - p.y, screen.height);
+ qemu_input_queue_abs(dcl->con, INPUT_AXIS_X, p.x, 0, screen.width);
+ qemu_input_queue_abs(dcl->con, INPUT_AXIS_Y, screen.height - p.y, 0, screen.height);
}
} else {
qemu_input_queue_rel(dcl->con, INPUT_AXIS_X, (int)[event deltaX]);
if (!isFullscreen) {
if (qemu_name)
- [normalWindow setTitle:[NSString stringWithFormat:@"QEMU %s - (Press ctrl + alt to release Mouse)", qemu_name]];
+ [normalWindow setTitle:[NSString stringWithFormat:@"QEMU %s - (Press ctrl + alt + g to release Mouse)", qemu_name]];
else
- [normalWindow setTitle:@"QEMU - (Press ctrl + alt to release Mouse)"];
+ [normalWindow setTitle:@"QEMU - (Press ctrl + alt + g to release Mouse)"];
}
[self hideCursor];
if (!isAbsoluteEnabled) {
- (void)doToggleFullScreen:(id)sender;
- (void)toggleFullScreen:(id)sender;
- (void)showQEMUDoc:(id)sender;
-- (void)showQEMUTec:(id)sender;
- (void)zoomToFit:(id) sender;
- (void)displayConsole:(id)sender;
- (void)pauseQEMU:(id)sender;
- (void)changeDeviceMedia:(id)sender;
- (BOOL)verifyQuit;
- (void)openDocumentation:(NSString *)filename;
+- (IBAction) do_about_menu_item: (id) sender;
+- (void)make_about_window;
+- (void)adjustSpeed:(id)sender;
@end
@implementation QemuCocoaAppController
// create a window
normalWindow = [[NSWindow alloc] initWithContentRect:[cocoaView frame]
- styleMask:NSTitledWindowMask|NSMiniaturizableWindowMask|NSClosableWindowMask
+ styleMask:NSWindowStyleMaskTitled|NSWindowStyleMaskMiniaturizable|NSWindowStyleMaskClosable
backing:NSBackingStoreBuffered defer:NO];
if(!normalWindow) {
fprintf(stderr, "(cocoa) can't create window\n");
// set the supported image file types that can be opened
supportedImageFileTypes = [NSArray arrayWithObjects: @"img", @"iso", @"dmg",
@"qcow", @"qcow2", @"cloop", @"vmdk", @"cdr",
- nil];
+ @"toast", nil];
+ [self make_about_window];
}
return self;
}
{
COCOA_DEBUG("QemuCocoaAppController: applicationWillTerminate\n");
- qemu_system_shutdown_request();
+ qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_UI);
exit(0);
}
[self openDocumentation: @"qemu-doc.html"];
}
-- (void)showQEMUTec:(id)sender
-{
- COCOA_DEBUG("QemuCocoaAppController: showQEMUTec\n");
-
- [self openDocumentation: @"qemu-tech.html"];
-}
-
/* Stretches video to fit host monitor size */
- (void)zoomToFit:(id) sender
{
}
Error *err = NULL;
- qmp_eject([drive cStringUsingEncoding: NSASCIIStringEncoding], false, false, &err);
+ qmp_eject(true, [drive cStringUsingEncoding: NSASCIIStringEncoding],
+ false, NULL, false, false, &err);
handleAnyDeviceErrors(err);
}
}
Error *err = NULL;
- qmp_blockdev_change_medium([drive cStringUsingEncoding:
+ qmp_blockdev_change_medium(true,
+ [drive cStringUsingEncoding:
NSASCIIStringEncoding],
+ false, NULL,
[file cStringUsingEncoding:
NSASCIIStringEncoding],
true, "raw",
}
}
+/* The action method for the About menu item */
+- (IBAction) do_about_menu_item: (id) sender
+{
+ [about_window makeKeyAndOrderFront: nil];
+}
+
+/* Create and display the about dialog */
+- (void)make_about_window
+{
+ /* Make the window */
+ int x = 0, y = 0, about_width = 400, about_height = 200;
+ NSRect window_rect = NSMakeRect(x, y, about_width, about_height);
+ about_window = [[NSWindow alloc] initWithContentRect:window_rect
+ styleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable |
+ NSWindowStyleMaskMiniaturizable
+ backing:NSBackingStoreBuffered
+ defer:NO];
+ [about_window setTitle: @"About"];
+ [about_window setReleasedWhenClosed: NO];
+ [about_window center];
+ NSView *superView = [about_window contentView];
+
+ /* Create the dimensions of the picture */
+ int picture_width = 80, picture_height = 80;
+ x = (about_width - picture_width)/2;
+ y = about_height - picture_height - 10;
+ NSRect picture_rect = NSMakeRect(x, y, picture_width, picture_height);
+
+ /* Get the path to the QEMU binary */
+ NSString *binary_name = [NSString stringWithCString: gArgv[0]
+ encoding: NSASCIIStringEncoding];
+ binary_name = [binary_name lastPathComponent];
+ NSString *program_path = [[NSString alloc] initWithFormat: @"%@/%@",
+ [[NSBundle mainBundle] bundlePath], binary_name];
+
+ /* Make the picture of QEMU */
+ NSImageView *picture_view = [[NSImageView alloc] initWithFrame:
+ picture_rect];
+ NSImage *qemu_image = [[NSWorkspace sharedWorkspace] iconForFile:
+ program_path];
+ [picture_view setImage: qemu_image];
+ [picture_view setImageScaling: NSImageScaleProportionallyUpOrDown];
+ [superView addSubview: picture_view];
+
+ /* Make the name label */
+ x = 0;
+ y = y - 25;
+ int name_width = about_width, name_height = 20;
+ NSRect name_rect = NSMakeRect(x, y, name_width, name_height);
+ NSTextField *name_label = [[NSTextField alloc] initWithFrame: name_rect];
+ [name_label setEditable: NO];
+ [name_label setBezeled: NO];
+ [name_label setDrawsBackground: NO];
+ [name_label setAlignment: NSTextAlignmentCenter];
+ NSString *qemu_name = [[NSString alloc] initWithCString: gArgv[0]
+ encoding: NSASCIIStringEncoding];
+ qemu_name = [qemu_name lastPathComponent];
+ [name_label setStringValue: qemu_name];
+ [superView addSubview: name_label];
+
+ /* Set the version label's attributes */
+ x = 0;
+ y = 50;
+ int version_width = about_width, version_height = 20;
+ NSRect version_rect = NSMakeRect(x, y, version_width, version_height);
+ NSTextField *version_label = [[NSTextField alloc] initWithFrame:
+ version_rect];
+ [version_label setEditable: NO];
+ [version_label setBezeled: NO];
+ [version_label setAlignment: NSTextAlignmentCenter];
+ [version_label setDrawsBackground: NO];
+
+ /* Create the version string*/
+ NSString *version_string;
+ version_string = [[NSString alloc] initWithFormat:
+ @"QEMU emulator version %s", QEMU_FULL_VERSION];
+ [version_label setStringValue: version_string];
+ [superView addSubview: version_label];
+
+ /* Make copyright label */
+ x = 0;
+ y = 35;
+ int copyright_width = about_width, copyright_height = 20;
+ NSRect copyright_rect = NSMakeRect(x, y, copyright_width, copyright_height);
+ NSTextField *copyright_label = [[NSTextField alloc] initWithFrame:
+ copyright_rect];
+ [copyright_label setEditable: NO];
+ [copyright_label setBezeled: NO];
+ [copyright_label setDrawsBackground: NO];
+ [copyright_label setAlignment: NSTextAlignmentCenter];
+ [copyright_label setStringValue: [NSString stringWithFormat: @"%s",
+ QEMU_COPYRIGHT]];
+ [superView addSubview: copyright_label];
+}
+
+/* Used by the Speed menu items */
+- (void)adjustSpeed:(id)sender
+{
+ int throttle_pct; /* throttle percentage */
+ NSMenu *menu;
+
+ menu = [sender menu];
+ if (menu != nil)
+ {
+ /* Unselect the currently selected item */
+ for (NSMenuItem *item in [menu itemArray]) {
+ if (item.state == NSOnState) {
+ [item setState: NSOffState];
+ break;
+ }
+ }
+ }
+
+ // check the menu item
+ [sender setState: NSOnState];
+
+ // get the throttle percentage
+ throttle_pct = [sender tag];
+
+ cpu_throttle_set(throttle_pct);
+ COCOA_DEBUG("cpu throttling at %d%c\n", cpu_throttle_get_percentage(), '%');
+}
+
@end
// Application menu
menu = [[NSMenu alloc] initWithTitle:@""];
- [menu addItemWithTitle:@"About QEMU" action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""]; // About QEMU
+ [menu addItemWithTitle:@"About QEMU" action:@selector(do_about_menu_item:) keyEquivalent:@""]; // About QEMU
[menu addItem:[NSMenuItem separatorItem]]; //Separator
[menu addItemWithTitle:@"Hide QEMU" action:@selector(hide:) keyEquivalent:@"h"]; //Hide QEMU
menuItem = (NSMenuItem *)[menu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"]; // Hide Others
- [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
+ [menuItem setKeyEquivalentModifierMask:(NSEventModifierFlagOption|NSEventModifierFlagCommand)];
[menu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""]; // Show All
[menu addItem:[NSMenuItem separatorItem]]; //Separator
[menu addItemWithTitle:@"Quit QEMU" action:@selector(terminate:) keyEquivalent:@"q"];
[menuItem setSubmenu:menu];
[[NSApp mainMenu] addItem:menuItem];
+ // Speed menu
+ menu = [[NSMenu alloc] initWithTitle:@"Speed"];
+
+ // Add the rest of the Speed menu items
+ int p, percentage, throttle_pct;
+ for (p = 10; p >= 0; p--)
+ {
+ percentage = p * 10 > 1 ? p * 10 : 1; // prevent a 0% menu item
+
+ menuItem = [[[NSMenuItem alloc]
+ initWithTitle: [NSString stringWithFormat: @"%d%%", percentage] action:@selector(adjustSpeed:) keyEquivalent:@""] autorelease];
+
+ if (percentage == 100) {
+ [menuItem setState: NSOnState];
+ }
+
+ /* Calculate the throttle percentage */
+ throttle_pct = -1 * percentage + 100;
+
+ [menuItem setTag: throttle_pct];
+ [menu addItem: menuItem];
+ }
+ menuItem = [[[NSMenuItem alloc] initWithTitle:@"Speed" action:nil keyEquivalent:@""] autorelease];
+ [menuItem setSubmenu:menu];
+ [[NSApp mainMenu] addItem:menuItem];
+
// Window menu
menu = [[NSMenu alloc] initWithTitle:@"Window"];
[menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"] autorelease]]; // Miniaturize
// Help menu
menu = [[NSMenu alloc] initWithTitle:@"Help"];
[menu addItem: [[[NSMenuItem alloc] initWithTitle:@"QEMU Documentation" action:@selector(showQEMUDoc:) keyEquivalent:@"?"] autorelease]]; // QEMU Help
- [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"QEMU Technology" action:@selector(showQEMUTec:) keyEquivalent:@""] autorelease]]; // QEMU Help
menuItem = [[[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""] autorelease];
[menuItem setSubmenu:menu];
[[NSApp mainMenu] addItem:menuItem];
NSEvent *event;
distantPast = [NSDate distantPast];
do {
- event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:distantPast
+ event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:distantPast
inMode: NSDefaultRunLoopMode dequeue:YES];
if (event != nil) {
[cocoaView handleEvent:event];
[menuItem setEnabled: NO];
[menu addItem: menuItem];
- /* Loop thru all the block devices in the emulator */
+ /* Loop through all the block devices in the emulator */
while (currentDevice) {
deviceName = [[NSString stringWithFormat: @"%s", currentDevice->value->device] retain];
qapi_free_BlockInfoList(pointerToFree);
}
-void cocoa_display_init(DisplayState *ds, int full_screen)
+static void cocoa_display_init(DisplayState *ds, DisplayOptions *opts)
{
COCOA_DEBUG("qemu_cocoa: cocoa_display_init\n");
/* if fullscreen mode is to be used */
- if (full_screen == true) {
+ if (opts->has_full_screen && opts->full_screen) {
[NSApp activateIgnoringOtherApps: YES];
[(QemuCocoaAppController *)[[NSApplication sharedApplication] delegate] toggleFullScreen: nil];
}
*/
addRemovableDevicesMenuItems();
}
+
+static QemuDisplay qemu_display_cocoa = {
+ .type = DISPLAY_TYPE_COCOA,
+ .init = cocoa_display_init,
+};
+
+static void register_cocoa(void)
+{
+ qemu_display_register(&qemu_display_cocoa);
+}
+
+type_init(register_cocoa);