[vlc-devel] [PATCH 8/8] qt4: Make the Qt4 interface compile on Mac OS X

Juho Vähä-Herttua juhovh at iki.fi
Wed Jul 21 15:54:26 CEST 2010


---
 modules/gui/qt4/qt4.cpp |   68 ++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 58 insertions(+), 10 deletions(-)

diff --git a/modules/gui/qt4/qt4.cpp b/modules/gui/qt4/qt4.cpp
index 990b255..7bd078e 100644
--- a/modules/gui/qt4/qt4.cpp
+++ b/modules/gui/qt4/qt4.cpp
@@ -41,6 +41,9 @@
 #ifdef Q_WS_X11
  #include <vlc_xlib.h>
 #endif
+#ifdef Q_WS_MAC
+ #include <signal.h>
+#endif
 
 #include "../../../share/icons/32x32/vlc.xpm"
 #include "../../../share/icons/32x32/vlc-christmas.xpm"
@@ -63,6 +66,7 @@ static int  WindowOpen   ( vlc_object_t * );
 static void WindowClose  ( vlc_object_t * );
 static void *Thread      ( void * );
 static void ShowDialog   ( intf_thread_t *, int, int, intf_dialog_args_t * );
+static void Run          ( intf_thread_t * );
 
 /*****************************************************************************
  * Module descriptor
@@ -248,14 +252,18 @@ vlc_module_begin ()
 
         set_callbacks( OpenDialogs, Close )
 
-#if defined(Q_WS_X11) || defined(Q_WS_WIN)
+#if defined(Q_WS_X11) || defined(Q_WS_WIN) || defined(Q_WS_MAC)
     add_submodule ()
 #if defined(Q_WS_X11)
         set_capability( "vout window xid", 0 )
 #elif defined(Q_WS_WIN)
         set_capability( "vout window hwnd", 0 )
+#elif defined(Q_WS_MAC)
+        set_capability( "vout window nsobject", 0 )
 #endif
         set_callbacks( WindowOpen, WindowClose )
+#else
+# error FIXME
 #endif
 
 vlc_module_end ()
@@ -297,6 +305,9 @@ static int Open( vlc_object_t *p_this, bool isDialogProvider )
     XCloseDisplay( p_display );
 #else
     char *display = NULL;
+# ifdef Q_WS_MAC
+    p_intf->b_should_run_on_first_thread = true;
+# endif
 #endif
 
     bool busy;
@@ -322,6 +333,9 @@ static int Open( vlc_object_t *p_this, bool isDialogProvider )
     x11_display = display;
 #endif
     vlc_sem_init (&ready, 0);
+#ifdef Q_WS_MAC
+    Thread( p_intf );
+#else
     if( vlc_clone( &p_sys->thread, Thread, p_intf, VLC_THREAD_PRIORITY_LOW ) )
     {
         delete p_sys;
@@ -331,26 +345,45 @@ static int Open( vlc_object_t *p_this, bool isDialogProvider )
         vlc_mutex_unlock (&one.lock);
         return VLC_ENOMEM;
     }
+#endif
 
     /* */
     vlc_sem_wait (&ready);
     vlc_sem_destroy (&ready);
-
-    if( !p_sys->b_isDialogProvider )
-    {
-        playlist_t *pl = pl_Get(p_this);
-        var_Create (pl, "qt4-iface", VLC_VAR_ADDRESS);
-        var_SetAddress (pl, "qt4-iface", p_this);
-        var_Create (pl, "window", VLC_VAR_STRING);
-        var_SetString (pl, "window", "qt4,any");
-    }
     return VLC_SUCCESS;
 }
 
 /* Open qt4 interface */
 static int OpenIntf( vlc_object_t *p_this )
 {
+    intf_thread_t *p_intf = (intf_thread_t*) p_this;
+
+#ifdef Q_WS_MAC
+    p_intf->pf_run = Run;
+    p_intf->b_should_run_on_first_thread = true;
+    return VLC_SUCCESS;
+#else
     return Open( p_this, false );
+#endif
+}
+
+/* This gets only called on Mac OS X and is always run
+ * from the main thread, a Cocoa compatibility hack */
+static void Run( intf_thread_t *p_intf )
+{
+#ifdef Q_WS_MAC
+    sigset_t set;
+
+    /* Make sure the "force quit" menu item does quit instantly.
+     * VLC overrides SIGTERM which is sent by the "force quit"
+     * menu item to make sure deamon mode quits gracefully, so
+     * we un-override SIGTERM here. */
+    sigemptyset( &set );
+    sigaddset( &set, SIGTERM );
+    pthread_sigmask( SIG_UNBLOCK, &set, NULL );
+#endif
+
+    Open( (vlc_object_t*) p_intf, false );
 }
 
 /* Open Dialog Provider */
@@ -456,6 +489,15 @@ static void *Thread( void *obj )
     /* Explain how to show a dialog :D */
     p_intf->pf_show_dialog = ShowDialog;
 
+    if( !p_intf->p_sys->b_isDialogProvider )
+    {
+        playlist_t *pl = pl_Get(p_intf);
+        var_Create (pl, "qt4-iface", VLC_VAR_ADDRESS);
+        var_SetAddress (pl, "qt4-iface", p_intf);
+        var_Create (pl, "window", VLC_VAR_STRING);
+        var_SetString (pl, "window", "qt4,any");
+    }
+
     /* */
     vlc_sem_post (&ready);
 
@@ -574,6 +616,12 @@ static int WindowOpen( vlc_object_t *p_obj )
     p_wnd->handle.hwnd = p_mi->getVideo( &i_x, &i_y, &i_width, &i_height );
     if( !p_wnd->handle.hwnd )
         return VLC_EGENERIC;
+
+#elif defined (Q_WS_MAC)
+    p_wnd->handle.nsobject = (void *) p_mi->getVideo( &i_x, &i_y, &i_width, &i_height );
+    if( !p_wnd->handle.nsobject )
+        return VLC_EGENERIC;
+
 #else
 # error FIXME
 #endif
-- 
1.7.0.4




More information about the vlc-devel mailing list