Skip to content

Commit

Permalink
ui/cocoa: Add utility method to check if point is within window
Browse files Browse the repository at this point in the history
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 <[email protected]>
Message-id: [email protected]
  • Loading branch information
pm215 committed Jun 29, 2014
1 parent 381600d commit 5dd45be
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions ui/cocoa.m
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ - (BOOL) isOpaque
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");
Expand Down Expand Up @@ -607,7 +612,7 @@ - (void) handleEvent:(NSEvent *)event
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;
Expand Down Expand Up @@ -657,7 +662,7 @@ - (void) handleEvent:(NSEvent *)event
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];
Expand Down

0 comments on commit 5dd45be

Please sign in to comment.