diff mbox

[v2] ui/cocoa.m: Prevent activation clicks from going to guest

Message ID CAFEAcA_vOp43D73k+fwyQkUFQoKp8F=hhFXcd8gROJ_insg1VA@mail.gmail.com
State Accepted
Commit 8d3a5d9b0f76e3f965ce2b845f6e9027fd98fd30
Headers show

Commit Message

Peter Maydell Nov. 26, 2015, 11:45 a.m. UTC
On 26 November 2015 at 01:14, Programmingkid <programmingkidx@gmail.com> 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.

>

> Signed-off-by: John Arbuckle <programmingkidx@gmail.com>

>

> ---

> Added code that handles the right mouse button and the other mouse button.


This seems like a fair bit of repeated code. Does the change
below do the right thing? I think it ought to work but I don't have
any guests handy which use the mouse to check with.




(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.)

thanks
-- PMM

Comments

Peter Maydell Nov. 26, 2015, 3:03 p.m. UTC | #1
On 26 November 2015 at 14:40, Programmingkid <programmingkidx@gmail.com> wrote:
>

> On Nov 26, 2015, at 6:45 AM, Peter Maydell wrote:

>

>> On 26 November 2015 at 01:14, Programmingkid <programmingkidx@gmail.com> 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.

>>>

>>> Signed-off-by: John Arbuckle <programmingkidx@gmail.com>

>>>

>>> ---

>>> Added code that handles the right mouse button and the other mouse button.

>>

>> 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.

>

>> I think it ought to work but I don't have

>> any guests handy which use the mouse to check with.

>

> Really?


All of my test guests on the OSX box are serial-console only
(they're faster to boot, and I don't do much development on
OSX anyway.)

> Reviewed-by: John Arbuckle <programmingkidx@gmail.com>


Great, thanks for testing this. I'll send it out as a proper
patch with my sign-off and your reviewed-by tag this afternoon.

-- PMM
diff mbox

Patch

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,