From patchwork Thu Nov 26 15:19:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 57332 Delivered-To: patches@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp576559lbb; Thu, 26 Nov 2015 07:19:30 -0800 (PST) X-Received: by 10.28.89.137 with SMTP id n131mr4602549wmb.9.1448551170282; Thu, 26 Nov 2015 07:19:30 -0800 (PST) Return-Path: Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id 14si4128138wmq.78.2015.11.26.07.19.30 for (version=TLS1_2 cipher=AES128-SHA bits=128/128); Thu, 26 Nov 2015 07:19:30 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::1 as permitted sender) client-ip=2001:8b0:1d0::1; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::1 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1a1yKW-0003RJ-HB; Thu, 26 Nov 2015 15:19:28 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, =?UTF-8?q?Andreas=20F=C3=A4rber?= , John Arbuckle Subject: [PATCH for-2.5] ui/cocoa.m: Prevent activation clicks from going to guest Date: Thu, 26 Nov 2015 15:19:28 +0000 Message-Id: <1448551168-13196-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 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 chance to handle them. In particular, if the guest input device is not an absolute-position one then the location of the guest cursor (and thus the click) will likely not be the location of the host cursor when it is clicked, and could be completely obscured below another window. Don't send mouse clicks to QEMU unless the window either has focus or has grabbed mouse events. Reported-by: John Arbuckle Signed-off-by: Peter Maydell Reviewed-by: John Arbuckle --- ui/cocoa.m | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) -- 2.6.2 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; } if (mouse_event) { - if (last_buttons != 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 != buttons)) { static uint32_t bmap[INPUT_BUTTON_MAX] = { [INPUT_BUTTON_LEFT] = MOUSE_EVENT_LBUTTON, [INPUT_BUTTON_MIDDLE] = MOUSE_EVENT_MBUTTON,