From patchwork Mon Jun 30 12:49:53 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 32715 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f200.google.com (mail-ob0-f200.google.com [209.85.214.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8AAF8203F4 for ; Mon, 30 Jun 2014 12:53:31 +0000 (UTC) Received: by mail-ob0-f200.google.com with SMTP id wm4sf51009018obc.11 for ; Mon, 30 Jun 2014 05:53:31 -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: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=OdVK1ZoZd0oydcO5rINwtW3DSSgKqMNfo9Wu02VaXgI=; b=C885WK8ztV9ZhJhtkOocU19+/s0l4vI0BbEhKrYmqu6v9F3RR+2W4jZhtBhJUOD9fM Ii1nxPJiIgQqkCJz977jfzyEE9z6JYaPKadm1mCYSHO5UiSRlhkJIAsnh7Wp79K2/TM7 pGWluOurRJRO6BZ0XIsPm/F8hbX/TkzhAJqm5QtBT08IZRkKSXHZjbcPa2c00jv4uNMj R0YwBwUv7lKrn7mUuM/jqfFtaZGQhn37gPL15MAzEx/gXR1LLvYYhdxsNuetpbpE26KB 2HPCQ5kR3KBR9mc2v9ET5JBJNpG24ifvnsGVVyF+vYLU0borcwCOjxZE+Fe4SC+kyaiW NBEQ== X-Gm-Message-State: ALoCoQnzhNYxgoK1nvX1Bctu5/DGb5aM04tuuBaYR83oIP1ZcGM7BxbOEs9PfJ9CybIbQhYiPQ98 X-Received: by 10.50.126.100 with SMTP id mx4mr4449437igb.6.1404132811156; Mon, 30 Jun 2014 05:53:31 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.46.99 with SMTP id j90ls1461575qga.49.gmail; Mon, 30 Jun 2014 05:53:31 -0700 (PDT) X-Received: by 10.52.69.133 with SMTP id e5mr188743vdu.66.1404132811065; Mon, 30 Jun 2014 05:53:31 -0700 (PDT) Received: from mail-ve0-f174.google.com (mail-ve0-f174.google.com [209.85.128.174]) by mx.google.com with ESMTPS id fa3si9953551vdc.63.2014.06.30.05.53.31 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 30 Jun 2014 05:53:31 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.174 as permitted sender) client-ip=209.85.128.174; Received: by mail-ve0-f174.google.com with SMTP id jx11so8072294veb.19 for ; Mon, 30 Jun 2014 05:53:31 -0700 (PDT) X-Received: by 10.52.248.146 with SMTP id ym18mr31857149vdc.8.1404132810997; Mon, 30 Jun 2014 05:53:30 -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 tc5csp136117vcb; Mon, 30 Jun 2014 05:53:30 -0700 (PDT) X-Received: by 10.224.60.137 with SMTP id p9mr61862048qah.70.1404132810530; Mon, 30 Jun 2014 05:53:30 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id p93si25179653qga.38.2014.06.30.05.53.30 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 30 Jun 2014 05:53:30 -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]:34110 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X1b5O-0003v0-8B for patch@linaro.org; Mon, 30 Jun 2014 08:53:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43855) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X1b22-0007nL-3F for qemu-devel@nongnu.org; Mon, 30 Jun 2014 08:50:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X1b1x-0006rk-1D for qemu-devel@nongnu.org; Mon, 30 Jun 2014 08:50:02 -0400 Received: from mnementh.archaic.org.uk ([2001:8b0:1d0::1]:48767) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X1b1w-0006qf-Pu for qemu-devel@nongnu.org; Mon, 30 Jun 2014 08:49:56 -0400 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1X1b1v-0008VF-4L for qemu-devel@nongnu.org; Mon, 30 Jun 2014 13:49:55 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 30 Jun 2014 13:49:53 +0100 Message-Id: <1404132595-32651-3-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1404132595-32651-1-git-send-email-peter.maydell@linaro.org> References: <1404132595-32651-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 Subject: [Qemu-devel] [PULL 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.128.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 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];