[vtkusers] Window events on Mac OS X

Peter Eastman peastman at stanford.edu
Fri Aug 1 16:21:56 EDT 2008


I'm working on a library that uses VTK for visualization.  For a  
complicated set of reasons that I can go into if you really want,  
running an event loop on the main thread is out of the question.  The  
main thread is getting used for lots of things other than handling  
events, and there's nothing I can do to change that.

As a workaround, every time we call Render(), we do a quick check for  
any events that have occurred since the last render and process them  
there.  We have three different versions of the code to do this for  
Windows, Mac, and Linux.  It's quoted below.

On Windows and Linux this works nicely.  On Mac, it only partly  
works.  Mouse events within the VTK window (zooming, rotating, etc.)  
get handled correctly.  But events related to the window itself  
(moving it, resizing it, bringing it to the front) are ignored.

Can anyone offer advice on what the problem might be and how to deal  
with it?

Thanks!

Peter


#ifdef _WIN32
     MSG msg;
     bool done = false;
     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
         if (msg.message == WM_QUIT) {
             printf("quit!!\n");
             renWin->Delete();renWin=0;
             break;
         }
         TranslateMessage(&msg);
         DispatchMessage(&msg);
     }
#endif

#ifdef VTK_USE_CARBON
     EventRef theEvent;
     EventTargetRef theTarget;
     theTarget = GetEventDispatcherTarget();
     while (ReceiveNextEvent(0, NULL, kEventDurationNoWait, true,  
&theEvent) == noErr) {
         SendEventToEventTarget(theEvent, theTarget);
         ReleaseEvent(theEvent);
     }
#endif

#ifdef VTK_USE_X
     vtkXRenderWindowInteractor* rwi =  
dynamic_cast<vtkXRenderWindowInteractor*>(renWin->GetInteractor());
     while (XtAppPending(rwi->GetApp()))
         XtAppProcessEvent(rwi->GetApp(), XtIMAll);
#endif




More information about the vtkusers mailing list