qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 2/4] ui/cocoa: Add utility method to check if point is within window
Date: Mon, 30 Jun 2014 13:49:53 +0100	[thread overview]
Message-ID: <1404132595-32651-3-git-send-email-peter.maydell@linaro.org> (raw)
In-Reply-To: <1404132595-32651-1-git-send-email-peter.maydell@linaro.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 <peter.maydell@linaro.org>
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

  parent reply	other threads:[~2014-06-30 12:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-30 12:49 [Qemu-devel] [PULL 0/4] cocoa queue Peter Maydell
2014-06-30 12:49 ` [Qemu-devel] [PULL 1/4] ui/cocoa: Cope with first surface being same as initial window size Peter Maydell
2014-06-30 12:49 ` Peter Maydell [this message]
2014-06-30 12:49 ` [Qemu-devel] [PULL 3/4] ui/cocoa: Fix handling of absolute positioning devices Peter Maydell
2014-06-30 12:49 ` [Qemu-devel] [PULL 4/4] ui/cocoa: Honour -show-cursor command line option Peter Maydell
2014-06-30 14:55 ` [Qemu-devel] [PULL 0/4] cocoa queue Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1404132595-32651-3-git-send-email-peter.maydell@linaro.org \
    --to=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).