1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
8 * Olivier Teulière <ipkiss@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
29 #include <vlc_common.h>
30 #include <vlc_plugin.h>
31 #include <vlc_input.h>
32 #include <vlc_playlist.h>
33 #include <vlc_threads.h>
34 #include <vlc_vout_window.h>
35 #include <vlc_vout_display.h>
37 #include "dialogs.hpp"
38 #include "os_factory.hpp"
39 #include "os_loop.hpp"
40 #include "var_manager.hpp"
41 #include "vlcproc.hpp"
42 #include "theme_loader.hpp"
44 #include "theme_repository.hpp"
45 #include "vout_window.hpp"
46 #include "vout_manager.hpp"
47 #include "art_manager.hpp"
48 #include "../parser/interpreter.hpp"
49 #include "../commands/async_queue.hpp"
50 #include "../commands/cmd_quit.hpp"
51 #include "../commands/cmd_dialogs.hpp"
52 #include "../commands/cmd_minimize.hpp"
53 #include "../commands/cmd_playlist.hpp"
54 #include "../commands/cmd_callbacks.hpp"
55 #include "../commands/cmd_show_window.hpp"
56 #include "../commands/cmd_resize.hpp"
57 #include "../commands/cmd_on_top.hpp"
59 //---------------------------------------------------------------------------
61 //---------------------------------------------------------------------------
62 static int Open ( vlc_object_t * );
63 static void Close ( vlc_object_t * );
64 static void *Run ( void * );
70 } skin_load = { NULL, VLC_STATIC_MUTEX };
72 //---------------------------------------------------------------------------
73 // Open: initialize interface
74 //---------------------------------------------------------------------------
75 static int Open( vlc_object_t *p_this )
77 intf_thread_t *p_intf = (intf_thread_t *)p_this;
79 // Allocate instance and initialize some members
80 p_intf->p_sys = (intf_sys_t *) calloc( 1, sizeof( intf_sys_t ) );
81 if( p_intf->p_sys == NULL )
84 p_intf->p_sys->p_input = NULL;
85 p_intf->p_sys->p_playlist = pl_Get( p_intf );
87 // Initialize "singleton" objects
88 p_intf->p_sys->p_logger = NULL;
89 p_intf->p_sys->p_queue = NULL;
90 p_intf->p_sys->p_dialogs = NULL;
91 p_intf->p_sys->p_interpreter = NULL;
92 p_intf->p_sys->p_osFactory = NULL;
93 p_intf->p_sys->p_osLoop = NULL;
94 p_intf->p_sys->p_varManager = NULL;
95 p_intf->p_sys->p_voutManager = NULL;
96 p_intf->p_sys->p_vlcProc = NULL;
97 p_intf->p_sys->p_repository = NULL;
100 p_intf->p_sys->p_theme = NULL;
102 vlc_mutex_init( &p_intf->p_sys->init_lock );
103 vlc_cond_init( &p_intf->p_sys->init_wait );
105 vlc_mutex_lock( &p_intf->p_sys->init_lock );
106 p_intf->p_sys->b_error = false;
107 p_intf->p_sys->b_ready = false;
109 if( vlc_clone( &p_intf->p_sys->thread, Run, p_intf,
110 VLC_THREAD_PRIORITY_LOW ) )
112 vlc_mutex_unlock( &p_intf->p_sys->init_lock );
114 vlc_cond_destroy( &p_intf->p_sys->init_wait );
115 vlc_mutex_destroy( &p_intf->p_sys->init_lock );
116 free( p_intf->p_sys );
120 while( !p_intf->p_sys->b_ready )
121 vlc_cond_wait( &p_intf->p_sys->init_wait, &p_intf->p_sys->init_lock );
122 vlc_mutex_unlock( &p_intf->p_sys->init_lock );
124 if( p_intf->p_sys->b_error )
126 vlc_join( p_intf->p_sys->thread, NULL );
128 vlc_mutex_destroy( &p_intf->p_sys->init_lock );
129 vlc_cond_destroy( &p_intf->p_sys->init_wait );
131 free( p_intf->p_sys );
135 vlc_mutex_lock( &skin_load.mutex );
136 skin_load.intf = p_intf;
137 vlc_mutex_unlock( &skin_load.mutex );
142 //---------------------------------------------------------------------------
143 // Close: destroy interface
144 //---------------------------------------------------------------------------
145 static void Close( vlc_object_t *p_this )
147 intf_thread_t *p_intf = (intf_thread_t *)p_this;
149 msg_Dbg( p_intf, "closing skins2 module" );
151 /* Terminate input to ensure that our window provider is released. */
152 playlist_Deactivate( p_intf->p_sys->p_playlist );
154 vlc_mutex_lock( &skin_load.mutex );
155 skin_load.intf = NULL;
156 vlc_mutex_unlock( &skin_load.mutex);
158 AsyncQueue *pQueue = p_intf->p_sys->p_queue;
161 CmdGeneric *pCmd = new CmdExitLoop( p_intf );
163 pQueue->push( CmdGenericPtr( pCmd ) );
167 msg_Err( p_intf, "thread found already stopped (weird!)" );
170 vlc_join( p_intf->p_sys->thread, NULL );
172 vlc_mutex_destroy( &p_intf->p_sys->init_lock );
173 vlc_cond_destroy( &p_intf->p_sys->init_wait );
176 free( p_intf->p_sys );
180 //---------------------------------------------------------------------------
182 //---------------------------------------------------------------------------
183 static void *Run( void * p_obj )
185 int canc = vlc_savecancel();
187 intf_thread_t *p_intf = (intf_thread_t *)p_obj;
189 bool b_error = false;
190 char *skin_last = NULL;
191 ThemeLoader *pLoader = NULL;
194 vlc_mutex_lock( &p_intf->p_sys->init_lock );
196 // Initialize singletons
197 if( OSFactory::instance( p_intf ) == NULL )
199 msg_Err( p_intf, "cannot initialize OSFactory" );
203 if( AsyncQueue::instance( p_intf ) == NULL )
205 msg_Err( p_intf, "cannot initialize AsyncQueue" );
209 if( Interpreter::instance( p_intf ) == NULL )
211 msg_Err( p_intf, "cannot instantiate Interpreter" );
215 if( VarManager::instance( p_intf ) == NULL )
217 msg_Err( p_intf, "cannot instantiate VarManager" );
221 if( VlcProc::instance( p_intf ) == NULL )
223 msg_Err( p_intf, "cannot initialize VLCProc" );
227 if( VoutManager::instance( p_intf ) == NULL )
229 msg_Err( p_intf, "cannot instantiate VoutManager" );
233 if( ArtManager::instance( p_intf ) == NULL )
235 msg_Err( p_intf, "cannot instantiate ArtManager" );
239 if( ThemeRepository::instance( p_intf ) == NULL )
241 msg_Err( p_intf, "cannot instantiate ThemeRepository" );
245 if( Dialogs::instance( p_intf ) == NULL )
247 msg_Err( p_intf, "cannot instantiate qt4 dialogs provider" );
253 skin_last = config_GetPsz( p_intf, "skins2-last" );
254 pLoader = new ThemeLoader( p_intf );
256 if( !skin_last || !pLoader->load( skin_last ) )
258 // No skins (not even the default one). let's quit
259 CmdQuit *pCmd = new CmdQuit( p_intf );
260 AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
261 pQueue->push( CmdGenericPtr( pCmd ) );
262 msg_Err( p_intf, "no skins found : exiting");
268 // Get the instance of OSLoop
269 loop = OSFactory::instance( p_intf )->getOSLoop();
271 // Signal the main thread this thread is now ready
272 p_intf->p_sys->b_error = false;
273 p_intf->p_sys->b_ready = true;
274 vlc_cond_signal( &p_intf->p_sys->init_wait );
275 vlc_mutex_unlock( &p_intf->p_sys->init_lock );
277 // Enter the main event loop
281 OSFactory::instance( p_intf )->destroyOSLoop();
283 // save and delete the theme
284 if( p_intf->p_sys->p_theme )
286 p_intf->p_sys->p_theme->saveConfig();
288 delete p_intf->p_sys->p_theme;
289 p_intf->p_sys->p_theme = NULL;
291 msg_Dbg( p_intf, "current theme deleted" );
295 config_SaveConfigFile( p_intf );
298 // Destroy "singleton" objects
299 Dialogs::destroy( p_intf );
300 ThemeRepository::destroy( p_intf );
301 ArtManager::destroy( p_intf );
302 VoutManager::destroy( p_intf );
303 VlcProc::destroy( p_intf );
304 VarManager::destroy( p_intf );
305 Interpreter::destroy( p_intf );
306 AsyncQueue::destroy( p_intf );
307 OSFactory::destroy( p_intf );
311 p_intf->p_sys->b_error = true;
312 p_intf->p_sys->b_ready = true;
313 vlc_cond_signal( &p_intf->p_sys->init_wait );
314 vlc_mutex_unlock( &p_intf->p_sys->init_lock );
317 vlc_restorecancel(canc);
321 static int WindowOpen( vout_window_t *, const vout_window_cfg_t * );
322 static void WindowClose( vout_window_t * );
323 static int WindowControl( vout_window_t *, int, va_list );
325 struct vout_window_sys_t
327 intf_thread_t* pIntf;
328 vout_window_cfg_t cfg;
331 static void WindowOpenLocal( intf_thread_t* pIntf, vlc_object_t *pObj )
333 vout_window_t* pWnd = (vout_window_t*)pObj;
334 int width = (int)pWnd->sys->cfg.width;
335 int height = (int)pWnd->sys->cfg.height;
336 VoutManager::instance( pIntf )->acceptWnd( pWnd, width, height );
339 static void WindowCloseLocal( intf_thread_t* pIntf, vlc_object_t *pObj )
341 vout_window_t* pWnd = (vout_window_t*)pObj;
342 VoutManager::instance( pIntf )->releaseWnd( pWnd );
345 static int WindowOpen( vout_window_t *pWnd, const vout_window_cfg_t *cfg )
347 if( cfg->type != VOUT_WINDOW_TYPE_INVALID )
350 if( cfg->type != VOUT_WINDOW_TYPE_XID )
352 if( cfg->type != VOUT_WINDOW_TYPE_HWND )
357 vout_window_sys_t* sys;
359 vlc_mutex_lock( &skin_load.mutex );
360 intf_thread_t *pIntf = skin_load.intf;
362 vlc_object_hold( pIntf );
363 vlc_mutex_unlock( &skin_load.mutex );
368 if( !var_InheritBool( pIntf, "skinned-video") ||
371 vlc_object_release( pIntf );
375 sys = (vout_window_sys_t*)calloc( 1, sizeof( *sys ) );
378 vlc_object_release( pIntf );
383 pWnd->sys->cfg = *cfg;
384 pWnd->sys->pIntf = pIntf;
386 pWnd->type = VOUT_WINDOW_TYPE_XID;
388 pWnd->type = VOUT_WINDOW_TYPE_HWND;
390 pWnd->control = WindowControl;
392 // force execution in the skins2 thread context
393 CmdExecuteBlock* cmd = new CmdExecuteBlock( pIntf, VLC_OBJECT( pWnd ),
395 CmdExecuteBlock::executeWait( CmdGenericPtr( cmd ) );
398 pWnd->display.x11 = NULL;
400 if( !pWnd->handle.xid )
402 if( !pWnd->handle.hwnd )
406 vlc_object_release( pIntf );
413 static void WindowClose( vout_window_t *pWnd )
415 vout_window_sys_t* sys = pWnd->sys;
416 intf_thread_t *pIntf = sys->pIntf;
418 // force execution in the skins2 thread context
419 CmdExecuteBlock* cmd = new CmdExecuteBlock( pIntf, VLC_OBJECT( pWnd ),
421 CmdExecuteBlock::executeWait( CmdGenericPtr( cmd ) );
423 vlc_object_release( sys->pIntf );
427 static int WindowControl( vout_window_t *pWnd, int query, va_list args )
429 vout_window_sys_t* sys = pWnd->sys;
430 intf_thread_t *pIntf = sys->pIntf;
431 AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
435 case VOUT_WINDOW_SET_SIZE:
437 unsigned int i_width = va_arg( args, unsigned int );
438 unsigned int i_height = va_arg( args, unsigned int );
440 if( i_width && i_height )
442 // Post a vout resize command
443 CmdResizeVout *pCmd =
444 new CmdResizeVout( pIntf, pWnd,
445 (int)i_width, (int)i_height );
446 pQueue->push( CmdGenericPtr( pCmd ) );
451 case VOUT_WINDOW_SET_FULLSCREEN:
453 bool b_fullscreen = va_arg( args, int );
455 // Post a set fullscreen command
456 CmdSetFullscreen* pCmd =
457 new CmdSetFullscreen( pIntf, pWnd, b_fullscreen );
458 pQueue->push( CmdGenericPtr( pCmd ) );
462 case VOUT_WINDOW_SET_STATE:
464 unsigned i_arg = va_arg( args, unsigned );
465 unsigned on_top = i_arg & VOUT_WINDOW_STATE_ABOVE;
467 // Post a SetOnTop command
469 new CmdSetOnTop( pIntf, on_top );
470 pQueue->push( CmdGenericPtr( pCmd ) );
475 msg_Dbg( pIntf, "control query not supported" );
480 //---------------------------------------------------------------------------
482 //---------------------------------------------------------------------------
483 #define SKINS2_LAST N_("Skin to use")
484 #define SKINS2_LAST_LONG N_("Path to the skin to use.")
485 #define SKINS2_CONFIG N_("Config of last used skin")
486 #define SKINS2_CONFIG_LONG N_("Windows configuration of the last skin used. " \
487 "This option is updated automatically, do not touch it." )
488 #define SKINS2_SYSTRAY N_("Systray icon")
489 #define SKINS2_SYSTRAY_LONG N_("Show a systray icon for VLC")
490 #define SKINS2_TASKBAR N_("Show VLC on the taskbar")
491 #define SKINS2_TASKBAR_LONG N_("Show VLC on the taskbar")
492 #define SKINS2_TRANSPARENCY N_("Enable transparency effects")
493 #define SKINS2_TRANSPARENCY_LONG N_("You can disable all transparency effects"\
494 " if you want. This is mainly useful when moving windows does not behave" \
496 #define SKINS2_PLAYLIST N_("Use a skinned playlist")
497 #define SKINS2_PLAYLIST_LONG N_("Use a skinned playlist")
498 #define SKINS2_VIDEO N_("Display video in a skinned window if any")
499 #define SKINS2_VIDEO_LONG N_( \
500 "When set to 'no', this parameter is intended to give old skins a chance" \
501 " to play back video even though no video tag is implemented")
504 set_category( CAT_INTERFACE )
505 set_subcategory( SUBCAT_INTERFACE_MAIN )
506 add_loadfile( "skins2-last", "", SKINS2_LAST, SKINS2_LAST_LONG,
508 add_string( "skins2-config", "", SKINS2_CONFIG, SKINS2_CONFIG_LONG,
512 add_bool( "skins2-systray", true, SKINS2_SYSTRAY,
513 SKINS2_SYSTRAY_LONG, false );
514 add_bool( "skins2-taskbar", true, SKINS2_TASKBAR,
515 SKINS2_TASKBAR_LONG, false );
517 add_bool( "skins2-transparency", false, SKINS2_TRANSPARENCY,
518 SKINS2_TRANSPARENCY_LONG, false );
520 add_bool( "skinned-playlist", true, SKINS2_PLAYLIST,
521 SKINS2_PLAYLIST_LONG, false );
522 add_bool( "skinned-video", true, SKINS2_VIDEO,
523 SKINS2_VIDEO_LONG, false );
524 set_shortname( N_("Skins"))
525 set_description( N_("Skinnable Interface") )
526 set_capability( "interface", 30 )
527 set_callbacks( Open, Close )
528 add_shortcut( "skins" )
531 set_capability( "vout window", 51 )
532 set_callbacks( WindowOpen, WindowClose )