From 4f4d1a58241dd254b5d8555a4c094e5b6c3b907e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Juho=20V=C3=A4h=C3=A4-Herttua?= Date: Sat, 31 Jul 2010 22:02:25 +0300 Subject: [PATCH] Qt: Run mainloop on the main thread on OSX MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémi Denis-Courmont --- modules/gui/qt4/qt4.cpp | 44 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/modules/gui/qt4/qt4.cpp b/modules/gui/qt4/qt4.cpp index 5965c05478..0e9ab8ea7c 100644 --- a/modules/gui/qt4/qt4.cpp +++ b/modules/gui/qt4/qt4.cpp @@ -282,6 +282,24 @@ static struct * Module callbacks *****************************************************************************/ +#ifdef Q_WS_MAC +/* Used to abort the app.exec() on OSX after libvlc_Quit is called */ +#include "../../../src/control/libvlc_internal.h" /* libvlc_SetExitHandler */ +static void Abort( void *obj ) +{ + QVLCApp::triggerQuit(); +} +#endif + +static void RegisterIntf( vlc_object_t *p_this ) +{ + 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"); +} + /* Open Interface */ static int Open( vlc_object_t *p_this, bool isDialogProvider ) { @@ -327,6 +345,11 @@ static int Open( vlc_object_t *p_this, bool isDialogProvider ) x11_display = display; #endif vlc_sem_init (&ready, 0); +#ifdef Q_WS_MAC + /* Run mainloop on the main thread as Cocoa requires */ + libvlc_SetExitHandler( p_intf->p_libvlc, Abort, p_intf ); + Thread( (void *)p_intf ); +#else if( vlc_clone( &p_sys->thread, Thread, p_intf, VLC_THREAD_PRIORITY_LOW ) ) { delete p_sys; @@ -336,19 +359,19 @@ 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); +#ifndef Q_WS_MAC 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"); + RegisterIntf( p_this ); } +#endif + return VLC_SUCCESS; } @@ -377,7 +400,9 @@ static void Close( vlc_object_t *p_this ) QVLCApp::triggerQuit(); +#ifndef Q_WS_MAC vlc_join (p_sys->thread, NULL); +#endif #ifdef Q_WS_X11 free (x11_display); x11_display = NULL; @@ -466,6 +491,15 @@ static void *Thread( void *obj ) /* */ vlc_sem_post (&ready); +#ifdef Q_WS_MAC + /* We took over main thread, register and start here */ + if( !p_intf->p_sys->b_isDialogProvider ) + { + RegisterIntf( (vlc_object_t *)p_intf ); + playlist_Play( p_intf->p_sys->p_playlist ); + } +#endif + /* Last settings */ app.setQuitOnLastWindowClosed( false ); -- 2.39.2