summaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
Diffstat (limited to 'ui')
-rw-r--r--ui/cocoa.m65
1 files changed, 64 insertions, 1 deletions
diff --git a/ui/cocoa.m b/ui/cocoa.m
index d20c74d938..b1250b7408 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -309,11 +309,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;
@@ -336,6 +338,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
{
@@ -361,6 +376,11 @@ QemuCocoaView *cocoaView;
}
qkbd_state_free(kbd);
+
+ if (eventsTap) {
+ CFRelease(eventsTap);
+ }
+
[super dealloc];
}
@@ -655,6 +675,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));
}
@@ -1281,6 +1331,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
{
@@ -1994,11 +2051,17 @@ 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];
});
}