From patchwork Mon Jun 23 09:35:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 32342 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pb0-f72.google.com (mail-pb0-f72.google.com [209.85.160.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 427B620540 for ; Mon, 23 Jun 2014 09:37:44 +0000 (UTC) Received: by mail-pb0-f72.google.com with SMTP id ma3sf24974188pbc.11 for ; Mon, 23 Jun 2014 02:37:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=ZuOSpLdU6N/MEw4uZt7ZAhcOErYrA3mapaY0T7z3n8M=; b=RKx9GX0aUEFKCW6VEkzTuSPGeemnMeWBfdygmq2b7WqXxVEiTxD8mfJj8O6ElzWMHY sCsvIXgr2QZrE/bLEfrrXt28W66f5UOU50BXfb2ZrrRt2EU3GMD5cTY4POX4V6OCyQvR u+l+Cygb2mZucVfvWC7PpZsWjz7Ow1ouekK3n55rAU/t6NCWuW6B1cEWDi1lRVubCkRU qwO+K3lSghotNts7JNLVA0t8xAQB+rwe/nFP5Zel/jkOvEHHSqnN7WIbEdZXTa75sQOU nXGILsr+DFzFjgZ/sRuLOUozap62y/8Oh+mnjYuYR7/YepeLFl213noI3azmTo9fd/UB zf6Q== X-Gm-Message-State: ALoCoQlyJ6YI7m8v0lEmQL3MiFBtBfcQBHwv1v2mPz0r1JhYY88T7+99Y9eANOCchxlJtfkGIFvF X-Received: by 10.66.122.137 with SMTP id ls9mr9069440pab.17.1403516263446; Mon, 23 Jun 2014 02:37:43 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.40.74 with SMTP id w68ls1921333qgw.53.gmail; Mon, 23 Jun 2014 02:37:43 -0700 (PDT) X-Received: by 10.58.160.10 with SMTP id xg10mr18914748veb.0.1403516263323; Mon, 23 Jun 2014 02:37:43 -0700 (PDT) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by mx.google.com with ESMTPS id y3si8069198vdx.29.2014.06.23.02.37.43 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 23 Jun 2014 02:37:43 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.174 as permitted sender) client-ip=209.85.220.174; Received: by mail-vc0-f174.google.com with SMTP id hy4so5693086vcb.33 for ; Mon, 23 Jun 2014 02:37:43 -0700 (PDT) X-Received: by 10.52.26.237 with SMTP id o13mr15340227vdg.1.1403516263245; Mon, 23 Jun 2014 02:37:43 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp117489vcb; Mon, 23 Jun 2014 02:37:42 -0700 (PDT) X-Received: by 10.224.7.6 with SMTP id b6mr30622936qab.45.1403516262840; Mon, 23 Jun 2014 02:37:42 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id b4si13967591qae.77.2014.06.23.02.37.42 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 23 Jun 2014 02:37:42 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:52343 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wz0h4-0001SY-Fz for patch@linaro.org; Mon, 23 Jun 2014 05:37:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60134) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wz0f3-0006zt-Kl for qemu-devel@nongnu.org; Mon, 23 Jun 2014 05:35:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wz0ez-00062R-OF for qemu-devel@nongnu.org; Mon, 23 Jun 2014 05:35:37 -0400 Received: from mnementh.archaic.org.uk ([2001:8b0:1d0::1]:48670) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wz0ez-00061e-Ht for qemu-devel@nongnu.org; Mon, 23 Jun 2014 05:35:33 -0400 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1Wz0er-0003nY-64; Mon, 23 Jun 2014 10:35:25 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 23 Jun 2014 10:35:23 +0100 Message-Id: <1403516125-14568-3-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1403516125-14568-1-git-send-email-peter.maydell@linaro.org> References: <1403516125-14568-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:8b0:1d0::1 Cc: =?UTF-8?q?Andreas=20F=C3=A4rber?= , Gerd Hoffmann Subject: [Qemu-devel] [PATCH 2/4] ui/cocoa: Add utility method to check if point is within window X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.174 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 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 --- 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];