From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58166) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1yKf-0005hz-Sh for qemu-devel@nongnu.org; Thu, 26 Nov 2015 10:19:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a1yKf-0001Ik-2r for qemu-devel@nongnu.org; Thu, 26 Nov 2015 10:19:37 -0500 Received: from mnementh.archaic.org.uk ([2001:8b0:1d0::1]:58984) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1yKe-0001IY-S9 for qemu-devel@nongnu.org; Thu, 26 Nov 2015 10:19:36 -0500 From: Peter Maydell Date: Thu, 26 Nov 2015 15:19:28 +0000 Message-Id: <1448551168-13196-1-git-send-email-peter.maydell@linaro.org> Subject: [Qemu-devel] [PATCH for-2.5] ui/cocoa.m: Prevent activation clicks from going to guest List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: John Arbuckle , =?UTF-8?q?Andreas=20F=C3=A4rber?= , patches@linaro.org 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(-) 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, -- 2.6.2