]> git.proxmox.com Git - mirror_qemu.git/commitdiff
ui/cocoa: Add utility method to check if point is within window
authorPeter Maydell <peter.maydell@linaro.org>
Mon, 23 Jun 2014 09:35:23 +0000 (10:35 +0100)
committerPeter Maydell <peter.maydell@linaro.org>
Sun, 29 Jun 2014 21:00:33 +0000 (22:00 +0100)
Add a utility method to check whether a point is within the current window
bounds, and use it in the various places in the mouse handling code that
were opencoding the check.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Message-id: 1403516125-14568-3-git-send-email-peter.maydell@linaro.org

ui/cocoa.m

index a270a464d8c134424e748bf98fec77978a3c03cd..1a626e215fc7bf3ca4ba751a7ac352afbec214f4 100644 (file)
@@ -305,6 +305,11 @@ QemuCocoaView *cocoaView;
     return YES;
 }
 
+- (BOOL) screenContainsPoint:(NSPoint) p
+{
+    return (p.x > -1 && p.x < screen.width && p.y > -1 && p.y < screen.height);
+}
+
 - (void) drawRect:(NSRect) rect
 {
     COCOA_DEBUG("QemuCocoaView: drawRect\n");
@@ -607,7 +612,7 @@ QemuCocoaView *cocoaView;
             break;
         case NSMouseMoved:
             if (isAbsoluteEnabled) {
-                if (p.x < 0 || p.x > screen.width || p.y < 0 || p.y > screen.height || ![[self window] isKeyWindow]) {
+                if (![self screenContainsPoint:p] || ![[self window] isKeyWindow]) {
                     if (isTabletEnabled) { // if we leave the window, deactivate the tablet
                         [NSCursor unhide];
                         isTabletEnabled = FALSE;
@@ -657,7 +662,7 @@ QemuCocoaView *cocoaView;
             if (isTabletEnabled) {
                     mouse_event = true;
             } else if (!isMouseGrabbed) {
-                if (p.x > -1 && p.x < screen.width && p.y > -1 && p.y < screen.height) {
+                if ([self screenContainsPoint:p]) {
                     [self grabMouse];
                 } else {
                     [NSApp sendEvent:event];