1 /*****************************************************************************
2 * screensaver.c : disable screen savers when VLC is playing
3 *****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
7 * Authors: Sam Hocevar <sam@zoy.org>
8 * Benjamin Pracht <bigben AT videolan DOT org>
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 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
33 #include <vlc_common.h>
34 #include <vlc_plugin.h>
35 #include <vlc_input.h>
36 #include <vlc_playlist.h>
37 #include <vlc_interface.h>
39 #include <sys/types.h>
44 /*****************************************************************************
46 *****************************************************************************/
47 static int Activate ( vlc_object_t * );
48 static void Deactivate ( vlc_object_t * );
50 static void Timer( void * );
58 /*****************************************************************************
60 *****************************************************************************/
62 set_description( N_("X Screensaver disabler") )
63 set_capability( "interface", 0 )
64 set_callbacks( Activate, Deactivate )
67 /*****************************************************************************
68 * Activate: initialize and create stuff
69 *****************************************************************************/
70 static int Activate( vlc_object_t *p_this )
72 intf_thread_t *p_intf = (intf_thread_t*)p_this;
75 p_sys = p_intf->p_sys = (intf_sys_t *)malloc( sizeof( intf_sys_t ) );
79 if( vlc_timer_create( &p_sys->timer, Timer, p_intf ) )
84 vlc_timer_schedule( p_sys->timer, false, 30*CLOCK_FREQ, 30*CLOCK_FREQ );
89 /*****************************************************************************
90 * Deactivate: uninitialize and cleanup
91 *****************************************************************************/
92 static void Deactivate( vlc_object_t *p_this )
94 intf_thread_t *p_intf = (intf_thread_t*)p_this;
95 intf_sys_t *p_sys = p_intf->p_sys;
97 vlc_timer_destroy( p_sys->timer );
102 /*****************************************************************************
103 * Execute: Spawns a process using execv()
104 *****************************************************************************/
105 static void Execute( intf_thread_t *p_this, const char *const *ppsz_args )
110 case 0: /* we're the child */
114 pthread_sigmask (SIG_SETMASK, &set, NULL);
116 /* We don't want output */
117 if( ( freopen( "/dev/null", "w", stdout ) != NULL )
118 && ( freopen( "/dev/null", "w", stderr ) != NULL ) )
119 execv( ppsz_args[0] , (char *const *)ppsz_args );
120 /* If the file we want to execute doesn't exist we exit() */
121 exit( EXIT_FAILURE );
123 case -1: /* we're the error */
124 msg_Dbg( p_this, "Couldn't fork() while launching %s",
127 default: /* we're the parent */
128 /* Wait for the child to exit.
129 * We will not deadlock because we ran "/bin/sh &" */
130 while( waitpid( pid, NULL, 0 ) != pid);
135 /*****************************************************************************
137 *****************************************************************************
138 * This part of the module is in a separate thread so that we do not have
139 * too much system() overhead.
140 *****************************************************************************/
141 static void Timer( void *data )
143 intf_thread_t *p_intf = data;
144 playlist_t *p_playlist = pl_Hold( p_intf );
145 input_thread_t *p_input = playlist_CurrentInput( p_playlist );
146 pl_Release( p_intf );
150 vlc_object_t *p_vout;
151 if( var_GetInteger( p_input, "state" ) == PLAYING_S )
152 p_vout = (vlc_object_t *)input_GetVout( p_input );
155 vlc_object_release( p_input );
158 vlc_object_release( p_vout );
160 /* If there is a playing video output, disable xscreensaver */
161 /* http://www.jwz.org/xscreensaver/faq.html#dvd */
162 const char *const ppsz_xsargs[] = { "/bin/sh", "-c",
163 "xscreensaver-command -deactivate &", (char*)NULL };
164 Execute( p_intf, ppsz_xsargs );
166 const char *const ppsz_gsargs[] = { "/bin/sh", "-c",
167 "gnome-screensaver-command --poke &", (char*)NULL };
168 Execute( p_intf, ppsz_gsargs );