From patchwork Sun Apr 28 03:31:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cameron Esfahani via X-Patchwork-Id: 1092145 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=nongnu.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=me.com header.i=@me.com header.b="2bujfJh8"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44sD5b56TXz9s9N for ; Sun, 28 Apr 2019 13:38:07 +1000 (AEST) Received: from localhost ([127.0.0.1]:39233 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hKadh-0001wb-6L for incoming@patchwork.ozlabs.org; Sat, 27 Apr 2019 23:38:05 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33558) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hKacy-0001sr-OL for qemu-devel@nongnu.org; Sat, 27 Apr 2019 23:37:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hKaXE-0005t0-Is for qemu-devel@nongnu.org; Sat, 27 Apr 2019 23:31:26 -0400 Received: from pv50p00im-ztdg10011301.me.com ([17.58.6.40]:21651) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hKaXE-0005sU-AO for qemu-devel@nongnu.org; Sat, 27 Apr 2019 23:31:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=04042017; t=1556422283; bh=RaCyOJ8X3bdfgOf1c7VF+2sH9Xvo3ugHJ8Wxturnu8Q=; h=From:Message-Id:Content-Type:Mime-Version:Subject:Date:To; b=2bujfJh8HjOMI5zStrAOJi4mJW2JhxvTqXHvRIohcAEJ+zc27sTiEmGeuSY0MOeNM Y9eBdgyZbcz9YG8FbeTQoxwJP+rXCCST2uTYivDi1r2fSNnz5Xq3fapSr//xmKoXkz +7MTadXJbFtcQaYvjs1KBOJiDopoBp7jItMqpulF/UFV0PHUNFf7BsbPdeCBr+Z2p2 NPq1e7JM+g1LAa5zlw2A/r8GjwT/e0kCQZCYPBpu5I6saW/HkhiNc5cCe4DucdwWp4 b51t6I2Mn4N1JGinFRRHD8VU80oBwpS3+nfha/EegFOP0F6IC0Koe0QZ0OyAltmPj9 1RxZMvORaJPRA== Received: from [172.18.2.102] (unknown [36.106.167.46]) by pv50p00im-ztdg10011301.me.com (Postfix) with ESMTPSA id C94CE6400FC; Sun, 28 Apr 2019 03:31:20 +0000 (UTC) Message-Id: Mime-Version: 1.0 (Mac OS X Mail 12.2 \(3445.102.3\)) Date: Sun, 28 Apr 2019 11:31:17 +0800 In-Reply-To: <4EAA64FC-AA22-4B01-8BC4-49DAC694963B@me.com> To: Peter Maydell , Gerd Hoffmann References: <4EAA64FC-AA22-4B01-8BC4-49DAC694963B@me.com> X-Mailer: Apple Mail (2.3445.102.3) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-04-28_03:, , signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1812120000 definitions=main-1904280022 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 17.58.6.40 X-Content-Filtered-By: Mailman/MimeDel 2.1.21 Subject: [Qemu-devel] [PATCH RESEND 1/2] ui/cocoa: Fix absolute input device grabbing issue on Mojave X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Chen Zhang via Qemu-devel From: Cameron Esfahani via Reply-To: Chen Zhang Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This patches fixed boundary check methods for cursor in normal and fullscreen modes with/without Zoom-to-Fit on Mojave. On Mojave, absolute input device, i.e. tablet, had trouble re-grabbing the cursor in re-entry into the virtual screen area. In some cases, the `window` property of NSEvent object was nil after exit of cursor, meaning that the `-locationInWindow` method would return value in screen coordinates. The current implementation used raw locations frrom NSEvent without considering whether the value was for the window coordinates or the macOS screen coordinates, nor the zooming factor for Zoom-to-Fit in fullscreen mode. In fullscreen mode, the fullscreen cocoa window might not be the key window, therefore the location of event in virtual coordinates should suffice. Note: CGRect, -convertRectToScreen: and -convertRectFromScreen: were used in coordinates conversion for compatibility reason. Signed-off-by: Chen Zhang > --- ui/cocoa.m | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) int keycode = 0; bool mouse_event = false; static bool switched_to_fullscreen = false; - NSPoint p = [event locationInWindow]; + // Location of event in virtual screen coordinates + NSPoint p = [self screenLocationOfEvent:event]; switch ([event type]) { case NSEventTypeFlagsChanged: @@ -815,7 +851,10 @@ QemuCocoaView *cocoaView; break; case NSEventTypeMouseMoved: if (isAbsoluteEnabled) { - if (![self screenContainsPoint:p] || ![[self window] isKeyWindow]) { + // Cursor re-entered into a window might generate events bound to screen coordinates + // and `nil` window property, and in full screen mode, current window might not be + // key window, where event location alone should suffice. + if (![self screenContainsPoint:p] || !([[self window] isKeyWindow] || isFullscreen)) { if (isMouseGrabbed) { [self ungrabMouse]; } diff --git a/ui/cocoa.m b/ui/cocoa.m index 420b2411c1..474d44cb9f 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -405,6 +405,41 @@ QemuCocoaView *cocoaView; return (p.x > -1 && p.x < screen.width && p.y > -1 && p.y < screen.height); } +/* Get location of event and convert to virtual screen coordinate */ +- (CGPoint) screenLocationOfEvent:(NSEvent *)ev +{ + NSWindow *eventWindow = [ev window]; + // XXX: Use CGRect and -convertRectFromScreen: to support macOS 10.10 + CGRect r = CGRectZero; + r.origin = [ev locationInWindow]; + if (!eventWindow) { + if (!isFullscreen) { + return [[self window] convertRectFromScreen:r].origin; + } else { + CGPoint locationInSelfWindow = [[self window] convertRectFromScreen:r].origin; + CGPoint loc = [self convertPoint:locationInSelfWindow fromView:nil]; + if (stretch_video) { + loc.x /= cdx; + loc.y /= cdy; + } + return loc; + } + } else if ([[self window] isEqual:eventWindow]) { + if (!isFullscreen) { + return r.origin; + } else { + CGPoint loc = [self convertPoint:r.origin fromView:nil]; + if (stretch_video) { + loc.x /= cdx; + loc.y /= cdy; + } + return loc; + } + } else { + return [[self window] convertRectFromScreen:[eventWindow convertRectToScreen:r]].origin; + } +} + - (void) hideCursor { if (!cursor_hide) { @@ -704,7 +739,8 @@ QemuCocoaView *cocoaView;