Simplify and avoid running a thread and an interval timer
when there is no video output.
/*****************************************************************************
* screensaver.c : disable screen savers when VLC is playing
*****************************************************************************
/*****************************************************************************
* screensaver.c : disable screen savers when VLC is playing
*****************************************************************************
- * Copyright (C) 2006 the VideoLAN team
+ * Copyright (C) 2006-2009 the VideoLAN team
* $Id$
*
* Authors: Sam Hocevar <sam@zoy.org>
* $Id$
*
* Authors: Sam Hocevar <sam@zoy.org>
#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_common.h>
#include <vlc_plugin.h>
-#include <vlc_input.h>
-#include <vlc_playlist.h>
-#include <vlc_interface.h>
+#include <vlc_inhibit.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/wait.h>
static void Deactivate ( vlc_object_t * );
static void Timer( void * );
static void Deactivate ( vlc_object_t * );
static void Timer( void * );
+static void Inhibit( vlc_inhibit_t *, bool );
*****************************************************************************/
vlc_module_begin ()
set_description( N_("X Screensaver disabler") )
*****************************************************************************/
vlc_module_begin ()
set_description( N_("X Screensaver disabler") )
- set_capability( "interface", 0 )
+ set_capability( "inhibit", 5 )
set_callbacks( Activate, Deactivate )
vlc_module_end ()
set_callbacks( Activate, Deactivate )
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_sys_t *p_sys;
+ vlc_inhibit_t *p_ih = (vlc_inhibit_t*)p_this;
+ vlc_inhibit_sys_t *p_sys;
- p_sys = p_intf->p_sys = (intf_sys_t *)malloc( sizeof( intf_sys_t ) );
+ p_sys = p_ih->p_sys = malloc( sizeof( *p_sys ) );
if( !p_sys )
return VLC_ENOMEM;
if( !p_sys )
return VLC_ENOMEM;
- if( vlc_timer_create( &p_sys->timer, Timer, p_intf ) )
+ if( vlc_timer_create( &p_sys->timer, Timer, p_ih ) )
{
free( p_sys );
return VLC_ENOMEM;
}
{
free( p_sys );
return VLC_ENOMEM;
}
- vlc_timer_schedule( p_sys->timer, false, 30*CLOCK_FREQ, 30*CLOCK_FREQ );
+ p_ih->inhibit = Inhibit;
*****************************************************************************/
static void Deactivate( vlc_object_t *p_this )
{
*****************************************************************************/
static void Deactivate( vlc_object_t *p_this )
{
- intf_thread_t *p_intf = (intf_thread_t*)p_this;
- intf_sys_t *p_sys = p_intf->p_sys;
+ vlc_inhibit_t *p_ih = (vlc_inhibit_t*)p_this;
+ vlc_inhibit_sys_t *p_sys = p_ih->p_sys;
vlc_timer_destroy( p_sys->timer );
free( p_sys );
}
vlc_timer_destroy( p_sys->timer );
free( p_sys );
}
+static void Inhibit( vlc_inhibit_t *p_ih, bool suspend )
+{
+ mtime_t d = suspend ? 30*CLOCK_FREQ : 0;
+ vlc_timer_schedule( p_ih->p_sys->timer, false, d, d );
+}
+
/*****************************************************************************
* Execute: Spawns a process using execv()
*****************************************************************************/
/*****************************************************************************
* Execute: Spawns a process using execv()
*****************************************************************************/
-static void Execute( intf_thread_t *p_this, const char *const *ppsz_args )
+static void Execute( vlc_object_t *p_this, const char *const *ppsz_args )
{
pid_t pid = fork();
switch( pid )
{
pid_t pid = fork();
switch( pid )
*****************************************************************************/
static void Timer( void *data )
{
*****************************************************************************/
static void Timer( void *data )
{
- intf_thread_t *p_intf = data;
- playlist_t *p_playlist = pl_Hold( p_intf );
- input_thread_t *p_input = playlist_CurrentInput( p_playlist );
- pl_Release( p_intf );
- if( !p_input )
- return;
-
- vlc_object_t *p_vout;
- if( var_GetInteger( p_input, "state" ) == PLAYING_S )
- 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 );
+ vlc_inhibit_t *p_ih = data;
/* 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 };
/* 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 );
+ Execute( VLC_OBJECT(p_ih), ppsz_xsargs );
const char *const ppsz_gsargs[] = { "/bin/sh", "-c",
"gnome-screensaver-command --poke &", (char*)NULL };
const char *const ppsz_gsargs[] = { "/bin/sh", "-c",
"gnome-screensaver-command --poke &", (char*)NULL };
- Execute( p_intf, ppsz_gsargs );
+ Execute( VLC_OBJECT(p_ih), ppsz_gsargs );
intf_Create( p_libvlc, "inhibit,none" );
#endif
intf_Create( p_libvlc, "inhibit,none" );
#endif
- /*
- * If needed, load the Xscreensaver interface
- * Currently, only for X
- */
-#ifdef HAVE_X11_XLIB_H
- if( config_GetInt( p_libvlc, "disable-screensaver" ) )
- {
- intf_Create( p_libvlc, "screensaver,none" );
- }
-#endif
-
if( (config_GetInt( p_libvlc, "file-logging" ) > 0) &&
!config_GetInt( p_libvlc, "syslog" ) )
{
if( (config_GetInt( p_libvlc, "file-logging" ) > 0) &&
!config_GetInt( p_libvlc, "syslog" ) )
{