Received: from eggs.gnu.org ([2001:4830:134:3::10]:47988) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1xiw-0005Yh-IZ for qemu-devel@nongnu.org; Thu, 26 Nov 2015 09:40:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a1xir-00084h-JH for qemu-devel@nongnu.org; Thu, 26 Nov 2015 09:40:38 -0500 Received: from mail-qg0-x231.google.com ([2607:f8b0:400d:c04::231]:34230) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1xir-00084Y-EY for qemu-devel@nongnu.org; Thu, 26 Nov 2015 09:40:33 -0500 Received: by qgeb1 with SMTP id b1so55716774qge.1 for ; Thu, 26 Nov 2015 06:40:32 -0800 (PST) Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii From: Programmingkid In-Reply-To: Date: Thu, 26 Nov 2015 09:40:30 -0500 Content-Transfer-Encoding: quoted-printable Message-Id: <77ACA221-0A65-4E98-A941-F17B0EC6668B@gmail.com> References: Subject: Re: [Qemu-devel] [PATCH v2] ui/cocoa.m: Prevent activation clicks from going to guest List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: qemu-devel qemu-devel On Nov 26, 2015, at 6:45 AM, Peter Maydell wrote: > On 26 November 2015 at 01:14, Programmingkid = wrote: >> When QEMU is brought to the foreground, the click event that = activates QEMU >> should not go to the guest. Accidents happen when they do go to the = guest >> without giving the user a change to handle them. Buttons are clicked = accidently. >> Windows are closed accidently. Volumes are unmounted accidently. This = patch >> prevents these accidents from happening. >>=20 >> Signed-off-by: John Arbuckle >>=20 >> --- >> Added code that handles the right mouse button and the other mouse = button. >=20 > This seems like a fair bit of repeated code. Does the change > below do the right thing? YES! Excellent job with this one. It's very compact.=20 > I think it ought to work but I don't have > any guests handy which use the mouse to check with. Really? This Debian distro should fix that: = http://cdimage.debian.org/cdimage/archive/5.0.10/powerpc/iso-cd/ >=20 > diff --git a/ui/cocoa.m b/ui/cocoa.m > index 1554331..d76b942 100644 > --- a/ui/cocoa.m > +++ b/ui/cocoa.m > @@ -724,7 +724,15 @@ QemuCocoaView *cocoaView; > } >=20 > if (mouse_event) { > - if (last_buttons !=3D buttons) { > + /* Don't send button events to the guest unless we've got a > + * mouse grab or window focus. If we have neither then this = event > + * is the user clicking on the background window to activate = and > + * bring us to the front, which will be done by the sendEvent > + * call below. We definitely don't want to pass that click = through > + * to the guest. > + */ > + if ((isMouseGrabbed || [[self window] isKeyWindow]) && > + (last_buttons !=3D buttons)) { > static uint32_t bmap[INPUT_BUTTON_MAX] =3D { > [INPUT_BUTTON_LEFT] =3D MOUSE_EVENT_LBUTTON, > [INPUT_BUTTON_MIDDLE] =3D MOUSE_EVENT_MBUTTON, >=20 >=20 >=20 > (if this is the activation click then we will do the mousegrab > on mouse-button-up so it's not necessary to do it on button-down, > I think.) >=20 > thanks > -- PMM Reviewed-by: John Arbuckle