From nobody Sun May 19 19:10:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552967601729281.8290924231128; Mon, 18 Mar 2019 20:53:21 -0700 (PDT) Received: from localhost ([127.0.0.1]:51023 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h65oN-0007J5-F1 for importer@patchew.org; Mon, 18 Mar 2019 23:53:11 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35063) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h65nD-0006qO-7x for qemu-devel@nongnu.org; Mon, 18 Mar 2019 23:52:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h65nC-0000Uz-32 for qemu-devel@nongnu.org; Mon, 18 Mar 2019 23:51:59 -0400 Received: from ms11p00im-qufo17281801.me.com ([17.58.38.55]:36819) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h65n7-0000Ln-CF for qemu-devel@nongnu.org; Mon, 18 Mar 2019 23:51:57 -0400 Received: from [172.18.2.102] (unknown [36.106.166.130]) by ms11p00im-qufo17281801.me.com (Postfix) with ESMTPSA id B4795100101; Tue, 19 Mar 2019 03:51:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=04042017; t=1552967511; bh=9sYF6RFuosPSi7f2Z09xZQP9Buu4l2F5yEYHjN+46DI=; h=From:Content-Type:Mime-Version:Subject:Message-Id:Date:To; b=6PAz5jk3jgyCSByLjnpfvVA4Buq5JqaeCQqAbO9YI6YBIzFSWQG66XihOnc+WPsW6 AlUH1ZX979OECInQDT8+ZZA6ikfdSceFGJrDGyRA2U6Ujbx393G3U964L6fe4JHhyq szS7vInkSxyD8LhN+H+QHb49tYwV6O4NEoXgLs+3RmEMrA7xkk9MYtBiBKq8gzngvC KLJyj1ni+1NOkIObfb1zT+zTuTCTC1h0P+a+4XJEcyBQRVSiSTWKjENk7eIYCfqwsD UsDL+I4bBkPbQ+5BmQflQZzDEp/WAal/TN8Mp5N9gho/+tSUShupvrhp9z8Ce4sE1R ocbLJRPMC21Ww== Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 12.2 \(3445.102.3\)) Message-Id: <2D646E18-7F28-4F06-9F3D-D5F8A1408FAC@me.com> Date: Tue, 19 Mar 2019 11:51:48 +0800 To: qemu-devel@nongnu.org X-Mailer: Apple Mail (2.3445.102.3) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-03-19_02:, , signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 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-1903190027 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 17.58.38.55 Subject: [Qemu-devel] [PATCH v2] ui/cocoa: Fix absolute input device grabbing issues 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: , From: Chen Zhang via Qemu-devel Reply-To: Chen Zhang Cc: Peter Maydell , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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 is nil, after exit of cursor, meaning that the `-locationInWindow` method would return value in screen coordinates. Current implementation used raw locations from NSEvent without considering whether the value was for the window coordinates or the macOS screen coordinates, nor was the zooming factor for Zoom-to-Fit included for fullscreen mode. In fullscreen mode, the fullscreen cocoa window might not be the key=20 window, therefore location of event in virtual coordinates should suffice for the condition of grabbing. This patch fixed boundary check methods for cursor in normal and fullscreen with/without Zoom-to-Fit on macOS Mojave. Signed-off-by: Chen Zhang --- ui/cocoa.m | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index 420b2411c1..21c20e8dd9 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -405,6 +405,37 @@ QemuCocoaView *cocoaView; return (p.x > -1 && p.x < screen.width && p.y > -1 && p.y < screen.hei= ght); } =20 +/* Get location of event and convert to virtual screen coordinate */ +- (CGPoint) screenLocationOfEvent:(NSEvent *)ev +{ + NSWindow *eventWindow =3D [ev window]; + if (!eventWindow) { + if (!isFullscreen) { + return [[self window] convertPointFromScreen:[ev locationInWin= dow]]; + } else { + CGPoint loc =3D [self convertPoint:[[self window] convertPoint= FromScreen:[ev locationInWindow]] fromView:nil]; + if (stretch_video) { + loc.x /=3D cdx; + loc.y /=3D cdy; + } + return loc; + } + } else if ([[self window] isEqual:eventWindow]) { + if (!isFullscreen) { + return [ev locationInWindow]; + } else { + CGPoint loc =3D [self convertPoint:[ev locationInWindow] fromV= iew:nil]; + if (stretch_video) { + loc.x /=3D cdx; + loc.y /=3D cdy; + } + return loc; + } + } else { + return [[self window] convertPointFromScreen:[eventWindow convertP= ointToScreen:[ev locationInWindow]]]; + } +} + - (void) hideCursor { if (!cursor_hide) { @@ -704,7 +735,8 @@ QemuCocoaView *cocoaView; int keycode =3D 0; bool mouse_event =3D false; static bool switched_to_fullscreen =3D false; - NSPoint p =3D [event locationInWindow]; + // Location of event in virtual screen coordinates + NSPoint p =3D [self screenLocationOfEvent:event]; =20 switch ([event type]) { case NSEventTypeFlagsChanged: @@ -815,7 +847,10 @@ QemuCocoaView *cocoaView; break; case NSEventTypeMouseMoved: if (isAbsoluteEnabled) { - if (![self screenContainsPoint:p] || ![[self window] isKey= Window]) { + // Cursor re-entered into a window may generate events in = screen coordinates + // and `nil` window property, and in full screen mode, cur= rent window may not be + // key window, where event location alone should suffice. + if (![self screenContainsPoint:p] || !([[self window] isKe= yWindow] || isFullscreen)) { if (isMouseGrabbed) { [self ungrabMouse]; } --=20 2.19.2