]> git.sesse.net Git - vlc/blob - modules/misc/screensaver.c
5ade8003458e8c1763d5ca92425320ebfbb036f1
[vlc] / modules / misc / screensaver.c
1 /*****************************************************************************
2  * screensaver.c : disable screen savers when VLC is playing
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id$
6  *
7  * Authors: Sam Hocevar <sam@zoy.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>
28
29 #include <vlc/vlc.h>
30 #include <vlc/intf.h>
31 #include <vlc/aout.h>
32 #include <vlc/vout.h>
33
34 /*****************************************************************************
35  * Local prototypes
36  *****************************************************************************/
37 static int  Activate     ( vlc_object_t * );
38 static void Run          ( intf_thread_t *p_intf );
39
40 /*****************************************************************************
41  * Module descriptor
42  *****************************************************************************/
43 vlc_module_begin();
44     set_description( _("X Screensaver disabler") );
45     set_capability( "interface", 0 );
46     set_callbacks( Activate, NULL );
47 vlc_module_end();
48
49 /*****************************************************************************
50  * Activate: initialize and create stuff
51  *****************************************************************************/
52 static int Activate( vlc_object_t *p_this )
53 {
54     intf_thread_t *p_intf = (intf_thread_t*)p_this;
55
56     p_intf->pf_run = Run;
57
58     return VLC_SUCCESS;
59 }
60
61 /*****************************************************************************
62  * Run: main thread
63  *****************************************************************************
64  * This part of the module is in a separate thread so that we do not have
65  * too much system() overhead.
66  *****************************************************************************/
67 static void Run( intf_thread_t *p_intf )
68 {
69     int i_lastcall = 0;
70
71     while( !p_intf->b_die )
72     {
73         msleep( 100000 );
74
75         /* Check screensaver every 30 seconds */
76         if( ++i_lastcall > 300 )
77         {
78             vlc_object_t *p_vout;
79             p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
80             /* If there is a video output, disable xscreensaver */
81             if( p_vout )
82             {
83                 vlc_object_release( p_vout );
84
85                 /* http://www.jwz.org/xscreensaver/faq.html#dvd */
86                 system( "xscreensaver-command -deactivate >&- 2>&- &" );
87
88                 /* FIXME: add support for other screensavers */
89             }
90
91             i_lastcall = 0;
92         }
93     }
94 }
95