[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 1/2] ui/cocoa: Fix absolute input device grabbing is
From: |
Chen Zhang |
Subject: |
[Qemu-devel] [PATCH 1/2] ui/cocoa: Fix absolute input device grabbing issues on Mojave |
Date: |
Fri, 15 Mar 2019 18:47:59 +0800 |
Signed-off-by: Chen Zhang <address@hidden <mailto:address@hidden>>
---
ui/cocoa.m | 29 +++++++++++++++++++++++++----
1 file changed, 25 insertions(+), 4 deletions(-)
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;
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]);
--
2.19.2