diff mbox

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

Message ID F1B2CC91-25A3-4D3A-BB73-3B355E317B7B@gmail.com
State New
Headers show

Commit Message

Programmingkid Nov. 26, 2015, 1:14 a.m. UTC
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.

 ui/cocoa.m |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)
diff mbox

Patch

diff --git a/ui/cocoa.m b/ui/cocoa.m
index 7730d0f..f23f5fd 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -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;