summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
Diffstat (limited to 'ui')
-rw-r--r--ui/cocoa.m122
-rw-r--r--ui/gtk.c4
-rw-r--r--ui/vnc-enc-tight.c2
-rw-r--r--ui/vnc.c26
4 files changed, 133 insertions, 21 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);
diff --git a/ui/gtk.c b/ui/gtk.c
index 1b24a67d79..c57c36749e 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -972,6 +972,10 @@ static gboolean gd_button_event(GtkWidget *widget, GdkEventButton *button,
return TRUE;
}
+ if (button->type == GDK_2BUTTON_PRESS || button->type == GDK_3BUTTON_PRESS) {
+ return TRUE;
+ }
+
qemu_input_queue_btn(vc->gfx.dcl.con, btn,
button->type == GDK_BUTTON_PRESS);
qemu_input_event_sync();
diff --git a/ui/vnc-enc-tight.c b/ui/vnc-enc-tight.c
index cebd35841a..7b86a4713d 100644
--- a/ui/vnc-enc-tight.c
+++ b/ui/vnc-enc-tight.c
@@ -1477,7 +1477,7 @@ static int send_sub_rect(VncState *vs, int x, int y, int w, int h)
#endif
if (!color_count_palette) {
- color_count_palette = g_malloc(sizeof(VncPalette));
+ color_count_palette = g_new(VncPalette, 1);
vnc_tight_cleanup_notifier.notify = vnc_tight_cleanup;
qemu_thread_atexit_add(&vnc_tight_cleanup_notifier);
}
diff --git a/ui/vnc.c b/ui/vnc.c
index 3ccd33dedc..310a873c21 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -3098,6 +3098,9 @@ static int vnc_refresh_server_surface(VncDisplay *vd)
VncState *vs;
int has_dirty = 0;
pixman_image_t *tmpbuf = NULL;
+ unsigned long offset;
+ int x;
+ uint8_t *guest_ptr, *server_ptr;
struct timeval tv = { 0, 0 };
@@ -3106,6 +3109,13 @@ static int vnc_refresh_server_surface(VncDisplay *vd)
has_dirty = vnc_update_stats(vd, &tv);
}
+ offset = find_next_bit((unsigned long *) &vd->guest.dirty,
+ height * VNC_DIRTY_BPL(&vd->guest), 0);
+ if (offset == height * VNC_DIRTY_BPL(&vd->guest)) {
+ /* no dirty bits in guest surface */
+ return has_dirty;
+ }
+
/*
* Walk through the guest dirty map.
* Check and copy modified bits from guest to server surface.
@@ -3130,15 +3140,6 @@ static int vnc_refresh_server_surface(VncDisplay *vd)
line_bytes = MIN(server_stride, guest_ll);
for (;;) {
- int x;
- uint8_t *guest_ptr, *server_ptr;
- unsigned long offset = find_next_bit((unsigned long *) &vd->guest.dirty,
- height * VNC_DIRTY_BPL(&vd->guest),
- y * VNC_DIRTY_BPL(&vd->guest));
- if (offset == height * VNC_DIRTY_BPL(&vd->guest)) {
- /* no more dirty bits */
- break;
- }
y = offset / VNC_DIRTY_BPL(&vd->guest);
x = offset % VNC_DIRTY_BPL(&vd->guest);
@@ -3177,6 +3178,13 @@ static int vnc_refresh_server_surface(VncDisplay *vd)
}
y++;
+ offset = find_next_bit((unsigned long *) &vd->guest.dirty,
+ height * VNC_DIRTY_BPL(&vd->guest),
+ y * VNC_DIRTY_BPL(&vd->guest));
+ if (offset == height * VNC_DIRTY_BPL(&vd->guest)) {
+ /* no more dirty bits */
+ break;
+ }
}
qemu_pixman_image_unref(tmpbuf);
return has_dirty;