From nobody Sat May 4 04:26:59 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1559696554; cv=none; d=zoho.com; s=zohoarc; b=dNaR5u3igSb8H7YoZXyWEc8UDkJcLsg+98YFncNlGljHVeZO1Pze1g1ctEsElSqLCuqUjEnznQDDLPGSMl3DzdqlKlC3qeLSHuH+HoWMf/m1RHXoommo1zyh5jUNzN59zEy4vStHhSqMuzn6nXU3GJvBqCZVCp1F6MznIMmWiEQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559696554; h=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=y9G7yXnrcLrmvD7zb6Cw4GYSumWsF1Re/4aYCfMNCYY=; b=QQNpO6G6qatGCewUrRWBuler3PeoesGLcEONWlu8i99l82Ivmk48umA5qBp7eQE8tD6CYpa0UBmxPNyN4/r4QnaM8LCIgFSh7YywKMjjHiOdMdRDlC92/ye9DSLehY/um9ybDEua5AWLjbkJr7MF/PpyPyZyYswjGcSJlJSHTf0= ARC-Authentication-Results: i=1; mx.zoho.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1559696554935239.8428104800413; Tue, 4 Jun 2019 18:02:34 -0700 (PDT) Received: from localhost ([127.0.0.1]:33546 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hYKJn-0007f8-T8 for importer@patchew.org; Tue, 04 Jun 2019 21:02:19 -0400 Received: from eggs.gnu.org ([209.51.188.92]:52589) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hYKIB-0006ax-IU for qemu-devel@nongnu.org; Tue, 04 Jun 2019 21:00:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hYKI9-0007CC-QH for qemu-devel@nongnu.org; Tue, 04 Jun 2019 21:00:39 -0400 Received: from [36.106.167.139] (port=63964 helo=cusers-Mac-mini.local) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hYKI7-000703-OW for qemu-devel@nongnu.org; Tue, 04 Jun 2019 21:00:37 -0400 Received: by cusers-Mac-mini.local (Postfix, from userid 501) id 65397EFD867; Tue, 4 Jun 2019 17:13:58 +0800 (CST) To: peter.maydell@linaro.org, kraxel@redhat.com Date: Tue, 4 Jun 2019 17:12:44 +0800 Message-Id: X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Mac OS X [generic] [fuzzy] X-Received-From: 36.106.167.139 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, Chen Zhang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" 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 --- 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 Sat May 4 04:26:59 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1559696552; cv=none; d=zoho.com; s=zohoarc; b=FBZQY1uGUiln6ifo9lDg9AUQ39W5oekDmQP2MWhZCr0eJg+Hgg5zeTNu3GVUebA/VNknFReu74ocC1jovJaX+tW5wEioO/J50G4STV1oRspJWkOW5829odKzW8nZgyo/o5hPIDgPNnGuflzR/am+tCMq9Bbfg7d83e3EJpgjGk8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559696552; h=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=3+2PNPWBYOyow3xYRpmWgka+la37YsKEpbD3y1sZBPs=; b=FwxUIpseDm7pdrLy6VFTjMspoMRIlyXSP/05FZO3BdLvE4cl4BcIjZ77cu0/TI4uskl8fN0pIHDhAyDGXTCFAUb9bI0pmmELGLVDKUuFNeyYupwtepCHaBxv07N+HaYyouM/eCj7aEfVsMvunQ8mu2MaLtrNWoHGZ3p/8Jl9kqw= ARC-Authentication-Results: i=1; mx.zoho.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1559696552757118.66439801926583; Tue, 4 Jun 2019 18:02:32 -0700 (PDT) Received: from localhost ([127.0.0.1]:33543 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hYKJl-0007dN-KN for importer@patchew.org; Tue, 04 Jun 2019 21:02:17 -0400 Received: from eggs.gnu.org ([209.51.188.92]:52568) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hYKI9-0006am-Oe for qemu-devel@nongnu.org; Tue, 04 Jun 2019 21:00:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hYKI7-000782-8z for qemu-devel@nongnu.org; Tue, 04 Jun 2019 21:00:37 -0400 Received: from [36.106.167.139] (port=63967 helo=cusers-Mac-mini.local) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hYKI5-00070q-9f for qemu-devel@nongnu.org; Tue, 04 Jun 2019 21:00:34 -0400 Received: by cusers-Mac-mini.local (Postfix, from userid 501) id EFE5DEFD86D; Tue, 4 Jun 2019 17:13:59 +0800 (CST) To: peter.maydell@linaro.org, kraxel@redhat.com Date: Tue, 4 Jun 2019 17:12:45 +0800 Message-Id: <0095872e709300198d5fc96f42b112a6fd724391.1559638310.git.tgfbeta@me.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Mac OS X [generic] [fuzzy] X-Received-From: 36.106.167.139 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, Chen Zhang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" 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 --- 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