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."
This commit is contained in:
Robert Osfield
2012-01-24 17:49:18 +00:00
parent 3c414c7962
commit 7fc23467f1

View File

@@ -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 <NSWindowDelegate>
{
@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<DarwinWindowingSystemInterface*>(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<DarwinWindowingSystemInterface*>(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);
}