From nobody Tue May 7 13:28:33 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 ARC-Seal: i=1; a=rsa-sha256; t=1559641060; cv=none; d=zoho.com; s=zohoarc; b=nos5M06JbvmHHreTfrCHtD3VxOoUgsqs/rc8uQS1UTb+EP0PZtW45UcrQm0QIjtno/PufWhWxz/vPYgGiiJgPFTvjBVNjg9fC50nZJPRBGVqrBvzrJTj8YOCcmtsyjevPdW6hpQDLQYPmMAUTd8otV2wpEKAEQuwLY4RCuxC9FU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559641060; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To:ARC-Authentication-Results; bh=YtIj/xfcacfqcYvQpZJ+7YOy5ZwqniykS7f5iqbxwRI=; b=IPN/4pEqHCnt9VvQMyeZPGHpiRfe2QfmDIUuym8czT1jlIyGNmcYcXEkz5KwBDZPr4mDdF7t4DbIiJYY21GxHSbiPWxV2UtFwLrO6kATLDVXjLiKz0QriepHIXVBjR3Yp6Pd/GkCZC59sJsh/4qh9cjWMVmtWXwwm5UwFpWdon0= ARC-Authentication-Results: i=1; mx.zoho.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 155964106001059.85436840503871; Tue, 4 Jun 2019 02:37:40 -0700 (PDT) Received: from localhost ([127.0.0.1]:49397 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hY5st-0000zl-V3 for importer@patchew.org; Tue, 04 Jun 2019 05:37:36 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49268) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hY5rS-0000MY-BO for qemu-devel@nongnu.org; Tue, 04 Jun 2019 05:36:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hY5rR-0003zz-AV for qemu-devel@nongnu.org; Tue, 04 Jun 2019 05:36:06 -0400 Received: from pv50p00im-ztdg10021901.me.com ([17.58.6.55]:40890) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hY5rR-0003zC-1i for qemu-devel@nongnu.org; Tue, 04 Jun 2019 05:36:05 -0400 Received: from [172.18.2.102] (unknown [36.106.167.139]) by pv50p00im-ztdg10021901.me.com (Postfix) with ESMTPSA id 419D1880578; Tue, 4 Jun 2019 09:36:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=04042017; t=1559640964; bh=YtIj/xfcacfqcYvQpZJ+7YOy5ZwqniykS7f5iqbxwRI=; h=Content-Type:Mime-Version:Subject:From:Date:Message-Id:To; b=yOhgdlpruWZHDzhG9ej8LtE8StuyJGc2gLzK7pPPPXjZgpXQr93XRioqqrMmNHXCP BJu4n3qMLaxMYjVz9vnxvJELKl56QfyQ6eDLlNOVg/LkJyhreGrsjQ8sJ3wdDI+WFq 7HZufCXZRMdDYiyn2JETWAyz2NR/adErJYKjF7fypsYcIosn8DfhoIIAasLF6K55gd i1SoeLhUY3uOhRlbosR7zySdl4y4HPHO5DsA6h+J5C1d8jNmoEwrjPhjx40A59jlrs +L99QAll0djUZ6ifPNkEUpjlWOW1v4rtag+bkaylpOKz8Cn74kd+bB4eHsvObVhaQB G/Zacmus/ofeA== Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) In-Reply-To: Date: Tue, 4 Jun 2019 17:36:00 +0800 Content-Transfer-Encoding: quoted-printable Message-Id: References: To: Gerd Hoffmann , Peter Maydell X-Mailer: Apple Mail (2.3445.104.11) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-06-04_07:, , 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-1906040064 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 17.58.6.55 Subject: [Qemu-devel] [PATCH 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: , From: Chen Zhang via Qemu-devel Reply-To: Chen Zhang Cc: qemu-devel@nongnu.org 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 was nil after cursor exiting from window, hinting that the `-locationInWindow` method would return value in=20 screen coordinates. The current implementation used raw locations from=20 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. This patches fixed boundary check methods for cursor in normal and fullscreen with/without Zoom-to-Fit in Mojave. Note: CGRect, -convertRectToScreen: and -convertRectFromScreen: were used in coordinates conversion for compatibility reason. Signed-off-by: Chen Zhang Reviewed-by: Peter Maydell --- ui/cocoa.m | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) 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.hei= ght); } =20 +/* Get location of event and convert to virtual screen coordinate */ +- (CGPoint) screenLocationOfEvent:(NSEvent *)ev +{ + NSWindow *eventWindow =3D [ev window]; + // XXX: Use CGRect and -convertRectFromScreen: to support macOS 10.10 + CGRect r =3D CGRectZero; + r.origin =3D [ev locationInWindow]; + if (!eventWindow) { + if (!isFullscreen) { + return [[self window] convertRectFromScreen:r].origin; + } else { + CGPoint locationInSelfWindow =3D [[self window] convertRectFro= mScreen:r].origin; + CGPoint loc =3D [self convertPoint:locationInSelfWindow fromVi= ew:nil]; + if (stretch_video) { + loc.x /=3D cdx; + loc.y /=3D cdy; + } + return loc; + } + } else if ([[self window] isEqual:eventWindow]) { + if (!isFullscreen) { + return r.origin; + } else { + CGPoint loc =3D [self convertPoint:r.origin fromView:nil]; + if (stretch_video) { + loc.x /=3D cdx; + loc.y /=3D cdy; + } + return loc; + } + } else { + return [[self window] convertRectFromScreen:[eventWindow convertRe= ctToScreen:r]].origin; + } +} + - (void) hideCursor { if (!cursor_hide) { @@ -704,7 +739,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 +851,10 @@ QemuCocoaView *cocoaView; break; case NSEventTypeMouseMoved: if (isAbsoluteEnabled) { - if (![self screenContainsPoint:p] || ![[self window] isKey= Window]) { + // Cursor re-entered into a window might generate events b= ound to screen coordinates + // and `nil` window property, and in full screen mode, cur= rent window might 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.21.0 From nobody Tue May 7 13:28:33 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 ARC-Seal: i=1; a=rsa-sha256; t=1559641115; cv=none; d=zoho.com; s=zohoarc; b=Ecbo1k3t05qPELhZto68hesaiXA7irIDDnD4tDznrzuDrABGsy1AjWtRqbYic9fPr1ub8iVMdXP2ywU2NfMONQneVhF2RndtHNKc5LaCjg0N63egVKq8apCbrqJ9yJoQORiHmUh5lvMOjTdjjetPyAhT1fUvR3KsxJT+oCtVKEg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559641115; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To:ARC-Authentication-Results; bh=qDQqvEUK1Ku+l8atD8lNJCpwoCM1Zj4XsvaD6ib62mY=; b=AufsK/Wshis5UAcO5Nh5i1KgODN0/0HI0ZPdzcY7RnbSTU2HogPagivZMamJEa3hw2bP3FUTE26jsdGXm7yYsb4rOXv5jJbuBIiyXeImiVuUiRw3gGnXDZ9k2IjrD4AB4hzyowsyMbXGwdoiIqQWwFnTPKt4QJkRb/uf8dxoASg= ARC-Authentication-Results: i=1; mx.zoho.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 1559641115701230.34734060743585; Tue, 4 Jun 2019 02:38:35 -0700 (PDT) Received: from localhost ([127.0.0.1]:49405 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hY5tk-0001lb-P6 for importer@patchew.org; Tue, 04 Jun 2019 05:38:28 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49516) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hY5sE-0000qP-Sr for qemu-devel@nongnu.org; Tue, 04 Jun 2019 05:36:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hY5sC-0004kc-Vw for qemu-devel@nongnu.org; Tue, 04 Jun 2019 05:36:53 -0400 Received: from pv50p00im-ztdg10021901.me.com ([17.58.6.55]:42933) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hY5sC-0004hh-Ec for qemu-devel@nongnu.org; Tue, 04 Jun 2019 05:36:52 -0400 Received: from [172.18.2.102] (unknown [36.106.167.139]) by pv50p00im-ztdg10021901.me.com (Postfix) with ESMTPSA id 62E2A880A96; Tue, 4 Jun 2019 09:36:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=04042017; t=1559641010; bh=qDQqvEUK1Ku+l8atD8lNJCpwoCM1Zj4XsvaD6ib62mY=; h=Content-Type:Mime-Version:Subject:From:Date:Message-Id:To; b=zj156XFD8rsQG1Z+eewq9CR9VACWCS15MTcJj5B1tCAwG09fF0JJCJFPkK3x8ONGB YYyIaZYWta6+5hwPu6LVIZacDwabzxoDY5W6yfeKeH1M5OiiFIQL7Krs+7GUcfQV8b u4u9R4qq+rPTk1xfjObTqqXXATaGJlo+yzKmXMIc1shwqsAEiH3r+5Rln9Slb2ndI/ 2UhHFNBzNFsLHUD1RsYUT8/9B6AEx5j4OelLwRwibezPEvNoCsEo4EG4Sls9cJnXPP s0ZraHikpedOPMSSyfHbuT/tA83pgR1iYjnMxGHp+A9ZSQ/deV2T7xhXSku2TPXBLR jG2sGzIPX5zpg== Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) In-Reply-To: Date: Tue, 4 Jun 2019 17:36:48 +0800 Content-Transfer-Encoding: quoted-printable Message-Id: <2D2F1191-E82F-4B54-A6E7-73FFB953DE93@me.com> References: To: Gerd Hoffmann , Peter Maydell X-Mailer: Apple Mail (2.3445.104.11) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-06-04_07:, , 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=634 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1812120000 definitions=main-1906040064 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 17.58.6.55 Subject: [Qemu-devel] [PATCH 2/2] ui/cocoa: Fix mouse grabbing in fullscreen mode for relative input device 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: qemu-devel@nongnu.org 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" In fullscreen mode, the window property of cocoaView may not be the key window, and the current implementation would not re-grab cursor by left cli= ck in fullscreen mode after ungrabbed in fullscreen mode with hot-key ctrl-opt= -g. This patch used value of isFullscreen as a short-cirtuit condition for relative input device grabbing. Signed-off-by: Chen Zhang Reviewed-by: Peter Maydell --- ui/cocoa.m | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index 474d44cb9f..aa7cf07368 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -901,7 +901,12 @@ QemuCocoaView *cocoaView; case NSEventTypeLeftMouseUp: mouse_event =3D true; if (!isMouseGrabbed && [self screenContainsPoint:p]) { - if([[self window] isKeyWindow]) { + /* + * In fullscreen mode, the window of cocoaView may not be = the + * key window, therefore the position relative to the virt= ual + * screen alone will be sufficient. + */ + if(isFullscreen || [[self window] isKeyWindow]) { [self grabMouse]; } } --=20 2.21.0