aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2014-06-22 19:33:45 +0100
committerPeter Maydell <peter.maydell@linaro.org>2014-06-23 10:41:36 +0100
commit5ecaecb53f43f1f3e274c2a98e0cf0fb0a6d734a (patch)
tree2f8ab44c81c0e04a07ba14adac6dba723cdf0ad1
parent380eead74413f7f934c7926912c6a52c9917bbc9 (diff)
downloadqemu-arm-5ecaecb53f43f1f3e274c2a98e0cf0fb0a6d734a.tar.gz
ui/cocoa: Add utility method to check if point is within window
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>
-rw-r--r--ui/cocoa.m9
1 files changed, 7 insertions, 2 deletions
diff --git a/ui/cocoa.m b/ui/cocoa.m
index a270a464d8..1a626e215f 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];