From nobody Mon Feb 9 14:01:19 2026 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=1556422746; cv=none; d=zoho.com; s=zohoarc; b=ScCYSi00AhQEpLlKWgtxBUiochFmFmUBaoVLpipsG2rwhRT4MAO7yJVKzI510/xwQSLnTUXLPCRi7pndslssOb0EIEuKpWDKiVII2jxKjH4df6z0Ue331YDTN3WMuk6gLFNSZRV/xJ/e+QxJQSg58EWhxbnXWDerajB+LwJU9SE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556422746; 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=Bb39MLBKUKwi2egwWpQ2s0HzbG/uYLnnNp9pqgifeTQ=; b=Md/zySDXI+B1mKXwpBY0seQs63eTTPBVGkexHI6qok9UJH99qZxBVnHgh4oK1X6QL/3JQCRZlH5+LQMmzGokEIFAEBXIz5gbtWVTtiKz4rAtEyZXqJcbVfCTMSB9xyJUc3eyvqbhOO6qwTS7qkmzqv04Rq6NYy19lV6I5awkivo= 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 1556422746399672.3062155750353; Sat, 27 Apr 2019 20:39:06 -0700 (PDT) Received: from localhost ([127.0.0.1]:39239 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hKaeY-0002kc-GB for importer@patchew.org; Sat, 27 Apr 2019 23:38:58 -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 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) 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== 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 Content-Transfer-Encoding: quoted-printable 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: , 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" 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(-) 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.heig= ht); } +/* 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]; 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.19.2 From nobody Mon Feb 9 14:01:19 2026 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=1556422746; cv=none; d=zoho.com; s=zohoarc; b=mNY0VC+2ytUGZ/PJ9wIadpU5yZsgZypW10/lahjyPo3oPq3G/d7VD5K7hajH8Bp8/gvmRgxsYnTUlpK+3IFVv42qN3HvLS/+jspy1I1BM+Lt3nhAgKKrAlwYLMeDUrvqxxTj0AdLcbMJUjazZitF5KDxlXk+P0Qf1GKv1031hqg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556422746; 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=+KZDaDWKI6UarYYu5ZCWUQH1GV3URskBESeCtf6LQWI=; b=HwJlpNPXJHunOF7Dxb+XYm9u2Jt53aC6m3XuWPqEa7du8ZPl7SAoBNFG95Gt0GyrjcuccIR8QdQZN+TdD2Nu9VJVnJzPHXdWd4ILbKF+6NYhs7Y6eMIMIiM30/KySGBEMMUDooZ/CGZSrm9R3PPs71DT8RTQM7HbqCKW0rpduC4= 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 1556422746207869.2146900106468; Sat, 27 Apr 2019 20:39:06 -0700 (PDT) Received: from localhost ([127.0.0.1]:39237 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hKaeV-0002iL-QP for importer@patchew.org; Sat, 27 Apr 2019 23:38:55 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33558) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hKacx-0001sr-9t for qemu-devel@nongnu.org; Sat, 27 Apr 2019 23:37:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hKaYA-0006PO-DO for qemu-devel@nongnu.org; Sat, 27 Apr 2019 23:32:23 -0400 Received: from pv50p00im-ztdg10011301.me.com ([17.58.6.40]:23042) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hKaYA-0006OL-5B for qemu-devel@nongnu.org; Sat, 27 Apr 2019 23:32:22 -0400 Received: from [172.18.2.102] (unknown [36.106.167.46]) by pv50p00im-ztdg10011301.me.com (Postfix) with ESMTPSA id 053A664011E; Sun, 28 Apr 2019 03:32:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=04042017; t=1556422341; bh=0WNm1kn5TP4Do87ua83jpqVh6ikh4v9ytPumFRZ994Y=; h=From:Message-Id:Content-Type:Mime-Version:Subject:Date:To; b=GxxAckINdwl3eLPcgInYeN1Ij3w+JBIEfQeHtl0zGCaOWs2D1WtExLC0/11sqrRAD 1Q5N08/Qyl6ZanRCZaPhCne26xFoY49bxdFkbxLPWC39AgB9Ztot4D5bz3G/MSil+x 0YGVJk5vNSfsu58FoKm7QutlKjSlEVsDi3bAcXQ/LLsnyDE1TjixPQK+WkKQ/3pQae NaNm3Oll0i8eNjBiaLmOZEIAaoqfxweq4LtRNKBm1xssCOqGgfoLnu6u4hQPYnvZWI GQWW6pVM8M/uVCcigR5Dbkbb5+kS4/Nyk0aHVVc8MzzHMJZHQJlVlOyivZxTNLbanE JvxfDj9CjNX8Q== Message-Id: Mime-Version: 1.0 (Mac OS X Mail 12.2 \(3445.102.3\)) Date: Sun, 28 Apr 2019 11:32:19 +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=803 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 Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.21 Subject: [Qemu-devel] [PATCH RESEND 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 grab mouse in fullscreen mode after user ungrabs cursor in fullscreen mode with hot-key, and left clicks the relative input devices to re-grab it. This patch used value of isFullscreen as a short-cirtuit condition for relative input device grabbing. Signed-off-by: Chen Zhang > --- 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.19.2