cocoa.next:
* Honour -show-cursor option * Fix handling of absolute positioning devices * Cope with first surface being same as initial window size -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAABCAAGBQJTsVyuAAoJEDwlJe0UNgzeiqMP/R/GVxM5aG2pXSsOqn6kuDCg /3faFHYS5hoTDLM0XQ2YRR2+RKqYecR2mcSGJG0iSppUFWSYxExfskJEiw6CjC4R t59wYtTx3v30JU9BjfFkBVY5X/r6vZybpU6EJ2UpWmiJ73z8XH3hGa7hoki+9HtZ 33HiPrW5A4yoj74W1IdBE6HnmAuSjclDL6/JlUhNPOxV9E2NsWyV+6Og0gODQSzy mzHeGg3J+MJFfJdydkOoM8Az8FuteSZhnkTVNNoT+iEyxwxmxETG2KiU6k9JqP+Z ZCAIsofsU6QjOFTx+Sq2jTDFPC0Pj2Hnjpt1VZ+kDh8Bo4xtn8/uZ+8DJp0Ackkd kh/zuw8ZZ35G4/qgLtVF73myXLkoKcD7Zxd6cHMc2cBEUyfpf3mPt3jVTlGEnG+H 9ln/CgicdznyHcCzkSwu90IKXsL+v0JXfVMYgWgLEso3h04ivAa1ugr6jDccomW+ VVpB/hOqanNPg6JIHK3IRLXilU8XvGB/GStO0uRGuAawq6J64VNuT/Qtrjz6N4hg NwHChBBIMZ7EIToRWsPyVpqMujFIYP3BDJ4YZ/ILULagfPKZKFy3LV61BYrzfqnU PFhTnIurt7wlpimuzJ4zn6/PLjpyZOhD5QvH4dg8hjIsPRvChEl5ZPDIGHOZmYKU 8DrLuGapPxQmaKCwSzIv =VoHE -----END PGP SIGNATURE----- Merge remote-tracking branch 'remotes/pmaydell/tags/pull-cocoa-20140630' into staging cocoa.next: * Honour -show-cursor option * Fix handling of absolute positioning devices * Cope with first surface being same as initial window size # gpg: Signature made Mon 30 Jun 2014 13:48:46 BST using RSA key ID 14360CDE # gpg: Good signature from "Peter Maydell <peter.maydell@linaro.org>" * remotes/pmaydell/tags/pull-cocoa-20140630: ui/cocoa: Honour -show-cursor command line option ui/cocoa: Fix handling of absolute positioning devices ui/cocoa: Add utility method to check if point is within window ui/cocoa: Cope with first surface being same as initial window size Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
		
						commit
						a4b31047c8
					
				
							
								
								
									
										108
									
								
								ui/cocoa.m
									
									
									
									
									
								
							
							
						
						
									
										108
									
								
								ui/cocoa.m
									
									
									
									
									
								
							@ -256,7 +256,7 @@ static int cocoa_keycode_to_qemu(int keycode)
 | 
				
			|||||||
    BOOL isMouseGrabbed;
 | 
					    BOOL isMouseGrabbed;
 | 
				
			||||||
    BOOL isFullscreen;
 | 
					    BOOL isFullscreen;
 | 
				
			||||||
    BOOL isAbsoluteEnabled;
 | 
					    BOOL isAbsoluteEnabled;
 | 
				
			||||||
    BOOL isTabletEnabled;
 | 
					    BOOL isMouseDeassociated;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
- (void) switchSurface:(DisplaySurface *)surface;
 | 
					- (void) switchSurface:(DisplaySurface *)surface;
 | 
				
			||||||
- (void) grabMouse;
 | 
					- (void) grabMouse;
 | 
				
			||||||
@ -264,8 +264,21 @@ static int cocoa_keycode_to_qemu(int keycode)
 | 
				
			|||||||
- (void) toggleFullScreen:(id)sender;
 | 
					- (void) toggleFullScreen:(id)sender;
 | 
				
			||||||
- (void) handleEvent:(NSEvent *)event;
 | 
					- (void) handleEvent:(NSEvent *)event;
 | 
				
			||||||
