ui/cocoa.m: Prevent activation clicks from going to guest
PATCH v2 1/1 ui/cocoa.m: Prevent activation clicks from going to guest
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.
---
Added code that handles the right mouse button and the other mouse button.
ui/cocoa.m | 22 ++++++++++++++++++++++ 1 files changed, 22 insertions(+), 0 deletions(-)
ui/cocoa.m +22 -0
@@ -696,6 +696,16 @@ QemuCocoaView *cocoaView; mouse_event = true; break; case NSLeftMouseDown: + /* + * This prevents the click that activates QEMU from being sent to + * the guest. + */ + if (!isMouseGrabbed && [self screenContainsPoint:p]) { + [self grabMouse]; + [NSApp sendEvent:event]; + return; + } + if ([event modifierFlags] & NSCommandKeyMask) { buttons |= MOUSE_EVENT_RBUTTON; } else {
@@ -704,10 +714,22 @@ QemuCocoaView *cocoaView; mouse_event = true; break; case NSRightMouseDown: + if (!isMouseGrabbed && [self screenContainsPoint:p]) { + [self grabMouse]; + [NSApp sendEvent:event]; + return; + } + buttons |= MOUSE_EVENT_RBUTTON; mouse_event = true; break; case NSOtherMouseDown: + if (!isMouseGrabbed && [self screenContainsPoint:p]) { + [self grabMouse]; + [NSApp sendEvent:event]; + return; + } + buttons |= MOUSE_EVENT_MBUTTON; mouse_event = true; break;
Signature · 1 line
1.7.5.4
Quoted 10 lines · Programmingkid
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 <[email protected]>---
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.
ui/cocoa.m +9 -1
@@ -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,
(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
Programmingkid
Reviewed-byQuoted 7 lines · Peter Maydell
Quoted 6 lines · Programmingkid
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.
Quoted 7 lines
Quoted 4 lines
Signed-off-by John Arbuckle <[email protected]>---
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.
Quoted 2 lines
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/
Quoted 25 lines
ui/cocoa.m +9
-1@@ -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,
Quoted 6 lines
(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
Quoted 15 lines · Programmingkid
Quoted 12 lines · Peter Maydell
Quoted 10 lines · Programmingkid
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 <[email protected]>---
Added code that handles the right mouse button and the other mouse button.
Quoted 8 lines
Quoted 2 lines
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.
Quoted 2 lines
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.)
Quoted 1 line
Reviewed-by John Arbuckle <[email protected]>
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