From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43855) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X1b22-0007nL-3F for qemu-devel@nongnu.org; Mon, 30 Jun 2014 08:50:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X1b1x-0006rk-1D for qemu-devel@nongnu.org; Mon, 30 Jun 2014 08:50:02 -0400 Received: from mnementh.archaic.org.uk ([2001:8b0:1d0::1]:48767) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X1b1w-0006qf-Pu for qemu-devel@nongnu.org; Mon, 30 Jun 2014 08:49:56 -0400 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1X1b1v-0008VF-4L for qemu-devel@nongnu.org; Mon, 30 Jun 2014 13:49:55 +0100 From: Peter Maydell Date: Mon, 30 Jun 2014 13:49:53 +0100 Message-Id: <1404132595-32651-3-git-send-email-peter.maydell@linaro.org> In-Reply-To: <1404132595-32651-1-git-send-email-peter.maydell@linaro.org> References: <1404132595-32651-1-git-send-email-peter.maydell@linaro.org> Subject: [Qemu-devel] [PULL 2/4] ui/cocoa: Add utility method to check if point is within window List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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 Message-id: 1403516125-14568-3-git-send-email-peter.maydell@linaro.org --- ui/cocoa.m | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index a270a46..1a626e2 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -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]; -- 1.9.1