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

screensaver: convert to inhibit plugin

Simplify and avoid running a thread and an interval timer
when there is no video output.
parent 2aed8da2
/***************************************************************************** /*****************************************************************************
* 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$ * $Id$
* *
* Authors: Sam Hocevar <sam@zoy.org> * Authors: Sam Hocevar <sam@zoy.org>
...@@ -32,9 +32,7 @@ ...@@ -32,9 +32,7 @@
#include <vlc_common.h> #include <vlc_common.h>
#include <vlc_plugin.h> #include <vlc_plugin.h>
#include <vlc_input.h> #include <vlc_inhibit.h>
#include <vlc_playlist.h>
#include <vlc_interface.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
...@@ -48,8 +46,9 @@ static int Activate ( vlc_object_t * ); ...@@ -48,8 +46,9 @@ static int Activate ( vlc_object_t * );
static void Deactivate ( vlc_object_t * ); static void Deactivate ( vlc_object_t * );
static void Timer( void * ); static void Timer( void * );
static void Inhibit( vlc_inhibit_t *, bool );
struct intf_sys_t struct vlc_inhibit_sys
{ {
vlc_timer_t timer; vlc_timer_t timer;
}; };
...@@ -60,7 +59,7 @@ struct intf_sys_t ...@@ -60,7 +59,7 @@ struct intf_sys_t
*****************************************************************************/ *****************************************************************************/
vlc_module_begin () vlc_module_begin ()
set_description( N_("X Screensaver disabler") ) set_description( N_("X Screensaver disabler") )
set_capability( "interface", 0 ) set_capability( "inhibit", 5 )
set_callbacks( Activate, Deactivate ) set_callbacks( Activate, Deactivate )
vlc_module_end () vlc_module_end ()
...@@ -69,19 +68,19 @@ vlc_module_end () ...@@ -69,19 +68,19 @@ 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; vlc_inhibit_t *p_ih = (vlc_inhibit_t*)p_this;
intf_sys_t *p_sys; 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 ) if( !p_sys )
return VLC_ENOMEM; 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 ); free( p_sys );
return VLC_ENOMEM; return VLC_ENOMEM;
} }
vlc_timer_schedule( p_sys->timer, false, 30*CLOCK_FREQ, 30*CLOCK_FREQ ); p_ih->inhibit = Inhibit;
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -91,18 +90,24 @@ static int Activate( vlc_object_t *p_this ) ...@@ -91,18 +90,24 @@ static int Activate( vlc_object_t *p_this )
*****************************************************************************/ *****************************************************************************/
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; vlc_inhibit_t *p_ih = (vlc_inhibit_t*)p_this;
intf_sys_t *p_sys = p_intf->p_sys; vlc_inhibit_sys_t *p_sys = p_ih->p_sys;
vlc_timer_destroy( p_sys->timer ); vlc_timer_destroy( p_sys->timer );
free( p_sys ); 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(); pid_t pid = fork();
switch( pid ) switch( pid )
...@@ -140,30 +145,15 @@ static void Execute( intf_thread_t *p_this, const char *const *ppsz_args ) ...@@ -140,30 +145,15 @@ static void Execute( intf_thread_t *p_this, const char *const *ppsz_args )
*****************************************************************************/ *****************************************************************************/
static void Timer( void *data ) static void Timer( void *data )
{ {
intf_thread_t *p_intf = data; vlc_inhibit_t *p_ih = 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 );
/* If there is a playing video output, disable xscreensaver */ /* If there is a playing video output, disable xscreensaver */
/* http://www.jwz.org/xscreensaver/faq.html#dvd */ /* http://www.jwz.org/xscreensaver/faq.html#dvd */
const char *const ppsz_xsargs[] = { "/bin/sh", "-c", const char *const ppsz_xsargs[] = { "/bin/sh", "-c",
"xscreensaver-command -deactivate &", (char*)NULL }; "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", 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( VLC_OBJECT(p_ih), ppsz_gsargs );
} }
...@@ -918,17 +918,6 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, ...@@ -918,17 +918,6 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
intf_Create( p_libvlc, "inhibit,none" ); intf_Create( p_libvlc, "inhibit,none" );
#endif #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) && if( (config_GetInt( p_libvlc, "file-logging" ) > 0) &&
!config_GetInt( p_libvlc, "syslog" ) ) !config_GetInt( p_libvlc, "syslog" ) )
{ {
......
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