diff mbox series

[1/2] ui/cocoa: Fix absolute input device grabbing issues on Mojave

Message ID 3F771462-AC5B-4CAC-939F-6E24F43B9FF5@me.com (mailing list archive)
State New, archived
Headers show
Series [1/2] ui/cocoa: Fix absolute input device grabbing issues on Mojave | expand

Commit Message

Gonglei (Arei)" via March 15, 2019, 10:47 a.m. UTC
Signed-off-by: Chen Zhang <tgfbeta@me.com <mailto:tgfbeta@me.com>>
---
ui/cocoa.m | 29 +++++++++++++++++++++++++----
1 file changed, 25 insertions(+), 4 deletions(-)

            break;
        case NSEventTypeMouseMoved:
            if (isAbsoluteEnabled) {
-                if (![self screenContainsPoint:p] || ![[self window] isKeyWindow]) {
+                BOOL is_key_window = [[self window] isKeyWindow];
+                BOOL is_in_screen =  [self screenContainsPointOfEvent: event];
+                if (!is_in_screen || !is_key_window) {
                    if (isMouseGrabbed) {
                        [self ungrabMouse];
                    }
@@ -927,9 +947,10 @@ QemuCocoaView *cocoaView;
                 * The check on screenContainsPoint is to avoid sending out of range values for
                 * clicks in the titlebar.
                 */
-                if ([self screenContainsPoint:p]) {
-                    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);
+                if ([self screenContainsPointOfEvent:event]) {
+                    CGPoint loc = [self screenLocationOfEvent: event];
+                    qemu_input_queue_abs(dcl->con, INPUT_AXIS_X, loc.x, 0, screen.width);
+                    qemu_input_queue_abs(dcl->con, INPUT_AXIS_Y, screen.height - loc.y, 0, screen.height);
                }
            } else {
                qemu_input_queue_rel(dcl->con, INPUT_AXIS_X, (int)[event deltaX]);
diff mbox series

Patch

diff --git a/ui/cocoa.m b/ui/cocoa.m
index 420b2411c1..5d0a6599d9 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -405,6 +405,24 @@  QemuCocoaView *cocoaView;
    return (p.x > -1 && p.x < screen.width && p.y > -1 && p.y < screen.height);
}

+/* Get location of event and convert to virtual screen coordinate */
+- (CGPoint) screenLocationOfEvent:(NSEvent *)ev
+{
+    NSWindow *eventWindow = [ev window];
+    if (!eventWindow) {
+	return [self.window convertPointFromScreen:[ev locationInWindow]];
+    } else if ([self.window isEqual:eventWindow]) {
+        return [ev locationInWindow];
+    } else {
+        return [self.window convertPointFromScreen:[eventWindow convertPointToScreen:[ev locationInWindow]]];
+    }
+}
+
+- (BOOL) screenContainsPointOfEvent:(NSEvent *)ev
+{
+    return [self screenContainsPoint:[self screenLocationOfEvent:ev]];
+}
+
- (void) hideCursor
{
    if (!cursor_hide) {
@@ -815,7 +833,9 @@  QemuCocoaView *cocoaView;