- (void) setAbsoluteEnabled:(BOOL)tIsAbsoluteEnabled;
 | 
					- (void) setAbsoluteEnabled:(BOOL)tIsAbsoluteEnabled;
 | 
				
			||||||
 | 
					/* The state surrounding mouse grabbing is potentially confusing.
 | 
				
			||||||
 | 
					 * isAbsoluteEnabled tracks qemu_input_is_absolute() [ie "is the emulated
 | 
				
			||||||
 | 
					 *   pointing device an absolute-position one?"], but is only updated on
 | 
				
			||||||
 | 
					 *   next refresh.
 | 
				
			||||||
 | 
					 * isMouseGrabbed tracks whether GUI events are directed to the guest;
 | 
				
			||||||
 | 
					 *   it controls whether special keys like Cmd get sent to the guest,
 | 
				
			||||||
 | 
					 *   and whether we capture the mouse when in non-absolute mode.
 | 
				
			||||||
 | 
					 * isMouseDeassociated tracks whether we've told MacOSX to disassociate
 | 
				
			||||||
 | 
					 *   the mouse and mouse cursor position by calling
 | 
				
			||||||
 | 
					 *   CGAssociateMouseAndMouseCursorPosition(FALSE)
 | 
				
			||||||
 | 
					 *   (which basically happens if we grab in non-absolute mode).
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
- (BOOL) isMouseGrabbed;
 | 
					- (BOOL) isMouseGrabbed;
 | 
				
			||||||
- (BOOL) isAbsoluteEnabled;
 | 
					- (BOOL) isAbsoluteEnabled;
 | 
				
			||||||
 | 
					- (BOOL) isMouseDeassociated;
 | 
				
			||||||
- (float) cdx;
 | 
					- (float) cdx;
 | 
				
			||||||
- (float) cdy;
 | 
					- (float) cdy;
 | 
				
			||||||
- (QEMUScreen) gscreen;
 | 
					- (QEMUScreen) gscreen;
 | 
				
			||||||
@ -305,6 +318,27 @@ QemuCocoaView *cocoaView;
 | 
				
			|||||||
    return YES;
 | 
					    return YES;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- (BOOL) screenContainsPoint:(NSPoint) p
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return (p.x > -1 && p.x < screen.width && p.y > -1 && p.y < screen.height);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- (void) hideCursor
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (!cursor_hide) {
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    [NSCursor hide];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- (void) unhideCursor
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (!cursor_hide) {
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    [NSCursor unhide];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- (void) drawRect:(NSRect) rect
 | 
					- (void) drawRect:(NSRect) rect
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    COCOA_DEBUG("QemuCocoaView: drawRect\n");
 | 
					    COCOA_DEBUG("QemuCocoaView: drawRect\n");
 | 
				
			||||||
@ -404,7 +438,11 @@ QemuCocoaView *cocoaView;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    int w = surface_width(surface);
 | 
					    int w = surface_width(surface);
 | 
				
			||||||
    int h = surface_height(surface);
 | 
					    int h = surface_height(surface);
 | 
				
			||||||
    bool isResize = (w != screen.width || h != screen.height);
 | 
					    /* cdx == 0 means this is our very first surface, in which case we need
 | 
				
			||||||
 | 
					     * to recalculate the content dimensions even if it happens to be the size
 | 
				
			||||||
 | 
					     * of the initial empty window.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    bool isResize = (w != screen.width || h != screen.height || cdx == 0.0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int oldh = screen.height;
 | 
					    int oldh = screen.height;
 | 
				
			||||||
    if (isResize) {
 | 
					    if (isResize) {
 | 
				
			||||||
@ -603,15 +641,13 @@ QemuCocoaView *cocoaView;
 | 
				
			|||||||
            break;
 | 
					            break;
 | 
				
			||||||
        case NSMouseMoved:
 | 
					        case NSMouseMoved:
 | 
				
			||||||
            if (isAbsoluteEnabled) {
 | 
					            if (isAbsoluteEnabled) {
 | 
				
			||||||
                if (p.x < 0 || p.x > screen.width || p.y < 0 || p.y > screen.height || ![[self window] isKeyWindow]) {
 | 
					                if (![self screenContainsPoint:p] || ![[self window] isKeyWindow]) {
 | 
				
			||||||
                    if (isTabletEnabled) { // if we leave the window, deactivate the tablet
 | 
					                    if (isMouseGrabbed) {
 | 
				
			||||||
                        [NSCursor unhide];
 | 
					                        [self ungrabMouse];
 | 
				
			||||||
                        isTabletEnabled = FALSE;
 | 
					 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                } else {
 | 
					                } else {
 | 
				
			||||||
                    if (!isTabletEnabled) { // if we enter the window, activate the tablet
 | 
					                    if (!isMouseGrabbed) {
 | 
				
			||||||
                        [NSCursor hide];
 | 
					                        [self grabMouse];
 | 
				
			||||||
                        isTabletEnabled = TRUE;
 | 
					 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@ -650,16 +686,9 @@ QemuCocoaView *cocoaView;
 | 
				
			|||||||
            mouse_event = true;
 | 
					            mouse_event = true;
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        case NSLeftMouseUp:
 | 
					        case NSLeftMouseUp:
 | 
				
			||||||
            if (isTabletEnabled) {
 | 
					            mouse_event = true;
 | 
				
			||||||
                    mouse_event = true;
 | 
					            if (!isMouseGrabbed && [self screenContainsPoint:p]) {
 | 
				
			||||||
            } else if (!isMouseGrabbed) {
 | 
					                [self grabMouse];
 | 
				
			||||||
                if (p.x > -1 && p.x < screen.width && p.y > -1 && p.y < screen.height) {
 | 
					 | 
				
			||||||
                    [self grabMouse];
 | 
					 | 
				
			||||||
                } else {
 | 
					 | 
				
			||||||
                    [NSApp sendEvent:event];
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
                mouse_event = true;
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        case NSRightMouseUp:
 | 
					        case NSRightMouseUp:
 | 
				
			||||||
@ -669,13 +698,11 @@ QemuCocoaView *cocoaView;
 | 
				
			|||||||
            mouse_event = true;
 | 
					            mouse_event = true;
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        case NSScrollWheel:
 | 
					        case NSScrollWheel:
 | 
				
			||||||
            if (isTabletEnabled || isMouseGrabbed) {
 | 
					            if (isMouseGrabbed) {
 | 
				
			||||||
                buttons |= ([event deltaY] < 0) ?
 | 
					                buttons |= ([event deltaY] < 0) ?
 | 
				
			||||||
                    MOUSE_EVENT_WHEELUP : MOUSE_EVENT_WHEELDN;
 | 
					                    MOUSE_EVENT_WHEELUP : MOUSE_EVENT_WHEELDN;
 | 
				
			||||||
                mouse_event = true;
 | 
					 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
                [NSApp sendEvent:event];
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            mouse_event = true;
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        default:
 | 
					        default:
 | 
				
			||||||
            [NSApp sendEvent:event];
 | 
					            [NSApp sendEvent:event];
 | 
				
			||||||
@ -693,12 +720,20 @@ QemuCocoaView *cocoaView;
 | 
				
			|||||||
            qemu_input_update_buttons(dcl->con, bmap, last_buttons, buttons);
 | 
					            qemu_input_update_buttons(dcl->con, bmap, last_buttons, buttons);
 | 
				
			||||||
            last_buttons = buttons;
 | 
					            last_buttons = buttons;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if (isTabletEnabled) {
 | 
					        if (isMouseGrabbed) {
 | 
				
			||||||
            qemu_input_queue_abs(dcl->con, INPUT_AXIS_X, p.x, screen.width);
 | 
					            if (isAbsoluteEnabled) {
 | 
				
			||||||
            qemu_input_queue_abs(dcl->con, INPUT_AXIS_Y, p.y, screen.height);
 | 
					                /* Note that the origin for Cocoa mouse coords is bottom left, not top left.
 | 
				
			||||||
        } else if (isMouseGrabbed) {
 | 
					                 * The check on screenContainsPoint is to avoid sending out of range values for
 | 
				
			||||||
            qemu_input_queue_rel(dcl->con, INPUT_AXIS_X, (int)[event deltaX]);
 | 
					                 * clicks in the titlebar.
 | 
				
			||||||
            qemu_input_queue_rel(dcl->con, INPUT_AXIS_Y, (int)[event deltaY]);
 | 
					                 */
 | 
				
			||||||
 | 
					                if ([self screenContainsPoint:p]) {
 | 
				
			||||||
 | 
					                    qemu_input_queue_abs(dcl->con, INPUT_AXIS_X, p.x, screen.width);
 | 
				
			||||||
 | 
					                    qemu_input_queue_abs(dcl->con, INPUT_AXIS_Y, screen.height - p.y, screen.height);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                qemu_input_queue_rel(dcl->con, INPUT_AXIS_X, (int)[event deltaX]);
 | 
				
			||||||
 | 
					                qemu_input_queue_rel(dcl->con, INPUT_AXIS_Y, (int)[event deltaY]);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            [NSApp sendEvent:event];
 | 
					            [NSApp sendEvent:event];
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@ -716,8 +751,11 @@ QemuCocoaView *cocoaView;
 | 
				
			|||||||
        else
 | 
					        else
 | 
				
			||||||
            [normalWindow setTitle:@"QEMU - (Press ctrl + alt to release Mouse)"];
 | 
					            [normalWindow setTitle:@"QEMU - (Press ctrl + alt to release Mouse)"];
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    [NSCursor hide];
 | 
					    [self hideCursor];
 | 
				
			||||||
    CGAssociateMouseAndMouseCursorPosition(FALSE);
 | 
					    if (!isAbsoluteEnabled) {
 | 
				
			||||||
 | 
					        isMouseDeassociated = TRUE;
 | 
				
			||||||
 | 
					        CGAssociateMouseAndMouseCursorPosition(FALSE);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    isMouseGrabbed = TRUE; // while isMouseGrabbed = TRUE, QemuCocoaApp sends all events to [cocoaView handleEvent:]
 | 
					    isMouseGrabbed = TRUE; // while isMouseGrabbed = TRUE, QemuCocoaApp sends all events to [cocoaView handleEvent:]
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -731,14 +769,18 @@ QemuCocoaView *cocoaView;
 | 
				
			|||||||
        else
 | 
					        else
 | 
				
			||||||
            [normalWindow setTitle:@"QEMU"];
 | 
					            [normalWindow setTitle:@"QEMU"];
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    [NSCursor unhide];
 | 
					    [self unhideCursor];
 | 
				
			||||||
    CGAssociateMouseAndMouseCursorPosition(TRUE);
 | 
					    if (isMouseDeassociated) {
 | 
				
			||||||
 | 
					        CGAssociateMouseAndMouseCursorPosition(TRUE);
 | 
				
			||||||
 | 
					        isMouseDeassociated = FALSE;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    isMouseGrabbed = FALSE;
 | 
					    isMouseGrabbed = FALSE;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- (void) setAbsoluteEnabled:(BOOL)tIsAbsoluteEnabled {isAbsoluteEnabled = tIsAbsoluteEnabled;}
 | 
					- (void) setAbsoluteEnabled:(BOOL)tIsAbsoluteEnabled {isAbsoluteEnabled = tIsAbsoluteEnabled;}
 | 
				
			||||||
- (BOOL) isMouseGrabbed {return isMouseGrabbed;}
 | 
					- (BOOL) isMouseGrabbed {return isMouseGrabbed;}
 | 
				
			||||||
- (BOOL) isAbsoluteEnabled {return isAbsoluteEnabled;}
 | 
					- (BOOL) isAbsoluteEnabled {return isAbsoluteEnabled;}
 | 
				
			||||||
 | 
					- (BOOL) isMouseDeassociated {return isMouseDeassociated;}
 | 
				
			||||||
- (float) cdx {return cdx;}
 | 
					- (float) cdx {return cdx;}
 | 
				
			||||||
- (float) cdy {return cdy;}
 | 
					- (float) cdy {return cdy;}
 | 
				
			||||||
- (QEMUScreen) gscreen {return screen;}
 | 
					- (QEMUScreen) gscreen {return screen;}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user