Commit 41f3974f authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

screesaver: use timer and cleanup

parent 35e2425f
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <vlc_common.h> #include <vlc_common.h>
#include <vlc_plugin.h> #include <vlc_plugin.h>
#include <vlc_input.h> #include <vlc_input.h>
#include <vlc_playlist.h>
#include <vlc_interface.h> #include <vlc_interface.h>
#include <sys/types.h> #include <sys/types.h>
...@@ -60,7 +61,7 @@ ...@@ -60,7 +61,7 @@
static int Activate ( vlc_object_t * ); static int Activate ( vlc_object_t * );
static void Deactivate ( vlc_object_t * ); static void Deactivate ( vlc_object_t * );
static void Run ( intf_thread_t *p_intf ); static void Timer( vlc_timer_t *, void * );
#ifdef HAVE_DBUS #ifdef HAVE_DBUS
...@@ -74,14 +75,16 @@ static void screensaver_send_message_void ( intf_thread_t *p_intf, ...@@ -74,14 +75,16 @@ static void screensaver_send_message_void ( intf_thread_t *p_intf,
const char *psz_interface, const char *psz_interface,
const char *psz_name ); const char *psz_name );
static bool screensaver_is_running( DBusConnection *p_connection, const char *psz_service ); static bool screensaver_is_running( DBusConnection *p_connection, const char *psz_service );
#endif
struct intf_sys_t struct intf_sys_t
{ {
#ifdef HAVE_DBUS
DBusConnection *p_connection; DBusConnection *p_connection;
#endif
vlc_timer_t timer;
}; };
#endif
/***************************************************************************** /*****************************************************************************
* Module descriptor * Module descriptor
...@@ -98,14 +101,22 @@ vlc_module_end () ...@@ -98,14 +101,22 @@ vlc_module_end ()
static int Activate( vlc_object_t *p_this ) static int Activate( vlc_object_t *p_this )
{ {
intf_thread_t *p_intf = (intf_thread_t*)p_this; intf_thread_t *p_intf = (intf_thread_t*)p_this;
intf_sys_t *p_sys;
p_sys = p_intf->p_sys = (intf_sys_t *)malloc( sizeof( intf_sys_t ) );
if( !p_sys )
return VLC_ENOMEM;
p_intf->pf_run = Run; if( vlc_timer_create( &p_sys->timer, Timer, p_intf ) )
{
free( p_sys );
return VLC_ENOMEM;
}
vlc_timer_schedule( &p_sys->timer, false, 30*CLOCK_FREQ, 30*CLOCK_FREQ );
#ifdef HAVE_DBUS #ifdef HAVE_DBUS
p_intf->p_sys = (intf_sys_t *)malloc( sizeof( intf_sys_t ) ); p_sys->p_connection = dbus_init( p_intf );
if( !p_intf->p_sys ) return VLC_ENOMEM;
#endif #endif
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -114,17 +125,16 @@ static int Activate( vlc_object_t *p_this ) ...@@ -114,17 +125,16 @@ static int Activate( vlc_object_t *p_this )
*****************************************************************************/ *****************************************************************************/
static void Deactivate( vlc_object_t *p_this ) static void Deactivate( vlc_object_t *p_this )
{ {
#ifdef HAVE_DBUS
intf_thread_t *p_intf = (intf_thread_t*)p_this; intf_thread_t *p_intf = (intf_thread_t*)p_this;
intf_sys_t *p_sys = p_intf->p_sys;
if( p_intf->p_sys->p_connection ) vlc_timer_destroy( &p_sys->timer );
{ #ifdef HAVE_DBUS
dbus_connection_unref( p_intf->p_sys->p_connection ); if( p_sys->p_connection )
} dbus_connection_unref( p_sys->p_connection );
free( p_intf->p_sys );
p_intf->p_sys = NULL;
#endif #endif
free( p_sys );
} }
/***************************************************************************** /*****************************************************************************
...@@ -166,55 +176,43 @@ static void Execute( intf_thread_t *p_this, const char *const *ppsz_args ) ...@@ -166,55 +176,43 @@ static void Execute( intf_thread_t *p_this, const char *const *ppsz_args )
* This part of the module is in a separate thread so that we do not have * This part of the module is in a separate thread so that we do not have
* too much system() overhead. * too much system() overhead.
*****************************************************************************/ *****************************************************************************/
static void Run( intf_thread_t *p_intf ) static void Timer( vlc_timer_t *id, void *data )
{ {
int canc = vlc_savecancel(); intf_thread_t *p_intf = data;
#ifdef HAVE_DBUS playlist_t *p_playlist = pl_Hold( p_intf );
p_intf->p_sys->p_connection = dbus_init( p_intf ); input_thread_t *p_input = playlist_CurrentInput( p_playlist );
#endif pl_Release( p_intf );
if( !p_input )
return;
for( ;; ) vlc_object_t *p_vout;
{ if( var_GetInteger( p_input, "state" ) == PLAYING_S )
vlc_object_t *p_vout; p_vout = (vlc_object_t *)input_GetVout( p_input );
else
p_vout = NULL;
vlc_object_release( p_input );
if( !p_vout )
return;
vlc_object_release( p_vout );
p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE ); /* If there is a playing video output, disable xscreensaver */
/* http://www.jwz.org/xscreensaver/faq.html#dvd */
const char *const ppsz_xsargs[] = { "/bin/sh", "-c",
"xscreensaver-command -deactivate &", (char*)NULL };
Execute( p_intf, ppsz_xsargs );
/* If there is a video output, disable xscreensaver */ /* If we have dbus support, let's communicate directly with
if( p_vout ) * gnome-screensave else, run gnome-screensaver-command */
{
input_thread_t *p_input;
p_input = vlc_object_find( p_vout, VLC_OBJECT_INPUT, FIND_PARENT );
vlc_object_release( p_vout );
if( p_input )
{
if( PLAYING_S == var_GetInteger( p_input, "state" ) )
{
/* http://www.jwz.org/xscreensaver/faq.html#dvd */
const char *const ppsz_xsargs[] = { "/bin/sh", "-c",
"xscreensaver-command -deactivate &", (char*)NULL };
Execute( p_intf, ppsz_xsargs );
/* If we have dbus support, let's communicate directly
with gnome-screensave else, run
gnome-screensaver-command */
#ifdef HAVE_DBUS #ifdef HAVE_DBUS
poke_screensaver( p_intf, p_intf->p_sys->p_connection ); poke_screensaver( p_intf, p_intf->p_sys->p_connection );
#else #else
const char *const ppsz_gsargs[] = { "/bin/sh", "-c", const char *const ppsz_gsargs[] = { "/bin/sh", "-c",
"gnome-screensaver-command --poke &", (char*)NULL }; "gnome-screensaver-command --poke &", (char*)NULL };
Execute( p_intf, ppsz_gsargs ); Execute( p_intf, ppsz_gsargs );
#endif #endif
/* FIXME: add support for other screensavers */ /* FIXME: add support for other screensavers */
}
vlc_object_release( p_input );
}
}
vlc_restorecancel( canc ); (void)id;
/* Check screensaver every 30 seconds */
msleep( 30 * CLOCK_FREQ );
canc = vlc_savecancel( );
}
} }
#ifdef HAVE_DBUS #ifdef HAVE_DBUS
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment