From 7fc23467f1ae687a8c1f8b21fa866e0c1433c990 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 24 Jan 2012 17:49:18 +0000 Subject: [PATCH] From Tobias Ottenweller, "this is a fix for the problem where all input freezes for a quarter second when calling requestWarpPointer under Mac OS X (described here: http://forum.openscenegraph.org/viewtopic.php?t=3933 ). I used the latest version available via subversion. My fix is using some API only available on 10.4 and later. I used some preprocessor statements to gain compatibility with 10.3 and earlier using (now) deprecated API. Only tested on OS X Lion (10.7). Please do some testing as well since I'm fairly new to OpenSceneGraph. Someone should also test the code for 10.3 and earlier." --- src/osgViewer/GraphicsWindowCocoa.mm | 32 +++++++++++++++++----------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/osgViewer/GraphicsWindowCocoa.mm b/src/osgViewer/GraphicsWindowCocoa.mm index ed03f2b81..d2f1d04da 100644 --- a/src/osgViewer/GraphicsWindowCocoa.mm +++ b/src/osgViewer/GraphicsWindowCocoa.mm @@ -748,7 +748,7 @@ static NSRect convertToQuartzCoordinates(const NSRect& rect) // the window-delegate, handles moving/resizing of the window etc. // ---------------------------------------------------------------------------------------------------------- -@interface GraphicsWindowCocoaDelegate : NSObject +@interface GraphicsWindowCocoaDelegate : NSObject { @private osgViewer::GraphicsWindowCocoa* _win; @@ -1302,21 +1302,29 @@ void GraphicsWindowCocoa::setWindowName (const std::string & name) // requestWarpPointer // ---------------------------------------------------------------------------------------------------------- void GraphicsWindowCocoa::requestWarpPointer(float x,float y) -{ - - DarwinWindowingSystemInterface* wsi = dynamic_cast(osg::GraphicsContext::getWindowingSystemInterface()); - if (wsi == NULL) { - osg::notify(osg::WARN) << "GraphicsWindowCarbon::useCursor :: could not get OSXCarbonWindowingSystemInterface" << std::endl; - return; - } - - CGDirectDisplayID displayId = wsi->getDisplayID((*_traits)); - +{ CGPoint point; point.x = x + _traits->x; point.y = y + _traits->y; + +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 + CGEventRef warpEvent = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved, point, kCGMouseButtonLeft); + CGEventPost(kCGHIDEventTap, warpEvent); + CFRelease(warpEvent); + +#else + DarwinWindowingSystemInterface* wsi = dynamic_cast(osg::GraphicsContext::getWindowingSystemInterface()); + + if (wsi == NULL) { + osg::notify(osg::WARN) << "GraphicsWindowCocoa::useCursor :: could not get OSXCocoaWindowingSystemInterface" << std::endl; + return; + } + + CGDirectDisplayID displayId = wsi->getDisplayID((*_traits)); + CGSetLocalEventsSuppressionInterval(0); CGDisplayMoveCursorToPoint(displayId, point); - +#endif + getEventQueue()->mouseWarped(x,y); }