+//default window event handler
+static pascal OSStatus WindowEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData)
+{
+ OSStatus result = noErr;
+ UInt32 class = GetEventClass (event);
+ UInt32 kind = GetEventKind (event);
+ vout_thread_t *p_vout = (vout_thread_t *)userData;
+
+ result = CallNextEventHandler(nextHandler, event);
+ if(class == kEventClassCommand)
+ {
+ HICommand theHICommand;
+ GetEventParameter( event, kEventParamDirectObject, typeHICommand, NULL, sizeof( HICommand ), NULL, &theHICommand );
+
+ switch ( theHICommand.commandID )
+ {
+ default:
+ result = eventNotHandledErr;
+ }
+ }
+ else if(class == kEventClassWindow)
+ {
+ WindowRef window;
+ Rect rectPort = {0,0,0,0};
+
+ GetEventParameter(event, kEventParamDirectObject, typeWindowRef, NULL, sizeof(WindowRef), NULL, &window);
+
+ if(window)
+ {
+ GetPortBounds(GetWindowPort(window), &rectPort);
+ }
+
+ switch (kind)
+ {
+ case kEventWindowClosed:
+ case kEventWindowZoomed:
+ case kEventWindowBoundsChanged:
+ break;
+
+ default:
+ result = eventNotHandledErr;
+ }
+ }
+ else if(class == kEventClassMouse)
+ {
+ switch (kind)
+ {
+ case kEventMouseDown:
+ {
+ UInt16 button;
+
+ GetEventParameter(event, kEventParamMouseButton, typeMouseButton, NULL, sizeof(button), NULL, &button);
+ switch (button)
+ {
+ case kEventMouseButtonPrimary:
+ {
+ vlc_value_t val;
+
+ var_Get( p_vout, "mouse-button-down", &val );
+ val.i_int |= 1;
+ var_Set( p_vout, "mouse-button-down", val );
+ break;
+ }
+ case kEventMouseButtonSecondary:
+ {
+ vlc_value_t val;
+
+ var_Get( p_vout, "mouse-button-down", &val );
+ val.i_int |= 2;
+ var_Set( p_vout, "mouse-button-down", val );
+ break;
+ }
+ case kEventMouseButtonTertiary:
+ {
+ vlc_value_t val;
+
+ var_Get( p_vout, "mouse-button-down", &val );
+ val.i_int |= 4;
+ var_Set( p_vout, "mouse-button-down", val );
+ break;
+ }
+ default:
+ result = eventNotHandledErr;
+ }
+ break;
+ }
+
+ case kEventMouseUp:
+ {
+ UInt16 button;
+
+ GetEventParameter(event, kEventParamMouseButton, typeMouseButton, NULL, sizeof(button), NULL, &button);
+ switch (button)
+ {
+ case kEventMouseButtonPrimary:
+ {
+ UInt32 clickCount = 0;
+ GetEventParameter(event, kEventParamClickCount, typeUInt32, NULL, sizeof(clickCount), NULL, &clickCount);
+ if( clickCount > 1 )
+ {
+ vlc_value_t val;
+
+ val.b_bool = VLC_FALSE;
+ var_Set((vout_thread_t *) p_vout->p_parent, "fullscreen", val);
+ }
+ else
+ {
+ vlc_value_t val;
+
+ val.b_bool = VLC_TRUE;
+ var_Set( p_vout, "mouse-clicked", val );
+
+ var_Get( p_vout, "mouse-button-down", &val );
+ val.i_int &= ~1;
+ var_Set( p_vout, "mouse-button-down", val );
+ }
+ break;
+ }
+ case kEventMouseButtonSecondary:
+ {
+ vlc_value_t val;
+
+ var_Get( p_vout, "mouse-button-down", &val );
+ val.i_int &= ~2;
+ var_Set( p_vout, "mouse-button-down", val );
+ break;
+ }
+ case kEventMouseButtonTertiary:
+ {
+ vlc_value_t val;
+
+ var_Get( p_vout, "mouse-button-down", &val );
+ val.i_int &= ~2;
+ var_Set( p_vout, "mouse-button-down", val );
+ break;
+ }
+ default:
+ result = eventNotHandledErr;
+ }
+ break;
+ }
+
+ case kEventMouseMoved:
+ {
+ Point ml;
+ vlc_value_t val;
+
+ unsigned int i_x, i_y;
+ unsigned int i_height = p_vout->p_sys->i_height;
+ unsigned int i_width = p_vout->p_sys->i_width;
+
+ vout_PlacePicture(p_vout, i_width, i_height, &i_x, &i_y, &i_width, &i_height);
+
+ GetEventParameter(event, kEventParamWindowMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &ml);
+
+ val.i_int = ( ((int)ml.h) - i_x ) *
+ p_vout->render.i_width / i_width;
+ var_Set( p_vout, "mouse-x", val );
+
+ val.i_int = ( ((int)ml.v) - i_y ) *
+ p_vout->render.i_height / i_height;
+
+ var_Set( p_vout, "mouse-y", val );
+
+ val.b_bool = VLC_TRUE;
+ var_Set( p_vout, "mouse-moved", val );
+
+ break;
+ }
+
+ default:
+ result = eventNotHandledErr;
+ }
+ }
+ else if(class == kEventClassTextInput)
+ {
+ switch (kind)
+ {
+ case kEventTextInputUnicodeForKeyEvent:
+ {
+ break;
+ }
+ default:
+ result = eventNotHandledErr;
+ }
+ }
+ else if(class == kEventClassVLCPlugin)
+ {
+ switch (kind)
+ {
+ case kEventVLCPluginShowFullscreen:
+ ShowWindow (p_vout->p_sys->theWindow);
+ SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
+ //CGDisplayHideCursor(kCGDirectMainDisplay);
+ break;
+ case kEventVLCPluginHideFullscreen:
+ HideWindow (p_vout->p_sys->theWindow);
+ SetSystemUIMode( kUIModeNormal, 0);
+ CGDisplayShowCursor(kCGDirectMainDisplay);
+ break;
+ default:
+ result = eventNotHandledErr;
+ break;
+ }
+ }
+ return result;
+}
+
+static int aglLock( vout_thread_t * p_vout )
+{
+#ifdef __ppc__
+ /*
+ * before 10.4, we set the AGL context as current and
+ * then we retrieve and use the matching CGL context
+ */
+ aglSetCurrentContext(p_vout->p_sys->agl_ctx);
+ return kCGLNoError != CGLLockContext( CGLGetCurrentContext() );
+#else
+ /* since 10.4, this is the safe way to get the underlying CGL context */
+ CGLContextObj cglContext;
+ if( aglGetCGLContext(p_vout->p_sys->agl_ctx, (void**)&cglContext) )
+ {
+ if( kCGLNoError == CGLLockContext( cglContext ) )
+ {
+ aglSetCurrentContext(p_vout->p_sys->agl_ctx);
+ return 0;
+ }
+ }
+ return 1;
+#endif
+}
+
+static void aglUnlock( vout_thread_t * p_vout )
+{
+#ifdef __ppc__
+ /*
+ * before 10.4, we assume that the AGL context is current.
+ * therefore, we use the current CGL context
+ */
+ CGLUnlockContext( CGLGetCurrentContext() );
+#else
+ /* since 10.4, this is the safe way to get the underlying CGL context */
+ CGLContextObj cglContext;
+ if( aglGetCGLContext(p_vout->p_sys->agl_ctx, (void**)&cglContext) )
+ {
+ CGLUnlockContext( cglContext );
+ }
+#endif
+}
+
+