aboutsummaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2022-03-15 18:58:41 +0000
committerPeter Maydell <peter.maydell@linaro.org>2022-03-15 18:58:41 +0000
commit22a3a45ade8d331f3c318afeb0374c94129e55b4 (patch)
tree046a894e945c680c58429b345969603c569373b8 /ui
parente2fb7d8aa218256793df99571d16f92074258447 (diff)
parentc82b7ef16f3efa59e28f821f25a9c084ef84ea9d (diff)
Merge tag 'darwin-20220315' of https://github.com/philmd/qemu into staging
Darwin-based host patches - Remove various build warnings - Fix building with modules on macOS - Fix mouse/keyboard GUI interactions # gpg: Signature made Tue 15 Mar 2022 12:52:19 GMT # gpg: using RSA key FAABE75E12917221DCFD6BB2E3E32C2CDEADC0DE # gpg: Good signature from "Philippe Mathieu-Daudé (F4BUG) <f4bug@amsat.org>" [unknown] # gpg: WARNING: This key is not certified with a trusted signature! # gpg: There is no indication that the signature belongs to the owner. # Primary key fingerprint: FAAB E75E 1291 7221 DCFD 6BB2 E3E3 2C2C DEAD C0DE * tag 'darwin-20220315' of https://github.com/philmd/qemu: (21 commits) MAINTAINERS: Volunteer to maintain Darwin-based hosts support ui/cocoa: add option to swap Option and Command ui/cocoa: capture all keys and combos when mouse is grabbed ui/cocoa: release mouse when user switches away from QEMU window ui/cocoa: add option to disable left-command forwarding to guest ui/cocoa: Constify qkeycode translation arrays configure: Pass filtered QEMU_OBJCFLAGS to meson meson: Log QEMU_CXXFLAGS content in summary meson: Resolve the entitlement.sh script once for good osdep: Avoid using Clang-specific __builtin_available() audio: Rename coreaudio extension to use Objective-C compiler coreaudio: Always return 0 in handle_voice_change audio: Log context for audio bug audio/dbus: Fix building with modules on macOS audio/coreaudio: Remove a deprecation warning on macOS 12 block/file-posix: Remove a deprecation warning on macOS 12 hvf: Remove deprecated hv_vcpu_flush() calls hvf: Make hvf_get_segments() / hvf_put_segments() local hvf: Use standard CR0 and CR4 register definitions tests/fp/berkeley-testfloat-3: Ignore ignored #pragma directives ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'ui')
-rw-r--r--ui/cocoa.m122
1 files changed, 111 insertions, 11 deletions
diff --git a/ui/cocoa.m b/ui/cocoa.m
index c88149852b..cb6e7c41dc 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -95,6 +95,8 @@ static DisplayChangeListener dcl = {
};
static int last_buttons;
static int cursor_hide = 1;
+static int left_command_key_enabled = 1;
+static bool swap_opt_cmd;
static int gArgc;
static char **gArgv;
@@ -308,11 +310,13 @@ static void handleAnyDeviceErrors(Error * err)
BOOL isMouseGrabbed;
BOOL isFullscreen;
BOOL isAbsoluteEnabled;
+ CFMachPortRef eventsTap;
}
- (void) switchSurface:(pixman_image_t *)image;
- (void) grabMouse;
- (void) ungrabMouse;
- (void) toggleFullScreen:(id)sender;
+- (void) setFullGrab:(id)sender;
- (void) handleMonitorInput:(NSEvent *)event;
- (bool) handleEvent:(NSEvent *)event;
- (bool) handleEventLocked:(NSEvent *)event;
@@ -335,6 +339,19 @@ static void handleAnyDeviceErrors(Error * err)
QemuCocoaView *cocoaView;
+static CGEventRef handleTapEvent(CGEventTapProxy proxy, CGEventType type, CGEventRef cgEvent, void *userInfo)
+{
+ QemuCocoaView *cocoaView = userInfo;
+ NSEvent *event = [NSEvent eventWithCGEvent:cgEvent];
+ if ([cocoaView isMouseGrabbed] && [cocoaView handleEvent:event]) {
+ COCOA_DEBUG("Global events tap: qemu handled the event, capturing!\n");
+ return NULL;
+ }
+ COCOA_DEBUG("Global events tap: qemu did not handle the event, letting it through...\n");
+
+ return cgEvent;
+}
+
@implementation QemuCocoaView
- (id)initWithFrame:(NSRect)frameRect
{
@@ -360,6 +377,11 @@ QemuCocoaView *cocoaView;
}
qkbd_state_free(kbd);
+
+ if (eventsTap) {
+ CFRelease(eventsTap);
+ }
+
[super dealloc];
}
@@ -654,6 +676,36 @@ QemuCocoaView *cocoaView;
}
}
+- (void) setFullGrab:(id)sender
+{
+ COCOA_DEBUG("QemuCocoaView: setFullGrab\n");
+
+ CGEventMask mask = CGEventMaskBit(kCGEventKeyDown) | CGEventMaskBit(kCGEventKeyUp) | CGEventMaskBit(kCGEventFlagsChanged);
+ eventsTap = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap, kCGEventTapOptionDefault,
+ mask, handleTapEvent, self);
+ if (!eventsTap) {
+ warn_report("Could not create event tap, system key combos will not be captured.\n");
+ return;
+ } else {
+ COCOA_DEBUG("Global events tap created! Will capture system key combos.\n");
+ }
+
+ CFRunLoopRef runLoop = CFRunLoopGetCurrent();
+ if (!runLoop) {
+ warn_report("Could not obtain current CF RunLoop, system key combos will not be captured.\n");
+ return;
+ }
+
+ CFRunLoopSourceRef tapEventsSrc = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventsTap, 0);
+ if (!tapEventsSrc ) {
+ warn_report("Could not obtain current CF RunLoop, system key combos will not be captured.\n");
+ return;
+ }
+
+ CFRunLoopAddSource(runLoop, tapEventsSrc, kCFRunLoopDefaultMode);
+ CFRelease(tapEventsSrc);
+}
+
- (void) toggleKey: (int)keycode {
qkbd_state_key_event(kbd, keycode, !qkbd_state_key_get(kbd, keycode));
}
@@ -671,7 +723,7 @@ QemuCocoaView *cocoaView;
/* translates Macintosh keycodes to QEMU's keysym */
- int without_control_translation[] = {
+ static const int without_control_translation[] = {
[0 ... 0xff] = 0, // invalid key
[kVK_UpArrow] = QEMU_KEY_UP,
@@ -686,7 +738,7 @@ QemuCocoaView *cocoaView;
[kVK_Delete] = QEMU_KEY_BACKSPACE,
};
- int with_control_translation[] = {
+ static const int with_control_translation[] = {
[0 ... 0xff] = 0, // invalid key
[kVK_UpArrow] = QEMU_KEY_CTRL_UP,
@@ -803,12 +855,22 @@ QemuCocoaView *cocoaView;
qkbd_state_key_event(kbd, Q_KEY_CODE_CTRL_R, false);
}
if (!(modifiers & NSEventModifierFlagOption)) {
- qkbd_state_key_event(kbd, Q_KEY_CODE_ALT, false);
- qkbd_state_key_event(kbd, Q_KEY_CODE_ALT_R, false);
+ if (swap_opt_cmd) {
+ qkbd_state_key_event(kbd, Q_KEY_CODE_META_L, false);
+ qkbd_state_key_event(kbd, Q_KEY_CODE_META_R, false);
+ } else {
+ qkbd_state_key_event(kbd, Q_KEY_CODE_ALT, false);
+ qkbd_state_key_event(kbd, Q_KEY_CODE_ALT_R, false);
+ }
}
if (!(modifiers & NSEventModifierFlagCommand)) {
- qkbd_state_key_event(kbd, Q_KEY_CODE_META_L, false);
- qkbd_state_key_event(kbd, Q_KEY_CODE_META_R, false);
+ if (swap_opt_cmd) {
+ qkbd_state_key_event(kbd, Q_KEY_CODE_ALT, false);
+ qkbd_state_key_event(kbd, Q_KEY_CODE_ALT_R, false);
+ } else {
+ qkbd_state_key_event(kbd, Q_KEY_CODE_META_L, false);
+ qkbd_state_key_event(kbd, Q_KEY_CODE_META_R, false);
+ }
}
switch ([event type]) {
@@ -840,13 +902,21 @@ QemuCocoaView *cocoaView;
case kVK_Option:
if (!!(modifiers & NSEventModifierFlagOption)) {
- [self toggleKey:Q_KEY_CODE_ALT];
+ if (swap_opt_cmd) {
+ [self toggleKey:Q_KEY_CODE_META_L];
+ } else {
+ [self toggleKey:Q_KEY_CODE_ALT];
+ }
}
break;
case kVK_RightOption:
if (!!(modifiers & NSEventModifierFlagOption)) {
- [self toggleKey:Q_KEY_CODE_ALT_R];
+ if (swap_opt_cmd) {
+ [self toggleKey:Q_KEY_CODE_META_R];
+ } else {
+ [self toggleKey:Q_KEY_CODE_ALT_R];
+ }
}
break;
@@ -854,14 +924,22 @@ QemuCocoaView *cocoaView;
case kVK_Command:
if (isMouseGrabbed &&
!!(modifiers & NSEventModifierFlagCommand)) {
- [self toggleKey:Q_KEY_CODE_META_L];
+ if (swap_opt_cmd) {
+ [self toggleKey:Q_KEY_CODE_ALT];
+ } else {
+ [self toggleKey:Q_KEY_CODE_META_L];
+ }
}
break;
case kVK_RightCommand:
if (isMouseGrabbed &&
!!(modifiers & NSEventModifierFlagCommand)) {
- [self toggleKey:Q_KEY_CODE_META_R];
+ if (swap_opt_cmd) {
+ [self toggleKey:Q_KEY_CODE_ALT_R];
+ } else {
+ [self toggleKey:Q_KEY_CODE_META_R];
+ }
}
break;
}
@@ -1259,6 +1337,7 @@ QemuCocoaView *cocoaView;
- (void) applicationWillResignActive: (NSNotification *)aNotification
{
COCOA_DEBUG("QemuCocoaAppController: applicationWillResignActive\n");
+ [cocoaView ungrabMouse];
[cocoaView raiseAllKeys];
}
@@ -1278,6 +1357,13 @@ QemuCocoaView *cocoaView;
[cocoaView toggleFullScreen:sender];
}
+- (void) setFullGrab:(id)sender
+{
+ COCOA_DEBUG("QemuCocoaAppController: setFullGrab\n");
+
+ [cocoaView setFullGrab:sender];
+}
+
/* Tries to find then open the specified filename */
- (void) openDocumentation: (NSString *) filename
{
@@ -1991,16 +2077,30 @@ static void cocoa_display_init(DisplayState *ds, DisplayOptions *opts)
qemu_sem_wait(&app_started_sem);
COCOA_DEBUG("cocoa_display_init: app start completed\n");
+ QemuCocoaAppController *controller = (QemuCocoaAppController *)[[NSApplication sharedApplication] delegate];
/* if fullscreen mode is to be used */
if (opts->has_full_screen && opts->full_screen) {
dispatch_async(dispatch_get_main_queue(), ^{
[NSApp activateIgnoringOtherApps: YES];
- [(QemuCocoaAppController *)[[NSApplication sharedApplication] delegate] toggleFullScreen: nil];
+ [controller toggleFullScreen: nil];
+ });
+ }
+ if (opts->u.cocoa.has_full_grab && opts->u.cocoa.full_grab) {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [controller setFullGrab: nil];
});
}
+
if (opts->has_show_cursor && opts->show_cursor) {
cursor_hide = 0;
}
+ if (opts->u.cocoa.has_swap_opt_cmd) {
+ swap_opt_cmd = opts->u.cocoa.swap_opt_cmd;
+ }
+
+ if (opts->u.cocoa.has_left_command_key && !opts->u.cocoa.left_command_key) {
+ left_command_key_enabled = 0;
+ }
// register vga output callbacks
register_displaychangelistener(&dcl);