mirror of https://github.com/xqemu/xqemu.git
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> Message-id: 1403516125-14568-3-git-send-email-peter.maydell@linaro.org
This commit is contained in:
parent
381600dad9
commit
5dd45bee58
|
@ -305,6 +305,11 @@ QemuCocoaView *cocoaView;
|
||||||
return YES;
|
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
|
- (void) drawRect:(NSRect) rect
|
||||||
{
|
{
|
||||||
COCOA_DEBUG("QemuCocoaView: drawRect\n");
|
COCOA_DEBUG("QemuCocoaView: drawRect\n");
|
||||||
|
@ -607,7 +612,7 @@ QemuCocoaView *cocoaView;
|
||||||
break;
|
break;
|
||||||
case NSMouseMoved:
|
case NSMouseMoved:
|
||||||
if (isAbsoluteEnabled) {
|
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
|
if (isTabletEnabled) { // if we leave the window, deactivate the tablet
|
||||||
[NSCursor unhide];
|
[NSCursor unhide];
|
||||||
isTabletEnabled = FALSE;
|
isTabletEnabled = FALSE;
|
||||||
|
@ -657,7 +662,7 @@ QemuCocoaView *cocoaView;
|
||||||
if (isTabletEnabled) {
|
if (isTabletEnabled) {
|
||||||
mouse_event = true;
|
mouse_event = true;
|
||||||
} else if (!isMouseGrabbed) {
|
} else if (!isMouseGrabbed) {
|
||||||
if (p.x > -1 && p.x < screen.width && p.y > -1 && p.y < screen.height) {
|
if ([self screenContainsPoint:p]) {
|
||||||
[self grabMouse];
|
[self grabMouse];
|
||||||
} else {
|
} else {
|
||||||
[NSApp sendEvent:event];
|
[NSApp sendEvent:event];
|
||||||
|
|
Loading…
Reference in New Issue